Skip to content

crond-bump-version #625

crond-bump-version

crond-bump-version #625

name: crond-bump-version
on:
workflow_dispatch:
workflow_run:
workflows:
- parser-release
types:
- completed
schedule:
- cron: '0 0 * * *'
jobs:
bump-version:
runs-on: ubuntu-latest
env:
TARGET_DIR: crond
steps:
- uses: actions/checkout@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 tag -l --sort=-taggerdate | grep $TARGET_DIR | head -n 1)
echo "LATEST_TAG=$LATEST_TAG"
echo "::set-output name=target_dir::$TARGET_DIR"
echo "::set-output name=package_id::oni-comb-$TARGET_DIR-rs"
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)(\(.*\))?:' \
-- "${{ steps.defines.outputs.target_dir }}/*" | 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)(\(.*\))?:' \
-- "${{ steps.defines.outputs.target_dir }}/*" | 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::oni-comb-${{ steps.defines.outputs.target_dir }}-rs-v$NEXT_VERSION"
if: steps.changes.outputs.count > 0
- name: bump version
run: |
cargo set-version -p ${{ steps.defines.outputs.package_id }} ${{ 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 "${{ 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 "::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 -- "${{ steps.defines.outputs.target_dir }}/*" | \
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