Skip to content

message-derive-bump-version #165

message-derive-bump-version

message-derive-bump-version #165

name: message-derive-bump-version
on:
workflow_dispatch:
inputs:
force_bump:
description: 'Force version bump'
required: true
default: 'false'
type: boolean
schedule:
- cron: '5 0 * * *'
jobs:
bump-version:
runs-on: ubuntu-latest
env:
TARGET_DIR: message-derive
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: true
token: ${{ secrets.PERSONAL_ACCESS_TOKEN }}
- uses: baptiste0928/cargo-install@v3
with:
crate: cargo-edit
- uses: actions/setup-python@v5
with:
python-version: '3.10'
- run: pip install semver
- id: defines
run: |
LATEST_TAG=$(git tag -l --sort=-taggerdate | grep $TARGET_DIR | head -n 1)
LATEST_TAG=${LATEST_TAG:-nexus-actor-$TARGET_DIR-rs-v0.0.0}
echo "LATEST_TAG=$LATEST_TAG"
echo "package_id=$TARGET_DIR" >> $GITHUB_OUTPUT
echo "package_id=nexus-actor-$TARGET_DIR-rs" >> $GITHUB_OUTPUT
echo "prev_tag=$LATEST_TAG" >> $GITHUB_OUTPUT
- name: Calculate changes or force bump
id: changes
run: |
if [[ "${{ github.event.inputs.force_bump }}" == "true" ]]; then
echo "Forcing version bump"
COUNT=1
else
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)(\(.*\))?:' \
-- "${{ steps.defines.outputs.target_dir }}/*" | awk 'END{print NR}')
fi
echo "COUNT=$COUNT"
echo "count=$COUNT" >> $GITHUB_OUTPUT
- name: Calculate semver level
id: semver_level
if: steps.changes.outputs.count > 0
run: |
if [[ "${{ github.event.inputs.force_bump }}" == "true" ]]; then
SEMVER_LEVEL=patch
else
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)(\(.*\))?:' \
-- "${{ steps.defines.outputs.target_dir }}/*" | python3 "${GITHUB_WORKSPACE}"/.github/semver-level.py)
fi
echo "SEMVER_LEVEL=$SEMVER_LEVEL"
echo "value=$SEMVER_LEVEL" >> $GITHUB_OUTPUT
- name: Get the next version
id: versions
if: steps.changes.outputs.count > 0
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 "next_version=$NEXT_VERSION" >> $GITHUB_OUTPUT
echo "next_tag=nexus-actor-${{ steps.defines.outputs.target_dir }}-rs-v$NEXT_VERSION" >> $GITHUB_OUTPUT
- name: bump version
if: steps.changes.outputs.count > 0
run: |
cargo set-version -p ${{ steps.defines.outputs.package_id }} ${{ steps.versions.outputs.next_version }}
- name: git commit & push
id: git_commit_push
if: steps.changes.outputs.count > 0
run: |
git config --global user.email "[email protected]"
git config --global user.name "Junichi Kato"
git diff
git add .
git commit -m "${{ steps.defines.outputs.target_dir }}'s version up to ${{ steps.versions.outputs.next_tag }}"
git push origin main
COMMIT_SHA=$(git rev-parse HEAD)
echo "commit_sha=$COMMIT_SHA" >> $GITHUB_OUTPUT
- name: tagging and push tag
id: tag_version
if: steps.changes.outputs.count > 0
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 -- "${{ steps.defines.outputs.target_dir }}/*" | \
python3 "${GITHUB_WORKSPACE}"/.github/create-release-note.py > changelog.txt
- name: Create a GitHub release
if: steps.changes.outputs.count > 0
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