Skip to content

Commit

Permalink
[CI] Added job for wrong target branch detection
Browse files Browse the repository at this point in the history
  • Loading branch information
mnocon committed Oct 18, 2021
1 parent 71182ae commit 5b4d160
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions .github/workflows/pr_check.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: PR check
on:
pull_request:
types:
- opened
- synchronize
- reopened
- edited

jobs:
test-base-branch:
name: Pull Request base branch verification
runs-on: ubuntu-latest
steps:
- uses: octokit/request-action@v2.x
name: Get PR's composer.json
id: pr
with:
branch: "!!str ${{ github.event.pull_request.head.ref }}"
repository: ${{ github.event.pull_request.head.repo.full_name }}
route: /repos/{repository}/contents/composer.json?ref={branch}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- uses: octokit/request-action@v2.x
name: Get base's composer.json
id: base
with:
branch: "!!str ${{ github.event.pull_request.base.ref }}"
repository: ${{ github.event.pull_request.base.repo.full_name }}
route: /repos/{repository}/contents/composer.json?ref={branch}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Verify base branch
run: |
PR_BRANCH_ALIAS=$(echo $PR_DATA | jq -r '.["content"]' | base64 --decode | jq -r '.["extra"]["branch-alias"] | flatten | .[0]')
BASE_BRANCH_ALIAS=$(echo $BASE_DATA | jq -r '.["content"]' | base64 --decode | jq -r '.["extra"]["branch-alias"] | flatten | .[0]')
if [ "$PR_BRANCH_ALIAS" != "$BASE_BRANCH_ALIAS" ]; then
echo "Base branch has different branch-alias than PR."
echo "Pull Request: $PR_BRANCH_ALIAS"
echo "Base branch: $BASE_BRANCH_ALIAS"
exit 1;
fi
env:
PR_DATA: ${{ steps.pr.outputs.data }}
BASE_DATA: ${{ steps.base.outputs.data }}

0 comments on commit 5b4d160

Please sign in to comment.