Chore(deps): Bump the github-actions group across 1 directory with 2 updates #104
Workflow file for this run
This file contains hidden or 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
| name: 🏷️ Auto Versioning | |
| on: | |
| pull_request: | |
| types: | |
| - labeled # Runs when labels are added to the PR | |
| branches: | |
| - main # Only run for PRs targeting the main branch | |
| if: github.event.pull_request.merged == false # Skip if PR is already merged | |
| jobs: | |
| versioning: | |
| name: Auto Versioning | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Repository | |
| uses: actions/checkout@v5 | |
| with: | |
| fetch-depth: 0 # Fetch full history to enable merging | |
| - 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@v8 | |
| with: | |
| script: | | |
| const labels = context.payload.pull_request.labels.map(label => label.name); | |
| console.log("PR Labels:", labels); | |
| return labels; | |
| - name: Check if Version Label Exists | |
| id: check_version_label | |
| run: | | |
| if echo "${{ steps.labels.outputs.result }}" | grep -Eq "version:(major|minor|patch)"; then | |
| echo "run_versioning=true" >> $GITHUB_ENV | |
| else | |
| echo "::notice::No versioning label found. Skipping workflow." | |
| exit 0 | |
| fi | |
| - name: Merge `main` into PR Branch | |
| if: env.run_versioning == 'true' | |
| run: | | |
| git fetch origin main | |
| git checkout ${{ github.head_ref }} | |
| if git merge --no-edit origin/main; then | |
| echo "Merge successful." | |
| else | |
| echo "::error::Merge conflict detected! Resolve conflicts manually." | |
| exit 1 | |
| fi | |
| continue-on-error: false | |
| - name: Get Current Version from `main` | |
| if: env.run_versioning == 'true' | |
| run: | | |
| VERSION=$(git show origin/main:CMakeLists.txt | sed -nE 's/project\(atta VERSION ([0-9]+\.[0-9]+\.[0-9]+).*/\1/p') | |
| if [[ -z "$VERSION" ]]; then | |
| echo "::error::Failed to extract version from CMakeLists.txt" | |
| exit 1 | |
| fi | |
| echo "::notice::Current Version (from main): $VERSION" | |
| echo "VERSION=$VERSION" >> $GITHUB_ENV | |
| - name: Determine Version Increment | |
| if: env.run_versioning == 'true' | |
| 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: Increment Version | |
| if: env.run_versioning == 'true' | |
| run: | | |
| 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 "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV | |
| - name: Commit Updated Version (If Changed) | |
| if: env.run_versioning == 'true' | |
| run: | | |
| git add CMakeLists.txt | |
| if git diff --staged --quiet; then | |
| echo "No changes to commit." | |
| else | |
| git commit -m "Chore: Bump version to $NEW_VERSION" | |
| git push origin ${{ github.head_ref }} | |
| fi | |
| - name: Delete Old Tag (If Exists) | |
| if: env.run_versioning == 'true' | |
| run: | | |
| if git rev-parse "v$NEW_VERSION" >/dev/null 2>&1; then | |
| git push --delete origin "v$NEW_VERSION" | |
| git tag -d "v$NEW_VERSION" | |
| echo "Deleted existing tag v$NEW_VERSION." | |
| else | |
| echo "No existing tag v$NEW_VERSION found." | |
| fi | |
| - name: Create and Push New Git Tag | |
| if: env.run_versioning == 'true' | |
| run: | | |
| # Fetch the PR title (single quotes to preserve special characters) | |
| PR_TITLE='${{ github.event.pull_request.title }}' | |
| # Fetch the PR number | |
| PR_NUMBER="${{ github.event.pull_request.number }}" | |
| echo "::notice::PR Title: $PR_TITLE" | |
| echo "::notice::PR Number: $PR_NUMBER" | |
| # Create an annotated tag with the PR title as the description | |
| git tag -a "v$NEW_VERSION" -m "PR #$PR_NUMBER - $PR_TITLE" | |
| # Push the tag to the remote repository | |
| git push origin "v$NEW_VERSION" |