Skip to content

Auto update packages v2 #2566

Auto update packages v2

Auto update packages v2 #2566

#
# 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'
is_update_geodata:
description: 'is update geodata'
required: false
default: 'false'
is_update_from_prerelease:
description: 'is update from prerelease'
required: false
default: 'false'
schedule:
- cron: "0 */4 * * *"
env:
TZ: Asia/Shanghai
jobs:
job_init:
runs-on: ubuntu-latest
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@main
with:
token: ${{ github.token }}
repository: ${{ github.repository }}
retain_days: 1
keep_minimum_runs: 0
- name: SSH connection to Actions
uses: mxschmitt/action-tmate@v3.13
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
name: Auto-update-${{ matrix.pakcages }}
strategy:
fail-fast: false
matrix:
pakcages: [brook, hysteria, ipt2socks, microsocks, shadowsocks-rust, sing-box, trojan, trojan-go, v2ray-core, v2ray-plugin, xray-core, xray-plugin, v2ray-geoip, v2ray-geosite, dns2tcp]
include:
- pakcages: brook
folder: brook
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/txthinking/brook/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/txthinking/brook/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/txthinking/brook/tar.gz/v
file_name:
# - pakcages: chinadns-ng
# folder: chinadns-ng
# version_head: PKG_VERSION:=
# hash_head: PKG_HASH:=
# version_line:
# hash_line:
# release_api_command: curl -sL "https://api.github.com/repos/zfl9/chinadns-ng/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
# release_download_url: https://codeload.github.com/zfl9/chinadns-ng/tar.gz/
# file_name:
- pakcages: hysteria
folder: hysteria
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/apernet/hysteria/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/apernet/hysteria/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/apernet/hysteria/tar.gz/app/v
file_name:
- pakcages: ipt2socks
folder: ipt2socks
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/zfl9/ipt2socks/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/zfl9/ipt2socks/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/zfl9/ipt2socks/tar.gz/v
file_name:
- pakcages: microsocks
folder: microsocks
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/rofl0r/microsocks/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/rofl0r/microsocks/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/rofl0r/microsocks/tar.gz/v
file_name:
- pakcages: shadowsocks-rust
folder: shadowsocks-rust
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/shadowsocks/shadowsocks-rust/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/shadowsocks/shadowsocks-rust/tar.gz/v
file_name:
- pakcages: sing-box
folder: sing-box
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
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//'
prerelease_api_command: curl -sL "https://api.github.com/repos/SagerNet/sing-box/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/SagerNet/sing-box/tar.gz/v
file_name:
- pakcages: trojan
folder: trojan
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/trojan-gfw/trojan/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/trojan-gfw/trojan/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/trojan-gfw/trojan/tar.gz/v
file_name:
- pakcages: trojan-go
folder: trojan-go
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/p4gefau1t/trojan-go/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/p4gefau1t/trojan-go/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/p4gefau1t/trojan-go/tar.gz/v
file_name:
- pakcages: v2ray-core
folder: v2ray-core
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/v2fly/v2ray-core/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/v2fly/v2ray-core/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/v2fly/v2ray-core/tar.gz/v
file_name:
- pakcages: v2ray-plugin
folder: v2ray-plugin
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/teddysun/v2ray-plugin/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/teddysun/v2ray-plugin/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/teddysun/v2ray-plugin/tar.gz/v
file_name:
- pakcages: xray-core
folder: xray-core
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
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//'
prerelease_api_command: curl -sL "https://api.github.com/repos/XTLS/Xray-core/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/XTLS/Xray-core/tar.gz/v
file_name:
- pakcages: xray-plugin
folder: xray-plugin
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/teddysun/xray-plugin/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/teddysun/xray-plugin/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/teddysun/xray-plugin/tar.gz/v
file_name:
- pakcages: v2ray-geoip
folder: v2ray-geodata
version_head: GEOIP_VER:=
hash_head: \ HASH:=
version_line:
hash_line: 21
release_api_command: curl -sL "https://api.github.com/repos/v2fly/geoip/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/v2fly/geoip/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://github.com/v2fly/geoip/releases/download/
file_name: /geoip.dat
- pakcages: v2ray-geosite
folder: v2ray-geodata
version_head: GEOSITE_VER:=
hash_head: \ HASH:=
version_line:
hash_line: 30
release_api_command: curl -sL "https://api.github.com/repos/v2fly/domain-list-community/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/v2fly/domain-list-community/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://github.com/v2fly/domain-list-community/releases/download/
file_name: /dlc.dat
- pakcages: dns2tcp
folder: dns2tcp
version_head: PKG_VERSION:=
hash_head: PKG_HASH:=
version_line:
hash_line:
release_api_command: curl -sL "https://api.github.com/repos/zfl9/dns2tcp/releases" | jq -r 'map(select(.prerelease|not)) | first | .tag_name' | sed -e 's/.*v//'
prerelease_api_command: curl -sL "https://api.github.com/repos/zfl9/dns2tcp/releases" | jq -r 'first | .tag_name' | sed -e 's/.*v//'
release_download_url: https://codeload.github.com/zfl9/dns2tcp/tar.gz/v
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 [ "${{ github.event.inputs.is_update_geodata }}" != "true" ] && [ "${{ matrix.pakcages }}" = "v2ray-geoip" ]; then
is_continue=false
fi
if [ "${{ github.event.inputs.is_update_geodata }}" != "true" ] && [ "${{ matrix.pakcages }}" = "v2ray-geosite" ]; then
is_continue=false
fi
if [ "$is_continue" = "true" ]; then
cd && cd $GITHUB_WORKSPACE/${{ matrix.folder }}
if [ ! -n "${{ matrix.version_line }}" ] ; then
Old_PKG_VERSION=$(sed -n '/^${{ matrix.version_head }}/p' Makefile | awk -F '=' '{print $2}');
else
Old_PKG_VERSION=$(sed -n '${{ matrix.version_line }}p' Makefile | awk -F '=' '{print $2}');
fi
if [ "${{ github.event.inputs.is_update_from_prerelease }}" = "true" ]; then
New_PKG_VERSION=$(${{ matrix.prerelease_api_command }})
else
New_PKG_VERSION=$(${{ matrix.release_api_command }})
fi
echo "${{ matrix.pakcages }}目前版本: $Old_PKG_VERSION"
echo "${{ matrix.pakcages }}latest release版本: $New_PKG_VERSION"
result=0
ver1=$(echo "$Old_PKG_VERSION" | sed 's/[^0-9]//g')
ver2=$(echo "$New_PKG_VERSION" | sed 's/[^0-9]//g')
if [[ "$ver1" == "$ver2" ]]; then
result=0
elif [[ "$ver1" -lt "$ver2" ]]; then
result=1
else
result=2
fi
echo "版本对比结果:$result "
if [[ $result -eq 0 ]]; then
echo "status=failure" >> $GITHUB_OUTPUT
echo "${{ matrix.pakcages }}版本为最新版本$New_PKG_VERSION, 无需更新"
elif [[ $result -eq 1 ]]; then
echo "New_PKG_VERSION=$New_PKG_VERSION" >> $GITHUB_OUTPUT
echo "status=success" >> $GITHUB_OUTPUT
else
echo "status=failure" >> $GITHUB_OUTPUT
echo "检测到本地版本高于最新latest release版本,停止更新"
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 }}
if [ ! -n "${{ matrix.version_line }}" ] ; then
sed -i "/^${{ matrix.version_head }}/c\${{ matrix.version_head }}$New_PKG_VERSION" Makefile;
else
sed -i "${{ matrix.version_line }}c ${{ matrix.version_head }}$New_PKG_VERSION" Makefile;
fi
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 }}
if [ ! -n "${{ matrix.hash_line }}" ] ; then
sed -i "/^${{ matrix.hash_head }}/c\${{ matrix.hash_head }}$PKG_HASH" Makefile;
else
sed -i "${{ matrix.hash_line }}c ${{ matrix.hash_head }}$PKG_HASH" Makefile;
fi
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:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "${{ matrix.pakcages }}: update to ${{ steps.update.outputs.version }}"
committer: smallprogram <smallprogram@foxmail.com>
author: smallprogram <smallprogram@foxmail.com>
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