From 34855932863679e75b23b98140ce9817ed53e353 Mon Sep 17 00:00:00 2001 From: Meo597 <197331664+Meo597@users.noreply.github.com> Date: Sat, 3 May 2025 12:52:11 +0800 Subject: [PATCH] Workflows: Ensure Geodat exists --- .github/workflows/release-win7.yml | 31 +++++++++++++ .github/workflows/release.yml | 46 +++++++++++++++++++ .github/workflows/scheduled-assets-update.yml | 4 +- .github/workflows/test.yml | 29 ++++++++++++ 4 files changed, 108 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release-win7.yml b/.github/workflows/release-win7.yml index 239de1b5..bdf5117f 100644 --- a/.github/workflows/release-win7.yml +++ b/.github/workflows/release-win7.yml @@ -9,7 +9,38 @@ on: types: [opened, synchronize, reopened] jobs: + check-assets: + runs-on: ubuntu-latest + steps: + - name: Restore Geodat Cache + uses: actions/cache/restore@v4 + with: + path: resources + key: xray-geodat- + + - name: Check Assets Existence + id: check-assets + run: | + [ -d 'resources' ] || mkdir resources + LIST=('geoip.dat' 'geosite.dat') + for FILE_NAME in "${LIST[@]}" + do + echo -e "Checking ${FILE_NAME}..." + if [ -s "./resources/${FILE_NAME}" ]; then + echo -e "${FILE_NAME} exists." + else + echo -e "${FILE_NAME} does not exist." + echo "missing=true" >> $GITHUB_OUTPUT + break + fi + done + + - name: Sleep for 90 seconds if Assets Missing + if: steps.check-assets.outputs.missing == 'true' + run: sleep 90 + build: + needs: check-assets permissions: contents: write strategy: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index c52f585e..130ea983 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,7 +9,53 @@ on: types: [opened, synchronize, reopened] jobs: + check-assets: + runs-on: ubuntu-latest + steps: + - name: Restore Geodat Cache + uses: actions/cache/restore@v4 + with: + path: resources + key: xray-geodat- + + - name: Check Assets Existence + id: check-assets + run: | + [ -d 'resources' ] || mkdir resources + LIST=('geoip.dat' 'geosite.dat') + for FILE_NAME in "${LIST[@]}" + do + echo -e "Checking ${FILE_NAME}..." + if [ -s "./resources/${FILE_NAME}" ]; then + echo -e "${FILE_NAME} exists." + else + echo -e "${FILE_NAME} does not exist." + echo "missing=true" >> $GITHUB_OUTPUT + break + fi + done + + - name: Trigger Asset Update Workflow if Assets Missing + if: steps.check-assets.outputs.missing == 'true' + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GITHUB_TOKEN }} + script: | + const { owner, repo } = context.repo; + await github.rest.actions.createWorkflowDispatch({ + owner, + repo, + workflow_id: 'scheduled-assets-update.yml', + ref: context.ref + }); + console.log('Triggered scheduled-assets-update.yml due to missing assets on branch:', context.ref); + + - name: Sleep for 90 seconds if Assets Missing + if: steps.check-assets.outputs.missing == 'true' + run: sleep 90 + build: + needs: check-assets permissions: contents: write strategy: diff --git a/.github/workflows/scheduled-assets-update.yml b/.github/workflows/scheduled-assets-update.yml index fb3ca455..954ba955 100644 --- a/.github/workflows/scheduled-assets-update.yml +++ b/.github/workflows/scheduled-assets-update.yml @@ -1,6 +1,6 @@ name: Scheduled assets update -# NOTE: This Github Actions is required by other actions, for preparing other packaging assets in a +# 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) @@ -9,7 +9,7 @@ on: workflow_dispatch: schedule: # Update GeoData on every day (22:30 UTC) - - cron: '30 22 * * *' + - cron: "30 22 * * *" push: # Prevent triggering update request storm paths: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 7ef9de65..c853a143 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -6,7 +6,36 @@ on: types: [opened, synchronize, reopened] jobs: + check-assets: + runs-on: ubuntu-latest + steps: + - name: Restore Geodat Cache + uses: actions/cache/restore@v4 + with: + path: resources + key: xray-geodat- + - name: Check Assets Existence + id: check-assets + run: | + [ -d 'resources' ] || mkdir resources + LIST=('geoip.dat' 'geosite.dat') + for FILE_NAME in "${LIST[@]}" + do + echo -e "Checking ${FILE_NAME}..." + if [ -s "./resources/${FILE_NAME}" ]; then + echo -e "${FILE_NAME} exists." + else + echo -e "${FILE_NAME} does not exist." + echo "missing=true" >> $GITHUB_OUTPUT + break + fi + done + - name: Sleep for 90 seconds if Assets Missing + if: steps.check-assets.outputs.missing == 'true' + run: sleep 90 + test: + needs: check-assets permissions: contents: read runs-on: ${{ matrix.os }}