From 0e91bc008d844c1894da6645f425ecf535afbd12 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=81=E3=82=BB?= <123655015+chise0713@users.noreply.github.com> Date: Mon, 8 Jan 2024 23:35:18 +0800 Subject: [PATCH] Chore: github-action[bot] commit with signing (#562) --- .github/workflows/updategeoip-cn.yaml | 124 ++++++++++++++++---------- 1 file changed, 77 insertions(+), 47 deletions(-) diff --git a/.github/workflows/updategeoip-cn.yaml b/.github/workflows/updategeoip-cn.yaml index a65a385a..1ab9c366 100644 --- a/.github/workflows/updategeoip-cn.yaml +++ b/.github/workflows/updategeoip-cn.yaml @@ -1,4 +1,4 @@ -name: Update China IP list and generate BypassCN.rules and BypassCN_someip.rules +name: Update China IP on: workflow_dispatch: @@ -7,11 +7,11 @@ on: - cron: '0 2 */3 * *' jobs: - build: - name: Generate BypassCN.rule + prepare: + name: Set up runs-on: ubuntu-latest steps: - + - name: Check out code into directory uses: actions/checkout@v4 @@ -19,20 +19,26 @@ jobs: run: | git config user.email "41898282+github-actions[bot]@users.noreply.github.com" git config user.name "github-actions[bot]" - git fetch + git fetch --unshallow shell: bash - - name: Get CIDR (Source someip) field - run: | - echo "#BypassCNandLan,绕过大陆和局域网someip,1,1,1,0,0,0," >> BypassCNandLan_someip.rules + - name: Save Cache + uses: actions/cache/save@v3 + with: + path: ./ + key: restore-${{ github.sha }}-${{ github.run_number }} - curl https://raw.githubusercontent.com/0x2E/someip/build/cidr.txt >> BypassCNandLan_someip.rules + rules: + name: Generate rules + runs-on: ubuntu-latest + needs: prepare + steps: - sed -i '2{/^$/d;}' BypassCNandLan_someip.rules # 删除源文件内第二行的空行 - echo 10.0.0.0/8 >> BypassCNandLan_someip.rules - echo 172.16.0.0/12 >> BypassCNandLan_someip.rules - echo 192.168.0.0/16 >> BypassCNandLan_someip.rules - shell: bash + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: ./ + key: restore- - name: Get CIDR field run: | @@ -40,66 +46,90 @@ jobs: curl https://raw.githubusercontent.com/Hackl0us/GeoIP2-CN/release/CN-ip-cidr.txt >> BypassCNandLan.rules - sed -i '2{/^$/d;}' BypassCNandLan.rules # 删除源文件内第二行的空行 + sed -i '2{/^$/d;}' BypassCNandLan.rules echo 10.0.0.0/8 >> BypassCNandLan.rules echo 172.16.0.0/12 >> BypassCNandLan.rules echo 192.168.0.0/16 >> BypassCNandLan.rules shell: bash - - name: Compare New file and Old file (Source someip) + - name: Compare New file and Old file run: | - hash1=$(sha256sum "./BypassCNandLan_someip.rules" | awk '{print $1}') - hash2=$(sha256sum "./rules/BypassCNandLan_someip.rules" | awk '{print $1}') + hash1=$(sha256sum "./BypassCNandLan.rules" | awk '{print $1}') + hash2=$(sha256sum "./rules/BypassCNandLan.rules" | awk '{print $1}') echo -e "hash1=$hash1\nhash2=$hash2" if [ "$hash1" == "$hash2" ]; then echo "Hashes match. The files are identical." echo "Upstream not updated" - echo "STATUS_1=1" >> $GITHUB_ENV + echo "STATUS=1" >> $GITHUB_ENV exit 0 else echo "Hashes do not match. The files are different." echo "Upstream updated." - echo "STATUS_1=0" >> $GITHUB_ENV - cp ./BypassCNandLan_someip.rules ./rules/BypassCNandLan_someip.rules - git add ./rules/BypassCNandLan_someip.rules - git commit -am "Updated at $(TZ='Asia/Shanghai' date)" + echo "STATUS=0" >> $GITHUB_ENV + cp ./BypassCNandLan.rules ./rules/BypassCNandLan.rules + echo "MESSAGE=\"Update at $(TZ=Asia/Shanghai date)\"" >> $GITHUB_ENV fi shell: bash + + - uses: planetscale/ghcommit-action@v0.1.6 + if: env.STATUS == '0' + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} + with: + commit_message: "${{ env.MESSAGE }}" + repo: ${{ github.repository }} + branch: ${{ github.head_ref || github.ref_name }} + file_pattern: './rules/BypassCNandLan.rules' + + someip: + name: Generate rules (someip) + runs-on: ubuntu-latest + needs: prepare + steps: + + - name: Restore Cache + uses: actions/cache/restore@v3 + with: + path: ./ + key: restore- + + - name: Get CIDR field + run: | + echo "#BypassCNandLan,绕过大陆和局域网someip,1,1,1,0,0,0," >> BypassCNandLan_someip.rules + + curl https://raw.githubusercontent.com/0x2E/someip/build/cidr.txt >> BypassCNandLan_someip.rules + + sed -i '2{/^$/d;}' BypassCNandLan_someip.rules + echo 10.0.0.0/8 >> BypassCNandLan_someip.rules + echo 172.16.0.0/12 >> BypassCNandLan_someip.rules + echo 192.168.0.0/16 >> BypassCNandLan_someip.rules + shell: bash - name: Compare New file and Old file run: | - hash1=$(sha256sum "./BypassCNandLan.rules" | awk '{print $1}') - hash2=$(sha256sum "./rules/BypassCNandLan.rules" | awk '{print $1}') + hash1=$(sha256sum "./BypassCNandLan_someip.rules" | awk '{print $1}') + hash2=$(sha256sum "./rules/BypassCNandLan_someip.rules" | awk '{print $1}') echo -e "hash1=$hash1\nhash2=$hash2" if [ "$hash1" == "$hash2" ]; then echo "Hashes match. The files are identical." echo "Upstream not updated" - echo "STATUS_2=1" >> $GITHUB_ENV + echo "STATUS=1" >> $GITHUB_ENV exit 0 else echo "Hashes do not match. The files are different." echo "Upstream updated." - echo "STATUS_2=0" >> $GITHUB_ENV - cp ./BypassCNandLan.rules ./rules/BypassCNandLan.rules - git add ./rules/BypassCNandLan.rules - git commit -am "Updated at $(TZ='Asia/Shanghai' date)" - fi - shell: bash - - - name: Check GitHub Environment Variable and judgment wheather a Github Push is Needed - run: | - if [[ "${{ env.STATUS_1 }}" == "0" ]] || [[ "${{ env.STATUS_2 }}" == "0" ]] ; then - echo "NeedUpdate=true" >> $GITHUB_ENV - else - echo "NeedUpdate=false" >> $GITHUB_ENV + echo "STATUS=0" >> $GITHUB_ENV + cp ./BypassCNandLan_someip.rules ./rules/BypassCNandLan_someip.rules + echo "MESSAGE=\"Update at $(TZ=Asia/Shanghai date)\"" >> $GITHUB_ENV fi - echo ${{ env.NeedUpdate }} shell: bash - - - name: GitHub Push - uses: ad-m/github-push-action@v0.6.0 - if: env.NeedUpdate == 'true' + + - uses: planetscale/ghcommit-action@v0.1.6 + if: env.STATUS == '0' + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} with: - github_token: ${{ secrets.GITHUB_TOKEN }} - branch: master - force: true + commit_message: "${{ env.MESSAGE }}" + repo: ${{ github.repository }} + branch: ${{ github.head_ref || github.ref_name }} + file_pattern: './rules/BypassCNandLan_someip.rules' \ No newline at end of file