Refactor CI skip check to use a single pattern
All checks were successful
CI / skip-ci-check (pull_request) Successful in 1m13s
CI / lint-and-test (pull_request) Has been skipped
CI / ansible-validation (pull_request) Has been skipped
CI / secret-scanning (pull_request) Has been skipped
CI / dependency-scan (pull_request) Has been skipped
CI / sast-scan (pull_request) Has been skipped
CI / license-check (pull_request) Has been skipped
CI / vault-check (pull_request) Has been skipped
CI / playbook-test (pull_request) Has been skipped
CI / container-scan (pull_request) Has been skipped
CI / sonar-analysis (pull_request) Has been skipped
CI / workflow-summary (pull_request) Successful in 1m11s

- Simplify the CI workflow by consolidating the skip check for both branch names and commit messages to a single case-insensitive pattern: @skipci.
- Remove the previous multiple pattern checks to streamline the logic and improve readability.
- Ensure that the CI process can be effectively skipped based on the new pattern, enhancing overall efficiency.
This commit is contained in:
ilia 2025-12-28 23:54:02 -05:00
parent 32479d03f8
commit 1b9b801713

View File

@ -21,45 +21,36 @@ jobs:
- name: Check if CI should be skipped
id: check
run: |
# Centralized skip patterns - add more here as needed
SKIP_PATTERNS="skip-ci,no-ci,skip ci,[skip ci],[ci skip]"
# Simple skip pattern: @skipci (case-insensitive)
# Works in branch names and commit messages
SKIP_PATTERN="@skipci"
# Get branch name (works for both push and PR)
# For PRs, GITHUB_HEAD_REF contains the branch name
BRANCH_NAME="${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}"
# Get commit message (works for both push and PR)
# Try multiple sources for commit message
COMMIT_MSG="${GITHUB_EVENT_HEAD_COMMIT_MESSAGE:-}"
if [ -z "$COMMIT_MSG" ]; then
# For PRs, try pull request head commit
COMMIT_MSG="${GITHUB_EVENT_PULL_REQUEST_HEAD_COMMIT_MESSAGE:-}"
fi
if [ -z "$COMMIT_MSG" ]; then
# Fallback: try to get from git log (requires checkout)
COMMIT_MSG=$(git log -1 --pretty=%B 2>/dev/null || echo "")
fi
SKIP=0
# Check branch name (case-insensitive)
for pattern in $(echo $SKIP_PATTERNS | tr ',' ' '); do
if echo "$BRANCH_NAME" | grep -qi "$pattern"; then
echo "Skipping CI: branch name contains '$pattern'"
SKIP=1
break
fi
done
if echo "$BRANCH_NAME" | grep -qiF "$SKIP_PATTERN"; then
echo "Skipping CI: branch name contains '$SKIP_PATTERN'"
SKIP=1
fi
# Check commit message (case-insensitive)
if [ $SKIP -eq 0 ] && [ -n "$COMMIT_MSG" ]; then
for pattern in $(echo $SKIP_PATTERNS | tr ',' ' '); do
if echo "$COMMIT_MSG" | grep -qi "$pattern"; then
echo "Skipping CI: commit message contains '$pattern'"
SKIP=1
break
fi
done
if echo "$COMMIT_MSG" | grep -qiF "$SKIP_PATTERN"; then
echo "Skipping CI: commit message contains '$SKIP_PATTERN'"
SKIP=1
fi
fi
echo "skip=$SKIP" >> $GITHUB_OUTPUT