Skip to content

Commit

Permalink
GA: 完善main.user.js_version_update.yaml逻辑
Browse files Browse the repository at this point in the history
1. `最近提交是否存在tag`代替`比较最近tag的提交和最近提交的sha值`
2. 比较上次发布的`main.user.js`的提交时间戳与上次的tag对应的提交时间戳,
   当大于时: 使用上次发布的`main.user.js`的提交中的`locals.js`与当前(最近提交)比较
   当小于时: 使用上次的tag对应的提交中的`locals.js`与当前(最近提交)比较
  • Loading branch information
maboloshi committed Dec 15, 2023
1 parent 97f3a9c commit 2409b02
Showing 1 changed file with 22 additions and 15 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/main.user.js_version_update.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,40 @@ 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
git diff --quiet --exit-code main.user.js || \
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 \
Expand Down

0 comments on commit 2409b02

Please sign in to comment.