From aeb12d9e3ba8db46b29bf2f480322df128f036d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=F0=90=B2=93=F0=90=B3=9B=F0=90=B3=AA=F0=90=B3=82?= =?UTF-8?q?=F0=90=B3=90=20=F0=90=B2=80=F0=90=B3=A2=F0=90=B3=A6=F0=90=B3=AB?= =?UTF-8?q?=F0=90=B3=A2=20=F0=90=B2=A5=F0=90=B3=94=F0=90=B3=9B=F0=90=B3=AA?= =?UTF-8?q?=F0=90=B3=8C=F0=90=B3=91=F0=90=B3=96=F0=90=B3=87?= <26771058+KobeArthurScofield@users.noreply.github.com> Date: Sun, 5 Jan 2025 14:37:50 +0800 Subject: [PATCH] Build: Update GeoIP/GeoSite Cache per hour (#4247) --- .github/workflows/hourly-prepare.yml | 64 ++++++++++++++++++++++++++++ .github/workflows/release-win7.yml | 46 +------------------- .github/workflows/release.yml | 46 +------------------- .github/workflows/test.yml | 2 +- 4 files changed, 67 insertions(+), 91 deletions(-) create mode 100644 .github/workflows/hourly-prepare.yml diff --git a/.github/workflows/hourly-prepare.yml b/.github/workflows/hourly-prepare.yml new file mode 100644 index 00000000..d07c1ee3 --- /dev/null +++ b/.github/workflows/hourly-prepare.yml @@ -0,0 +1,64 @@ +name: Timely assets update + +# NOTE: This Github Actions is required by other actions, for preparing other packaging assets in a +# routine manner, for example: GeoIP/GeoSite. +# Currently updating: +# - Geodat (GeoIP/Geosite) + +on: + workflow_dispatch: + schedule: + # Update assets on every hour (xx:30) + - cron: '30 * * * *' + push: + # Prevent triggering update request storm + paths: + - ".github/workflows/hourly-prepare.yml" + pull_request: + # Prevent triggering update request storm + paths: + - ".github/workflows/hourly-prepare.yml" + +jobs: + geodat: + runs-on: ubuntu-latest + steps: + - name: Restore Geodat Cache + uses: actions/cache/restore@v4 + with: + path: resources + key: xray-geodat- + + - name: Update Geodat + id: update + uses: nick-fields/retry@v3 + with: + timeout_minutes: 60 + retry_wait_seconds: 60 + max_attempts: 60 + command: | + [ -d 'resources' ] || mkdir resources + LIST=('geoip geoip geoip' 'domain-list-community dlc geosite') + for i in "${LIST[@]}" + do + INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}')) + FILE_NAME="${INFO[2]}.dat" + echo -e "Verifying HASH key..." + HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')" + if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then + continue + else + echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..." + curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME} + echo -e "Verifying HASH key..." + [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; } + echo "unhit=true" >> $GITHUB_OUTPUT + fi + done + + - name: Save Geodat Cache + uses: actions/cache/save@v4 + if: ${{ steps.update.outputs.unhit }} + with: + path: resources + key: xray-geodat-${{ github.sha }}-${{ github.run_number }} diff --git a/.github/workflows/release-win7.yml b/.github/workflows/release-win7.yml index ae1dd35b..0d00634a 100644 --- a/.github/workflows/release-win7.yml +++ b/.github/workflows/release-win7.yml @@ -15,51 +15,7 @@ on: types: [opened, synchronize, reopened] jobs: - prepare: - runs-on: ubuntu-latest - steps: - - name: Restore Cache - uses: actions/cache/restore@v4 - with: - path: resources - key: xray-geodat- - - - name: Update Geodat - id: update - uses: nick-fields/retry@v3 - with: - timeout_minutes: 60 - retry_wait_seconds: 60 - max_attempts: 60 - command: | - [ -d 'resources' ] || mkdir resources - LIST=('geoip geoip geoip' 'domain-list-community dlc geosite') - for i in "${LIST[@]}" - do - INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}')) - FILE_NAME="${INFO[2]}.dat" - echo -e "Verifying HASH key..." - HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')" - if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then - continue - else - echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..." - curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME} - echo -e "Verifying HASH key..." - [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; } - echo "unhit=true" >> $GITHUB_OUTPUT - fi - done - - - name: Save Cache - uses: actions/cache/save@v4 - if: ${{ steps.update.outputs.unhit }} - with: - path: resources - key: xray-geodat-${{ github.sha }}-${{ github.run_number }} - build: - needs: prepare permissions: contents: write strategy: @@ -112,7 +68,7 @@ jobs: make find . -maxdepth 1 -type f -regex './\(wxray\|xray\).exe' -exec mv {} ./build_assets/ \; - - name: Restore Cache + - name: Restore Geodat Cache uses: actions/cache/restore@v4 with: path: resources diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index dc6fa6fe..7bc8c51d 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -15,51 +15,7 @@ on: types: [opened, synchronize, reopened] jobs: - prepare: - runs-on: ubuntu-latest - steps: - - name: Restore Cache - uses: actions/cache/restore@v4 - with: - path: resources - key: xray-geodat- - - - name: Update Geodat - id: update - uses: nick-fields/retry@v3 - with: - timeout_minutes: 60 - retry_wait_seconds: 60 - max_attempts: 60 - command: | - [ -d 'resources' ] || mkdir resources - LIST=('geoip geoip geoip' 'domain-list-community dlc geosite') - for i in "${LIST[@]}" - do - INFO=($(echo $i | awk 'BEGIN{FS=" ";OFS=" "} {print $1,$2,$3}')) - FILE_NAME="${INFO[2]}.dat" - echo -e "Verifying HASH key..." - HASH="$(curl -sL "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat.sha256sum" | awk -F ' ' '{print $1}')" - if [ -s "./resources/${FILE_NAME}" ] && [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ]; then - continue - else - echo -e "Downloading https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat..." - curl -L "https://raw.githubusercontent.com/v2fly/${INFO[0]}/release/${INFO[1]}.dat" -o ./resources/${FILE_NAME} - echo -e "Verifying HASH key..." - [ "$(sha256sum "./resources/${FILE_NAME}" | awk -F ' ' '{print $1}')" == "${HASH}" ] || { echo -e "The HASH key of ${FILE_NAME} does not match cloud one."; exit 1; } - echo "unhit=true" >> $GITHUB_OUTPUT - fi - done - - - name: Save Cache - uses: actions/cache/save@v4 - if: ${{ steps.update.outputs.unhit }} - with: - path: resources - key: xray-geodat-${{ github.sha }}-${{ github.run_number }} - build: - needs: prepare permissions: contents: write strategy: @@ -176,7 +132,7 @@ jobs: make find . -maxdepth 1 -type f -regex './\(wxray\|xray\|xray_softfloat\)\(\|.exe\)' -exec mv {} ./build_assets/ \; - - name: Restore Cache + - name: Restore Geodat Cache uses: actions/cache/restore@v4 with: path: resources diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 9620829a..7ef9de65 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -22,7 +22,7 @@ jobs: with: go-version-file: go.mod check-latest: true - - name: Restore Cache + - name: Restore Geodat Cache uses: actions/cache/restore@v4 with: path: resources