Auto update packages v2 #4130
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Copyright (c) 2022-2024 SMALLPROGRAM <https://github.com/smallprogram> | |
# Description: Auto update packages v2 | |
# | |
name: "Auto update packages v2" | |
on: | |
repository_dispatch: | |
workflow_dispatch: | |
inputs: | |
ssh: | |
description: 'SSH connection to Actions' | |
required: false | |
default: 'false' | |
schedule: | |
- cron: "0 */2 * * *" | |
env: | |
TZ: Asia/Shanghai | |
jobs: | |
job_init: | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: read | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Initialization environment | |
run: | | |
sudo timedatectl set-timezone "$TZ" | |
- name: Delete workflow runs | |
uses: Mattraks/delete-workflow-runs@v2 | |
with: | |
retain_days: 1 | |
keep_minimum_runs: 0 | |
- name: SSH connection to Actions | |
uses: mxschmitt/action-tmate@v3 | |
if: (github.event.inputs.ssh == 'true' && github.event.inputs.ssh != 'false') || contains(github.event.action, 'ssh') | |
job_auto_update_packages: | |
if: ${{ always() }} | |
needs: job_init | |
runs-on: ubuntu-latest | |
permissions: | |
actions: read | |
contents: write | |
pull-requests: write | |
name: Auto-update-${{ matrix.pakcages }} | |
strategy: | |
fail-fast: false | |
matrix: | |
pakcages: [ adguardhome, dnscrypt-proxy2, dnsproxy, frp, mosdns, sing-box, syncthing, tailscale, xray-core, ddns-go, cloudflared ] | |
include: | |
- pakcages: adguardhome | |
folder: adguardhome | |
version_head: PKG_VERSION:= | |
hash_head: PKG_MIRROR_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/AdguardTeam/AdGuardHome/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/AdguardTeam/AdGuardHome/tar.gz/v | |
file_name: | |
- pakcages: dnscrypt-proxy2 | |
folder: dnscrypt-proxy2 | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/DNSCrypt/dnscrypt-proxy/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/DNSCrypt/dnscrypt-proxy/tar.gz/ | |
file_name: | |
- pakcages: dnsproxy | |
folder: dnsproxy | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/AdguardTeam/dnsproxy/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/AdguardTeam/dnsproxy/tar.gz/v | |
file_name: | |
- pakcages: frp | |
folder: frp | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/fatedier/frp/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/fatedier/frp/tar.gz/v | |
file_name: | |
- pakcages: mosdns | |
folder: mosdns | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/IrineSistiana/mosdns/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/IrineSistiana/mosdns/tar.gz/v | |
file_name: | |
- pakcages: sing-box | |
folder: sing-box | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/SagerNet/sing-box/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/SagerNet/sing-box/tar.gz/v | |
file_name: | |
- pakcages: syncthing | |
folder: syncthing | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/syncthing/syncthing/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://github.com/syncthing/syncthing/releases/download/v | |
file_name: /syncthing-source-$(curl -sL https://api.github.com/repos/syncthing/syncthing/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name').tar.gz | |
- pakcages: tailscale | |
folder: tailscale | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/tailscale/tailscale/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/tailscale/tailscale/tar.gz/v | |
file_name: | |
- pakcages: xray-core | |
folder: xray-core | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/XTLS/Xray-core/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/XTLS/Xray-core/tar.gz/v | |
file_name: | |
- pakcages: ddns-go | |
folder: ddns-go | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/jeessy2/ddns-go/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/jeessy2/ddns-go/tar.gz/v | |
file_name: | |
- pakcages: cloudflared | |
folder: cloudflared | |
version_head: PKG_VERSION:= | |
hash_head: PKG_HASH:= | |
release_api_command: curl -sL https://api.github.com/repos/cloudflare/cloudflared/releases | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//' | |
release_download_url: https://codeload.github.com/cloudflare/cloudflared/tar.gz/ | |
file_name: | |
steps: | |
- name: Checkout | |
uses: actions/checkout@main | |
- name: Initialization environment | |
run: | | |
cd && mkdir -p packages && cd packages | |
sudo timedatectl set-timezone "$TZ" | |
- name: Check ${{ matrix.pakcages }} | |
id: check | |
run: | | |
is_continue=true | |
if [ "$is_continue" = "true" ]; then | |
cd && cd $GITHUB_WORKSPACE/${{ matrix.folder }} | |
Old_PKG_VERSION=$(sed -n '/^${{ matrix.version_head }}/p' Makefile | awk -F '=' '{print $2}') | |
New_PKG_VERSION=$(${{ matrix.release_api_command }}) | |
echo "${{ matrix.pakcages }}目前版本: $Old_PKG_VERSION" | |
echo "${{ matrix.pakcages }}最新版本: $New_PKG_VERSION" | |
if [ "$Old_PKG_VERSION" = "$New_PKG_VERSION" ]; then | |
echo "status=failure" >> $GITHUB_OUTPUT; | |
echo "${{ matrix.pakcages }}版本为最新版本$New_PKG_VERSION,无需更新"; | |
else | |
echo "New_PKG_VERSION=$New_PKG_VERSION" >> $GITHUB_OUTPUT; | |
echo "status=success" >> $GITHUB_OUTPUT; | |
fi | |
else | |
echo "status=failure" >> $GITHUB_OUTPUT; | |
fi | |
- name: Update ${{ matrix.pakcages }} | |
id: update | |
if: steps.check.outputs.status == 'success' && steps.check.outputs.New_PKG_VERSION != '' && !cancelled() | |
run: | | |
cd && cd $GITHUB_WORKSPACE/${{ matrix.folder }} | |
New_PKG_VERSION=${{ steps.check.outputs.New_PKG_VERSION }} | |
sed -i "/^${{ matrix.version_head }}/c\${{ matrix.version_head }}$New_PKG_VERSION" Makefile | |
cd && cd packages && mkdir -p ${{ matrix.pakcages }} && cd ${{ matrix.pakcages }} | |
wget -P / ${{ matrix.release_download_url }}$New_PKG_VERSION${{ matrix.file_name }} | |
file_name=${{ matrix.file_name }} | |
is_v=$(echo ${{ matrix.release_download_url }} | awk -F/ '{print $NF}') | |
if [ ! -n "${{ matrix.file_name }}" ]; then PKG_HASH=$(sha256sum $is_v$New_PKG_VERSION) && PKG_HASH=${PKG_HASH%% *}; else PKG_HASH=$(sha256sum ${file_name##*/}) && PKG_HASH=${PKG_HASH%% *}; fi; | |
cd && cd $GITHUB_WORKSPACE/${{ matrix.folder }} | |
sed -i "/^${{ matrix.hash_head }}/c\${{ matrix.hash_head }}$PKG_HASH" Makefile | |
echo "已更新${{ matrix.pakcages }}版本到: $New_PKG_VERSION" | |
echo "${{ matrix.pakcages }} Hash:$PKG_HASH" | |
cd && cd packages | |
echo ":white_check_mark: ${{ matrix.pakcages }}: update to $New_PKG_VERSION" >> commit_messages.txt | |
echo "version=$New_PKG_VERSION" >> $GITHUB_OUTPUT | |
cd && cd $GITHUB_WORKSPACE | |
echo "branch_exists=$(git ls-remote --heads origin patches-${{ matrix.pakcages }}-$New_PKG_VERSION | tr -d '\n')" >> $GITHUB_OUTPUT | |
- name: Create Pull Request | |
id: cpr | |
if: steps.check.outputs.status == 'success' && steps.check.outputs.New_PKG_VERSION != '' && steps.update.outputs.branch_exists == '' && !cancelled() | |
uses: peter-evans/create-pull-request@v7 | |
with: | |
commit-message: "${{ matrix.pakcages }}: update to ${{ steps.update.outputs.version }}" | |
signoff: false | |
branch: patches-${{ matrix.pakcages }}-${{ steps.update.outputs.version }} | |
base: main | |
delete-branch: true | |
body: | | |
${{ matrix.pakcages }}: update to ${{ steps.update.outputs.version }} | |
title: "${{ matrix.pakcages }}: update to ${{ steps.update.outputs.version }}" | |
labels: | | |
automated-pr | |
draft: false | |