Skip to content

Commit e7d7470

Browse files
committed
Only run on default branch, schedule, or manual dispatch
Add an early guard in entrypoint.sh that skips execution for unsupported event types (e.g. pull_request) and for pushes to non-default branches. Exits cleanly with a warning instead of failing.
1 parent c147651 commit e7d7470

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

entrypoint.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,22 @@ set -euo pipefail
55
cd "${GITHUB_WORKSPACE:-.}"
66
git config --global --add safe.directory "${GITHUB_WORKSPACE:-.}"
77

8+
# ─── Guard: only run on the default branch or scheduled/manual triggers ─────────
9+
EVENT="${GITHUB_EVENT_NAME:-}"
10+
if [ "$EVENT" = "schedule" ] || [ "$EVENT" = "workflow_dispatch" ]; then
11+
: # always allowed
12+
elif [ "$EVENT" = "push" ]; then
13+
DEFAULT_BRANCH=$(git remote show origin | grep 'HEAD branch' | sed 's/.*: //')
14+
CURRENT_BRANCH="${GITHUB_REF#refs/heads/}"
15+
if [ "$CURRENT_BRANCH" != "$DEFAULT_BRANCH" ]; then
16+
echo "::warning::Skipping: push event on '${CURRENT_BRANCH}', not the default branch '${DEFAULT_BRANCH}'."
17+
exit 0
18+
fi
19+
else
20+
echo "::warning::Skipping: unsupported event '${EVENT}'. This action only runs on push to the default branch, schedule, or workflow_dispatch."
21+
exit 0
22+
fi
23+
824
# ─── Helpers ────────────────────────────────────────────────────────────────────
925

1026
# Sanitize user-provided CLI options: allow only flags, alphanumerics, dashes,

0 commit comments

Comments
 (0)