# This GitHub Actions workflow handles version bumping and tag updates. # It can be triggered either by: # 1. Pushing to main branch - automatically bumps version and updates tags # 2. Manual dispatch - allows independent control over stable and latest tags --- name: Version and Tags on: # yamllint disable-line rule:truthy push: branches: - main paths-ignore: - '**/VERSION' - '**/VERSION_YAML' workflow_dispatch: inputs: update_stable: description: "Update stable tag?" required: true default: false type: boolean update_latest: description: "Update latest tag?" required: true default: false type: boolean jobs: version-and-tag: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v4 with: fetch-depth: 0 - name: Set up Git run: | git config user.name "GitHub Actions" git config user.email "actions@github.com" - name: Get PR information id: pr_info if: github.event_name == 'push' uses: actions/github-script@v7 with: script: | try { // Use GitHub's reliable API to find PRs associated with this commit const { data: associatedPRs } = await github.rest.repos.listPullRequestsAssociatedWithCommit({ owner: context.repo.owner, repo: context.repo.repo, commit_sha: context.sha }); if (associatedPRs.length > 0) { // Get the most recent merged PR const pr = associatedPRs.find(pr => pr.state === 'closed' && pr.merged_at) || associatedPRs[0]; return { title: pr.title, body: pr.body || 'No description provided', number: pr.number, found: true }; } else { // Fallback for direct pushes or when no PR is found const commit = await github.rest.repos.getCommit({ owner: context.repo.owner, repo: context.repo.repo, ref: context.sha }); return { title: 'Direct push to main', body: commit.data.commit.message, number: null, found: false }; } } catch (error) { console.log('Could not get PR info:', error.message); return { title: 'Version update', body: 'Automated version bump', number: null, found: false }; } - name: Bump version run: | chmod +x ./versioning/bump_version.sh ./versioning/bump_version.sh - name: Create tag message id: tag_message run: | NEW_VERSION=$(cat ./versioning/VERSION) if [ "${{ github.event_name }}" == "push" ] && [ "${{ steps.pr_info.outcome }}" == "success" ]; then # Use PR information directly in heredoc to avoid quoting issues cat > tag_message.txt << EOF # v${NEW_VERSION} - ${{ fromJson(steps.pr_info.outputs.result).title }} ${{ fromJson(steps.pr_info.outputs.result).body }} EOF else # Manual dispatch or PR info unavailable - simpler message cat > tag_message.txt << EOF # v${NEW_VERSION} - Manual tag update Tag updated via manual workflow dispatch. EOF fi # Store the message for use in subsequent steps echo "TAG_MESSAGE_FILE=tag_message.txt" >> $GITHUB_ENV - name: Push Changes and Tags env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} run: | git push origin main git push origin --tags --force - name: Update stable tag if: | success() && ( github.event_name == 'workflow_dispatch' && inputs.update_stable || github.event_name == 'push' ) run: | # Verify version bump was successful if [ ! -f "./versioning/VERSION" ]; then echo "Error: VERSION file not found. Version bump may have failed." exit 1 fi # Backup existing tag if git rev-parse --verify stable >/dev/null 2>&1; then OLD_STABLE=$(git rev-parse stable) echo "Backing up current stable tag ($OLD_STABLE)" fi # Update tag with detailed message NEW_VERSION=$(cat ./versioning/VERSION) echo "Updating stable tag to $NEW_VERSION" git tag -fa stable -F "$TAG_MESSAGE_FILE" git push origin stable --force - name: Update latest tag if: | success() && ( github.event_name == 'workflow_dispatch' && inputs.update_latest || github.event_name == 'push' ) run: | # Verify version bump was successful if [ ! -f "./versioning/VERSION" ]; then echo "Error: VERSION file not found. Version bump may have failed." exit 1 fi # Backup existing tag if git rev-parse --verify latest >/dev/null 2>&1; then OLD_LATEST=$(git rev-parse latest) echo "Backing up current latest tag ($OLD_LATEST)" fi # Update tag with detailed message NEW_VERSION=$(cat ./versioning/VERSION) echo "Updating latest tag to $NEW_VERSION" git tag -fa latest -F "$TAG_MESSAGE_FILE" git push origin latest --force - name: Cleanup if: always() run: | # Clean up temporary files [ -f tag_message.txt ] && rm tag_message.txt || true ...