Skip to content

Commit

Permalink
Chore: Add auto versioning workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
brenocq committed Mar 4, 2025
1 parent f8eb8d5 commit 41fb9a3
Showing 1 changed file with 81 additions and 0 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/versioning.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
name: 🏷️ Auto Versioning

on:
pull_request:
types:
- synchronize # XXX Temporary to test the workflow
#- closed # Runs when PR is merged

jobs:
versioning:
#if: github.event.pull_request.merged == true # Only run if PR is merged
runs-on: ubuntu-latest
steps:
- name: Checkout Repository
uses: actions/checkout@v4

- name: Set up Git
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
- name: Get PR Labels
id: labels
uses: actions/github-script@v7
with:
script: |
const labels = context.payload.pull_request.labels.map(label => label.name);
console.log("PR Labels:", labels);
return labels;
- name: Determine Version Increment
id: version_type
run: |
echo "::notice::PR Labels Found: ${{ steps.labels.outputs.result }}"
if echo "${{ steps.labels.outputs.result }}" | grep -q "version:major"; then
echo "increment=major" >> $GITHUB_ENV
echo "::notice::Version Increment: major"
elif echo "${{ steps.labels.outputs.result }}" | grep -q "version:minor"; then
echo "increment=minor" >> $GITHUB_ENV
echo "::notice::Version Increment: minor"
else
echo "increment=patch" >> $GITHUB_ENV
echo "::notice::Version Increment: patch"
fi
- name: Read and Increment Version
id: update_version
run: |
VERSION=$(sed -nE 's/project\(atta VERSION ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p' CMakeLists.txt)
if [[ -z "$VERSION" ]]; then
echo "::error::Failed to extract version from CMakeLists.txt"
exit 1
fi
echo "::notice::Current Version: $VERSION"
IFS='.' read -r major minor patch <<< "$VERSION"
case "$increment" in
major) major=$((major + 1)); minor=0; patch=0 ;;
minor) minor=$((minor + 1)); patch=0 ;;
patch) patch=$((patch + 1)) ;;
esac
NEW_VERSION="$major.$minor.$patch"
echo "::notice::New Version: $NEW_VERSION"
sed -i -E "s/(project\(atta VERSION) [0-9]+\.[0-9]+\.[0-9]+/\1 $NEW_VERSION/" CMakeLists.txt
echo "version=$NEW_VERSION" >> $GITHUB_ENV
- name: Commit and Push Updated Version
run: |
git add CMakeLists.txt
git commit --allow-empty -m "Chore: Bump version to ${{ env.version }}"
git push
- name: Create Git Tag
run: |
git tag "v${{ env.version }}"
git push origin "v${{ env.version }}"

0 comments on commit 41fb9a3

Please sign in to comment.