diff --git a/.github/workflows/check_pr_branch.yml b/.github/workflows/check_pr_branch.yml index 7eed5684df..2421422f57 100644 --- a/.github/workflows/check_pr_branch.yml +++ b/.github/workflows/check_pr_branch.yml @@ -5,9 +5,14 @@ jobs: check-PR-branch: runs-on: ubuntu-latest steps: - - name: PRs should not target main - run: | - if [[ "${{ github.base_ref }}" == "main" ]]; then - echo "Pull requests must not be made against main. Please target development instead." - exit 1 - fi + - uses: actions/checkout@v3 + with: + fetch-depth 0 + + - name: Get PR target branch + id: get-target-branch + run: bash .github/workflows/get_pr_target_branch.sh + + - name: No PRs should target the main branch; use development instead + if: ${{ steps.get-target-branch.outputs.target_branch == 'main' }} + run: exit 1 diff --git a/.github/workflows/get_pr_target_branch.sh b/.github/workflows/get_pr_target_branch.sh new file mode 100644 index 0000000000..b0a14ef502 --- /dev/null +++ b/.github/workflows/get_pr_target_branch.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# Get the PR number from the GitHub context +PR_NUMBER=${{ github.event.pull_request.number }} + +# Call the GitHub API to get the PR details +PR_DETAILS=$(curl \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Accept: application/vnd.github.v3+json" \ + "https://api.github.com/repos/${{ github.repository }}/pulls/$PR_NUMBER") + +# Extract the base ref (target branch) from the PR details +TARGET_BRANCH=$(echo "$PR_DETAILS" | jq -r '.base.ref') + +# Output the target branch +echo "::set-output name=target_branch::$TARGET_BRANCH"