Bump Version #1654
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Bump Version | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| force_bump: | |
| description: 'Force version bump' | |
| required: true | |
| type: boolean | |
| default: false | |
| schedule: | |
| - cron: '0 0 * * *' | |
| jobs: | |
| bump-version: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 | |
| persist-credentials: false | |
| token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| - name: Calculate changes from the latest tag to HEAD | |
| id: changes | |
| run: | | |
| # タグが存在するか確認 | |
| if git tag -l | grep -q .; then | |
| LATEST_TAG=$(git describe --abbrev=0 --tags) | |
| echo "latest-tag = $LATEST_TAG" | |
| # 最新タグから現在までの変更をカウント | |
| COUNT=$(git log $LATEST_TAG..HEAD --pretty=format:"%s" --no-merges \ | |
| --grep='^build:' \ | |
| --grep='^ci:' \ | |
| --grep='^feat:' \ | |
| --grep='^fix:' \ | |
| --grep='^docs:' \ | |
| --grep='^style:' \ | |
| --grep='^refactor:' \ | |
| --grep='^perf:' \ | |
| --grep='^test:' \ | |
| --grep='^revert:' \ | |
| --grep='^chore:' | awk 'END{print NR}') | |
| else | |
| echo "No tags found - using initial commit as base" | |
| # 初期コミットから現在までの変更をカウント(初回実行時) | |
| FIRST_COMMIT=$(git rev-list --max-parents=0 HEAD) | |
| COUNT=$(git log $FIRST_COMMIT..HEAD --pretty=format:"%s" --no-merges \ | |
| --grep='^build:' \ | |
| --grep='^ci:' \ | |
| --grep='^feat:' \ | |
| --grep='^fix:' \ | |
| --grep='^docs:' \ | |
| --grep='^style:' \ | |
| --grep='^refactor:' \ | |
| --grep='^perf:' \ | |
| --grep='^test:' \ | |
| --grep='^revert:' \ | |
| --grep='^chore:' | awk 'END{print NR}') | |
| # 初回は必ず1以上にしてタグ付けができるようにする | |
| if [ "$COUNT" -eq "0" ]; then | |
| COUNT=1 | |
| fi | |
| fi | |
| echo "steps.changes.outputs.count = $COUNT" | |
| if [[ "${{ inputs.force_bump }}" == "true" ]]; then | |
| echo "count=1" >> $GITHUB_OUTPUT | |
| else | |
| echo "count=$COUNT" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Bump version and push tag | |
| id: tag_version | |
| uses: mathieudutour/[email protected] | |
| with: | |
| github_token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| default_bump: patch | |
| if: steps.changes.outputs.count > 0 | |
| - name: Create a GitHub release | |
| uses: actions/create-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
| with: | |
| tag_name: ${{ steps.tag_version.outputs.new_tag }} | |
| release_name: Release ${{ steps.tag_version.outputs.new_tag }} | |
| body: ${{ steps.tag_version.outputs.changelog }} | |
| if: steps.changes.outputs.count > 0 |