Skip to content

Commit

Permalink
Try again
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpkatz committed Oct 16, 2023
1 parent 58b768d commit eb19358
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 6 deletions.
17 changes: 11 additions & 6 deletions .github/workflows/check_pr_branch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 16 additions & 0 deletions .github/workflows/get_pr_target_branch.sh
Original file line number Diff line number Diff line change
@@ -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"

0 comments on commit eb19358

Please sign in to comment.