Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 25 additions & 3 deletions .github/workflows/bump-version.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name: Bump Version and Tag

on:
push:
branches:
- main
workflow_dispatch:
schedule:
- cron: "0 12 * * *"

jobs:
bump-version:
Expand All @@ -27,19 +27,37 @@ jobs:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}

- name: Check for new commits since last tag
id: changes
run: |
set -euo pipefail
LAST_TAG=$(git tag --sort=-creatordate | head -n1)
if [ -z "$LAST_TAG" ]; then
echo "No tags yet, treating as changed."
echo "changed=true" >> "$GITHUB_OUTPUT"
elif [ "$(git rev-list "${LAST_TAG}..HEAD" --count)" -gt 0 ]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
else
echo "No commits since $LAST_TAG, skipping."
echo "changed=false" >> "$GITHUB_OUTPUT"
fi

- name: Configure Git identity
if: steps.changes.outputs.changed == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

- name: Resolve current version
if: steps.changes.outputs.changed == 'true'
id: current
run: |
set -euo pipefail
VERSION=$(sed -n 's/.*\.version = "\([^"]*\)".*/\1/p' build.zig.zon)
echo "version=$VERSION" >> "$GITHUB_OUTPUT"

- name: Compute next patch version
if: steps.changes.outputs.changed == 'true'
id: next
run: |
IFS='.' read -r MAJOR MINOR PATCH <<< "${{ steps.current.outputs.version }}"
Expand All @@ -48,6 +66,7 @@ jobs:
echo "version=$NEW_VERSION" >> "$GITHUB_OUTPUT"

- name: Bump version in files
if: steps.changes.outputs.changed == 'true'
env:
OLD: ${{ steps.current.outputs.version }}
NEW: ${{ steps.next.outputs.version }}
Expand All @@ -59,15 +78,18 @@ jobs:
echo "Bumped $OLD -> $NEW"

- name: Commit version bump
if: steps.changes.outputs.changed == 'true'
run: |
git add -A
git commit -m "Release MicroZig ${{ steps.next.outputs.version }}"

- name: Configure Git remote with app token
if: steps.changes.outputs.changed == 'true'
run: |
git remote set-url origin "https://x-access-token:${{ steps.app-token.outputs.token }}@github.com/ZigEmbeddedGroup/microzig.git"

- name: Create and push version tag
if: steps.changes.outputs.changed == 'true'
run: |
git tag "${{ steps.next.outputs.version }}"
git push origin HEAD:main "${{ steps.next.outputs.version }}"
Loading