From 09d0f02e850f55a4af24a1045fe98275a78f83c8 Mon Sep 17 00:00:00 2001 From: loyalsoldier <10487845+Loyalsoldier@users.noreply.github.com> Date: Sun, 1 Nov 2020 10:38:53 +0800 Subject: [PATCH] Check update according to upstream latest tag --- .github/workflows/build.yml | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b9ba8372..a97c57ee 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -17,38 +17,49 @@ jobs: with: go-version: ^1.15 - - name: Set variables + - name: Compare latest tags and set variables run: | - echo "RELEASE_NAME=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV - echo "TAG_NAME=$(date +%Y%m%d%H%M%S)" >> $GITHUB_ENV + upstreamLatestTag=$(curl -sSL --connect-timeout 5 -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/v2fly/domain-list-community/releases/latest | grep "tag_name" | cut -d\" -f4) + thisLatestTag=$(curl -sSL --connect-timeout 5 -H "Accept: application/vnd.github.v3+json" https://api.github.com/repos/${{ github.repository }}/releases/latest | grep "tag_name" | cut -d\" -f4) + if [[ $upstreamLatestTag != $thisLatestTag ]]; then + echo "NeedToSync=true" >> $GITHUB_ENV + fi + echo "RELEASE_NAME=$upstreamLatestTag" >> $GITHUB_ENV + echo "TAG_NAME=$upstreamLatestTag" >> $GITHUB_ENV shell: bash - name: Checkout codebase uses: actions/checkout@v2 + if: ${{ env.NeedToSync }} - name: Checkout v2fly/domain-list-community + if: ${{ env.NeedToSync }} uses: actions/checkout@v2 with: repository: v2fly/domain-list-community path: domain-list-community - name: Append attribute rules + if: ${{ env.NeedToSync }} run: | echo "include:geolocation-!cn@cn" >> ./domain-list-community/data/cn echo "include:geolocation-cn@!cn" >> ./domain-list-community/data/geolocation-\!cn - name: Get dependencies and run + if: ${{ env.NeedToSync }} run: | go mod download go run ./ --datapath=./domain-list-community/data - name: Rename to geosite.dat && generate sha256 hash + if: ${{ env.NeedToSync }} run: | cd publish || exit 1 mv dlc.dat geosite.dat sha256sum geosite.dat > geosite.dat.sha256sum - name: Git push assets to "release" branch + if: ${{ env.NeedToSync }} run: | cd publish || exit 1 git init @@ -61,6 +72,7 @@ jobs: git push -f publish release - name: Create a release + if: ${{ env.NeedToSync }} id: create_release uses: actions/create-release@v1 env: @@ -72,6 +84,7 @@ jobs: prerelease: false - name: Upload geosite.dat + if: ${{ env.NeedToSync }} uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -82,6 +95,7 @@ jobs: asset_content_type: application/octet-stream - name: Upload geosite.dat sha256sum + if: ${{ env.NeedToSync }} uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}