From 6f326956e0d45a831e41032118642a2844b69712 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B2=99=E6=BC=A0=E4=B9=8B=E5=AD=90?= <7850715+maboloshi@users.noreply.github.com> Date: Fri, 15 Dec 2023 16:17:38 +0800 Subject: [PATCH] =?UTF-8?q?GA:=20=E5=AE=8C=E5=96=84`main.user.js=5Fversion?= =?UTF-8?q?=5Fupdate.yaml`=E9=80=BB=E8=BE=91=201.=20`=E6=9C=80=E8=BF=91?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=98=AF=E5=90=A6=E5=AD=98=E5=9C=A8tag`?= =?UTF-8?q?=E4=BB=A3=E6=9B=BF`=E6=AF=94=E8=BE=83=E6=9C=80=E8=BF=91tag?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E4=BA=A4=E5=92=8C=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4=E7=9A=84sha=E5=80=BC`=202.=20=E6=AF=94=E8=BE=83?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E5=8F=91=E5=B8=83=E7=9A=84`main.user.js`?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E4=BA=A4=E6=97=B6=E9=97=B4=E6=88=B3=E4=B8=8E?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E7=9A=84tag=E5=AF=B9=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E6=8F=90=E4=BA=A4=E6=97=B6=E9=97=B4=E6=88=B3,=20=20=20=20?= =?UTF-8?q?=E5=BD=93=E5=A4=A7=E4=BA=8E=E6=97=B6:=20=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E4=B8=8A=E6=AC=A1=E5=8F=91=E5=B8=83=E7=9A=84`main.user.js`?= =?UTF-8?q?=E7=9A=84=E6=8F=90=E4=BA=A4=E4=B8=AD=E7=9A=84`locals.js`?= =?UTF-8?q?=E4=B8=8E=E5=BD=93=E5=89=8D(=E6=9C=80=E8=BF=91=E6=8F=90?= =?UTF-8?q?=E4=BA=A4)=E6=AF=94=E8=BE=83=20=20=20=20=E5=BD=93=E5=B0=8F?= =?UTF-8?q?=E4=BA=8E=E6=97=B6:=20=E4=BD=BF=E7=94=A8=E4=B8=8A=E6=AC=A1?= =?UTF-8?q?=E7=9A=84tag=E5=AF=B9=E5=BA=94=E7=9A=84=E6=8F=90=E4=BA=A4?= =?UTF-8?q?=E4=B8=AD=E7=9A=84`locals.js`=E4=B8=8E=E5=BD=93=E5=89=8D(?= =?UTF-8?q?=E6=9C=80=E8=BF=91=E6=8F=90=E4=BA=A4)=E6=AF=94=E8=BE=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main.user.js_version_update.yaml | 37 +++++++++++-------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/.github/workflows/main.user.js_version_update.yaml b/.github/workflows/main.user.js_version_update.yaml index f51b2b78e..b46fbeab6 100644 --- a/.github/workflows/main.user.js_version_update.yaml +++ b/.github/workflows/main.user.js_version_update.yaml @@ -14,25 +14,32 @@ jobs: with: fetch-tags: true - - name: Check if commit is ahead of latest tag + - name: Test if locals.js has changed since the last release run: | - LATEST_TAG_COMMIT_SHA=$(git rev-list --tags --max-count=1) - LAST_COMMIT_SHA=${{ github.sha }} - if [ "$LAST_COMMIT_SHA" != "$LATEST_TAG_COMMIT_SHA" ]; then - echo "AHEAD=true" >> $GITHUB_ENV - else - echo "AHEAD=false" >> $GITHUB_ENV - fi + # 最近提交是否存在tag + if [ ! "$(git tag --contains ${{ github.sha }})" ]; then + # 获得最近以`main.user.js Update to version`开头的提交的sha + release_commit_sha=$(git log --grep="^main.user.js Update to version" -n 1 --pretty=format:"%H") + # 对应的时间戳 + release_commit_timestamp=$(git show -s --format=%ct $release_commit_sha) - - name: Get last commit message - run: | - LAST_COMMIT_MESSAGE=$(git log -1 --pretty=format:"%s") - echo "LAST_COMMIT_MESSAGE=$LAST_COMMIT_MESSAGE" >> $GITHUB_ENV + # 最近的tag的时间戳 + latest_tag_commit_sha=$(git rev-list --tags --max-count=1) + latest_tag_commit_timestamp=$(git show -s --format=%ct $latest_tag_commit_sha) + + if [ $release_commit_timestamp -gt $latest_tag_timestamp ]; then + ref=$release_commit_sha + else + ref=$latest_tag_commit_sha + fi + + git diff --quiet --exit-code $ref locals.js || \ + echo "LOCALS_JS_IS_CHANGED=true" >> $GITHUB_ENV + fi - name: Update version in main.user.js if: | - ${{ env.AHEAD == 'true' && - !startsWith(env.LAST_COMMIT_MESSAGE, 'main.user.js Update to version') }} + ${{ env.LOCALS_JS_IS_CHANGED == 'true' }} run: | sed -i -E "s/(@version\s*[0-9]+\.[0-9]+\.[0-9]+)(-[0-9]{4}-[0-9]{2}-[0-9]{2})?/\ \1-$(TZ='Asia/Shanghai' date +'%Y-%m-%d')/" main.user.js @@ -40,7 +47,7 @@ jobs: echo "MAIN_USER_JS_IS_CHANGED=true" >> $GITHUB_ENV - name: Commit and push main.user.js - if: ${{ env.AHEAD == 'true' && + if: ${{ env.LOCALS_JS_IS_CHANGED == 'true' && env.MAIN_USER_JS_IS_CHANGED == 'true' }} run: | bash script/ci_commit_with_signature.sh \