bump-version #555
This file contains 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: | |
schedule: | |
- cron: '0 0 * * *' | |
jobs: | |
bump-version: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
with: | |
fetch-depth: 0 | |
persist-credentials: true | |
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
- uses: baptiste0928/cargo-install@v2 | |
with: | |
crate: cargo-edit | |
- uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
- run: pip install semver | |
- id: defines | |
run: | | |
LATEST_TAG=$(git describe --abbrev=0 --tags) | |
echo "LATEST_TAG=$LATEST_TAG" | |
echo "::set-output name=prev_tag::$LATEST_TAG" | |
- name: Calculate changes from the latest tag to HEAD | |
id: changes | |
run: | | |
COUNT=$(git log ${{ steps.defines.outputs.prev_tag }}..HEAD --pretty=format:"%s" \ | |
--no-merges -P --grep='^(build|ci|feat|fix|docs|style|refactor|perf|test|revert|chore)(\(.*\))?:' \ | |
| awk 'END{print NR}') | |
echo "COUNT=$COUNT" | |
echo "::set-output name=count::$COUNT" | |
- name: Calculate semver level | |
id: semver_level | |
run: | | |
SEMVER_LEVEL=$(git log ${{ steps.defines.outputs.prev_tag }}..HEAD --pretty=format:"%h%x09%H%x09%s" \ | |
--no-merges -P --grep='^(build|ci|feat|fix|docs|style|refactor|perf|test|revert|chore)(\(.*\))?:' \ | |
| python3 "${GITHUB_WORKSPACE}"/.github/semver-level.py) | |
echo "SEMVER_LEVEL=$SEMVER_LEVEL" | |
echo "::set-output name=value::$SEMVER_LEVEL" | |
if: steps.changes.outputs.count > 0 | |
- name: Get the next version | |
id: versions | |
run: | | |
NEXT_VERSION=$(echo ${{ steps.defines.outputs.prev_tag }} | python3 "${GITHUB_WORKSPACE}"/.github/next-semver.py ${{ steps.semver_level.outputs.value }}) | |
echo "NEXT_VERSION=$NEXT_VERSION" | |
echo "::set-output name=next_version::$NEXT_VERSION" | |
echo "::set-output name=next_tag::v$NEXT_VERSION" | |
if: steps.changes.outputs.count > 0 | |
- name: bump version | |
run: | | |
cargo set-version ${{ steps.versions.outputs.next_version }} | |
if: steps.changes.outputs.count > 0 | |
- name: git commit & push | |
id: git_commit_push | |
run: | | |
git config --global user.email "[email protected]" | |
git config --global user.name "Junichi Kato" | |
git diff | |
git add . | |
git commit -m "version up to ${{ steps.versions.outputs.next_tag }}" | |
git push origin main | |
COMMIT_SHA=$(git rev-parse HEAD) | |
echo "::set-output name=commit_sha::$COMMIT_SHA" | |
if: steps.changes.outputs.count > 0 | |
- name: tagging and push tag | |
id: tag_version | |
run: | | |
git tag -a "${{ steps.versions.outputs.next_tag }}" ${{ steps.git_commit_push.outputs.commit_sha }} -m "${{ steps.versions.outputs.next_tag }}" | |
git push origin ${{ steps.versions.outputs.next_tag }} | |
git log ${{ steps.defines.outputs.prev_tag }}..${{ steps.versions.outputs.next_tag }} --pretty=format:"%h%x09%H%x09%s" \ | |
-P --grep='^(build|ci|feat|fix|docs|style|refactor|perf|test|revert|chore)(.*)?:.*$' \ | |
--no-merges --full-history | \ | |
python3 "${GITHUB_WORKSPACE}"/.github/create-release-note.py > changelog.txt | |
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.versions.outputs.next_tag }} | |
release_name: Release ${{ steps.versions.outputs.next_tag }} | |
body_path: changelog.txt | |
if: steps.changes.outputs.count > 0 |