Skip to content

Check New Commit and Bump Version #240

Check New Commit and Bump Version

Check New Commit and Bump Version #240

Workflow file for this run

name: Check New Commit and Bump Version
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:
jobs:
check-commit:
permissions:
contents: write
runs-on: ubuntu-latest
outputs:
updated: ${{ steps.updated.outputs.updated }}
steps:
- name: Setup
uses: cordiverse/workflows/.github/actions/setup@main
- name: Checkout Landosol Roster
uses: actions/checkout@v4
with:
repository: Ice9Coffee/LandosolRoster
path: LandosolRoster
fetch-depth: 0
- name: Get latest commit SHA
id: lastest-commit
run: |
latest_commit_sha=$(git -C LandosolRoster log -1 --format=%h)
version=$(jq -r '.version' packages/landosol-roster/package.json | awk '{print $1}')
if [[ $version == *"+"* ]]; then
sha=${version#*+}
echo $sha
echo "CURRENT_COMMIT_SHA=$sha" >> $GITHUB_OUTPUT
else
sha=""
echo "None commit hash."
fi
if [[ $sha != $latest_commit_sha ]]; then
echo "New commit found."
echo "IS_NEW_COMMIT_SHA=true" >> $GITHUB_OUTPUT
echo "LATEST_COMMIT_SHA=$latest_commit_sha" >> $GITHUB_OUTPUT
else
echo "No new commit found."
echo "IS_NEW_COMMIT_SHA=false" >> $GITHUB_OUTPUT
fi
if [[ -z "$sha" ]]; then
# 获取第一个提交的 SHA
first_commit_sha=$(git -C LandosolRoster rev-list --max-parents=0 HEAD | cut -c1-7)
sha=$first_commit_sha
echo "CURRENT_COMMIT_SHA=$sha" >> $GITHUB_OUTPUT
fi
- name: Get latest commit message
id: lastest-commit-message
if: steps.lastest-commit.outputs.IS_NEW_COMMIT_SHA == 'true'
run: |
current_sha=${{steps.lastest-commit.outputs.CURRENT_COMMIT_SHA}}
latest_sha=${{steps.lastest-commit.outputs.LATEST_COMMIT_SHA}}
if [[ "$current_sha" != "$latest_sha" ]]; then
latest_commit_message=$(git -C LandosolRoster log --pretty=format:"%s" $current_sha..$latest_sha | grep -c 'auto sync to json')
echo "found $latest_commit_message commit message."
if [[ "$latest_commit_message" -ne 0 ]]; then
echo "IS_SYNC=true" >> $GITHUB_OUTPUT
else
echo "IS_SYNC=false" >> $GITHUB_OUTPUT
fi
else
echo "IS_SYNC=false" >> $GITHUB_OUTPUT
fi
- name: Bump version
if: steps.lastest-commit.outputs.IS_NEW_COMMIT_SHA == 'true' && steps.lastest-commit-message.outputs.IS_SYNC == 'true'
run: |
yarn bump -3 landosol-roster
version=$(jq -r '.version' packages/landosol-roster/package.json | awk '{print $1}')
echo $version
latest_commit_sha=${{steps.lastest-commit.outputs.LATEST_COMMIT_SHA}}
version="${version}+${latest_commit_sha}"
echo "Bump version to $version."
jq --arg version "$version" '.version = $version' packages/landosol-roster/package.json > package.json.tmp && mv package.json.tmp packages/landosol-roster/package.json
version=$(jq -r '.version' packages/landosol-roster/package.json | awk '{print $1}')
echo $version
- name: Commit and push
if: steps.lastest-commit.outputs.IS_NEW_COMMIT_SHA == 'true' && steps.lastest-commit-message.outputs.IS_SYNC == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
git add packages/landosol-roster/package.json
git commit -m "chore: auto bump version"
git push origin master
- name: Set output
id: updated
if: steps.lastest-commit.outputs.IS_NEW_COMMIT_SHA == 'true' && steps.lastest-commit-message.outputs.IS_SYNC == 'true'
run: echo "updated=true" >> $GITHUB_OUTPUT
publish:
needs: check-commit
if: needs.check-commit.outputs.updated == 'true'
uses: ./.github/workflows/publish.yml
secrets:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}