File tree Expand file tree Collapse file tree
.github/actions/github-check-branch Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ name : ' Branch Validator'
2+ description : ' Verify that tag or commit is from specified branch'
3+
4+ inputs :
5+ target_branch :
6+ description : ' Branch to validate against'
7+ required : false
8+ default : ' main'
9+ tag_name :
10+ description : ' Tag name to validate (if empty, uses current HEAD)'
11+ required : false
12+ default : ' '
13+
14+ runs :
15+ using : composite
16+ steps :
17+ - name : Checkout repository
18+ uses : actions/checkout@v4
19+ with :
20+ fetch-depth : 0
21+
22+ - name : Validate branch
23+ shell : bash
24+ run : |
25+ TARGET_BRANCH="${{ inputs.target_branch }}"
26+ TAG_NAME="${{ inputs.tag_name }}"
27+
28+ if [ -n "$TAG_NAME" ]; then
29+ COMMIT=$(git rev-list -n 1 "$TAG_NAME")
30+ echo "Checking tag '$TAG_NAME' (commit: $COMMIT)"
31+ else
32+ COMMIT=$(git rev-parse HEAD)
33+ echo "Checking current HEAD (commit: $COMMIT)"
34+ fi
35+
36+ if git merge-base --is-ancestor "$COMMIT" "origin/$TARGET_BRANCH"; then
37+ echo "Commit is from branch '$TARGET_BRANCH'"
38+ else
39+ echo "Commit is NOT from branch '$TARGET_BRANCH'"
40+ exit 1
41+ fi
You can’t perform that action at this time.
0 commit comments