-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
81 additions
and
0 deletions.
There are no files selected for viewing
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
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 }}" |