Skip to content

Commit

Permalink
Add workflow to check mergeable state executed on pull request
Browse files Browse the repository at this point in the history
  • Loading branch information
grzegorz-roboflow committed Nov 29, 2024
1 parent ed15d1d commit 33e766c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions .github/workflows/check_if_branch_is_mergeable.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: mergeable

on:
pull_request:
branches: [main]
push:
branches: [main]

jobs:
is_mergeable:
runs-on:
labels: depot-ubuntu-22.04-8
group: public-depot
timeout-minutes: 15
steps:
- name: 🛎️ Checkout main
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
ref: main
- name : Store main sha in context
run: echo "main_sha=$(git rev-parse main)" >> "${GITHUB_ENV}"
- name: Calculate depth
run: echo "FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"
- name: 🛎️ Checkout branch with all history
uses: actions/checkout@v4
with:
fetch-depth: ${{ env.FETCH_DEPTH }}
ref: ${{ github.event.pull_request.head.sha }}
- name: Check and store mergable state
id: mergeable_check
run: |
echo "Check if main is ancestor of ${{ github.event.pull_request.head.sha }} (branch HEAD)";
if $(git merge-base --is-ancestor ${{ env.main_sha }} ${{ github.event.pull_request.head.sha }}); then
echo "Branch is mergeable";
exit 0;
else
echo "Branch needs to be updated";
exit 1;
fi

0 comments on commit 33e766c

Please sign in to comment.