Adding release checks for multiple versions #1
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] | |
| env: | |
| RELEASE_BRANCH_PREFIX: 'release/' | |
| CURRENT_RELEASE: 'v2' | |
| jobs: | |
| validate-release-branch: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| - name: Validate release branch | |
| run: | | |
| # First check if it's a release branch | |
| if [[ ! "${{ github.base_ref }}" =~ ^${{ env.RELEASE_BRANCH_PREFIX }} ]]; then | |
| echo "::error::Releases are only allowed to branches starting with '${{ env.RELEASE_BRANCH_PREFIX }}'. Current target branch: ${{ github.base_ref }}" | |
| exit 1 | |
| fi | |
| # Extract version from branch name (e.g., v2 from release/v2) | |
| BRANCH_VERSION=$(echo "${{ github.base_ref }}" | sed "s|${{ env.RELEASE_BRANCH_PREFIX }}||") | |
| # Check if trying to merge to an older release branch | |
| if [[ "$BRANCH_VERSION" != "${{ env.CURRENT_RELEASE }}" ]]; then | |
| # Check for special label that allows merging to older releases | |
| if ! [[ "${{ github.event.pull_request.labels.*.name }}" =~ "allow-older-release" ]]; then | |
| echo "::error::Merging to older release branches (release/$BRANCH_VERSION) is not allowed. Current release is ${{ env.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 | |
| if [[ "${{ github.base_ref }}" =~ ^${{ env.RELEASE_BRANCH_PREFIX }} ]]; then | |
| # Check if PR title follows release format | |
| if ! [[ "${{ github.event.pull_request.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 ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} | grep -q "CHANGELOG.md"; then | |
| echo "::error::CHANGELOG.md must be updated for releases" | |
| exit 1 | |
| fi | |
| fi |