Skip to content

Commit 776b840

Browse files
committed
[feature] add action for validate branch
1 parent c1d146c commit 776b840

1 file changed

Lines changed: 41 additions & 0 deletions

File tree

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
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

0 commit comments

Comments
 (0)