Adding release checks for multiple versions #5
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: Release Branch Check | |
| on: | |
| pull_request: | |
| branches: | |
| - 'release/**' | |
| - 'main' | |
| types: [opened, synchronize, reopened] | |
| jobs: | |
| validate-release-branch: | |
| runs-on: ubuntu-latest | |
| env: | |
| RELEASE_BRANCH_PREFIX: 'release/' | |
| CURRENT_RELEASE: 'v2' | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Set PR variables | |
| id: pr | |
| run: | | |
| echo "target_branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT | |
| echo "pr_title=${{ github.event.pull_request.title }}" >> $GITHUB_OUTPUT | |
| echo "pr_labels=${{ github.event.pull_request.labels.*.name }}" >> $GITHUB_OUTPUT | |
| echo "base_sha=${{ github.event.pull_request.base.sha }}" >> $GITHUB_OUTPUT | |
| echo "head_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT | |
| - name: Validate release branch | |
| run: | | |
| # First check if it's a release branch | |
| if [[ ! "${{ steps.pr.outputs.target_branch }}" =~ ^"$RELEASE_BRANCH_PREFIX" ]]; then | |
| # Not a release branch, no need for release validation | |
| exit 0 | |
| fi | |
| # Check if PR has release label | |
| if [[ ! "${{ steps.pr.outputs.pr_labels }}" =~ "release" ]]; then | |
| echo "::error::PRs targeting release branches must have the 'release' label" | |
| exit 1 | |
| fi | |
| # Extract version from branch name (e.g., v2 from release/v2) | |
| BRANCH_VERSION=$(echo "${{ steps.pr.outputs.target_branch }}" | sed "s|$RELEASE_BRANCH_PREFIX||") | |
| # Check if trying to merge to an older release branch | |
| if [[ "$BRANCH_VERSION" != "$CURRENT_RELEASE" ]]; then | |
| # Check for special label that allows merging to older releases | |
| if ! [[ "${{ steps.pr.outputs.pr_labels }}" =~ "allow-older-release" ]]; then | |
| echo "::error::Merging to older release branches (release/$BRANCH_VERSION) is not allowed. Current release is $CURRENT_RELEASE." | |
| echo "::error::If this is intentional, add the 'allow-older-release' label to the PR." | |
| exit 1 | |
| fi | |
| fi | |
| # Additional validation for release PRs | |
| # Check if PR title follows release format | |
| if ! [[ "${{ steps.pr.outputs.pr_title }}" =~ ^Release\ \[[0-9]{4}-[0-9]{2}-[0-9]{2}\]$ ]]; then | |
| echo "::error::Release PR title must follow format: 'Release [YYYY-MM-DD]'" | |
| exit 1 | |
| fi | |
| # Check if CHANGELOG.md has been updated | |
| if ! git diff --name-only "${{ steps.pr.outputs.base_sha }}" "${{ steps.pr.outputs.head_sha }}" | grep -q "CHANGELOG.md"; then | |
| echo "::error::CHANGELOG.md must be updated for releases" | |
| exit 1 | |
| fi |