Skip to content

Commit 8255e59

Browse files
CopilotLayZeeDK
andcommitted
fix(workflows): check actual branch in default branch validation
Update the default branch check to validate the actual branch being processed (from input or GITHUB_REF) rather than just GITHUB_REF. This prevents running the workflow on the default branch even when specified via the branch input parameter. Co-authored-by: LayZeeDK <[email protected]>
1 parent fc332b2 commit 8255e59

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

.github/workflows/format.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,17 @@ jobs:
3232
DEFAULT_BRANCH=$(gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name')
3333
echo "default-branch=$DEFAULT_BRANCH" >> $GITHUB_OUTPUT
3434
35+
# Determine the branch being processed
36+
# If a branch was specified via workflow input, use that
37+
# Otherwise, use the branch from GITHUB_REF
38+
if [ -n "${{ inputs.branch }}" ]; then
39+
BRANCH="${{ inputs.branch }}"
40+
else
41+
BRANCH="${GITHUB_REF#refs/heads/}"
42+
fi
43+
3544
# Prevent running on the default branch
36-
if [ "$GITHUB_REF" == "refs/heads/$DEFAULT_BRANCH" ]; then
45+
if [ "$BRANCH" == "$DEFAULT_BRANCH" ]; then
3746
echo "Error: This workflow cannot run on the default branch ($DEFAULT_BRANCH)"
3847
exit 1
3948
fi

0 commit comments

Comments
 (0)