diff --git a/.github/workflows/main.user.js_version_update.yaml b/.github/workflows/main.user.js_version_update.yaml index f51b2b78e..2b8a257ee 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_commit_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 \