chore: Refine CI workflow to skip push events on feature branches
Some checks failed
CI / skip-ci-check (push) Successful in 1m29s
CI / skip-ci-check (pull_request) Successful in 1m28s
CI / python-lint (push) Has been cancelled
CI / test-backend (push) Has been cancelled
CI / build (push) Has been cancelled
CI / secret-scanning (push) Has been cancelled
CI / dependency-scan (push) Has been cancelled
CI / sast-scan (push) Has been cancelled
CI / workflow-summary (push) Has been cancelled
CI / lint-and-type-check (push) Has been cancelled
CI / python-lint (pull_request) Has been cancelled
CI / test-backend (pull_request) Has been cancelled
CI / build (pull_request) Has been cancelled
CI / secret-scanning (pull_request) Has been cancelled
CI / dependency-scan (pull_request) Has been cancelled
CI / sast-scan (pull_request) Has been cancelled
CI / workflow-summary (pull_request) Has been cancelled
CI / lint-and-type-check (pull_request) Has been cancelled

This commit updates the CI workflow to skip push events on feature branches, encouraging the use of pull request events instead. Additionally, it enhances the concurrency management by using commit SHA for grouping runs, preventing duplicate executions for the same commit. These changes improve the efficiency and clarity of the CI process.
This commit is contained in:
Tanya 2026-01-08 10:59:51 -05:00
parent 2f6dae5f8c
commit c0267f262d

View File

@ -2,19 +2,22 @@
name: CI
on:
# Only trigger on push for protected branches (master, dev)
# Feature branches should use pull_request events only to avoid duplicates
push:
branches: [master, dev]
pull_request:
types: [opened, synchronize, reopened]
branches: [master, dev]
# Prevent duplicate runs when pushing to a branch with an open PR
# This ensures only one workflow runs at a time for the same branch/PR
concurrency:
# Group by workflow name and either PR number (for PRs) or branch name (for pushes)
# Use commit SHA to unify push and PR events for the same commit
# This prevents duplicate runs when both push and PR events fire for the same commit
# For PRs: uses PR number to group all runs for that PR
# For pushes: uses branch ref to group all runs for that branch
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
# For PRs: uses head SHA (the commit being tested)
# For pushes: uses the commit SHA from the push event (github.event.after or github.sha)
group: ${{ github.workflow }}-${{ github.event.pull_request.head.sha || github.event.after || github.sha }}
cancel-in-progress: true
jobs:
@ -49,8 +52,19 @@ jobs:
SKIP=0
# Skip push events if this is a push (not a PR) to avoid duplicates with PR events
# PR events are preferred as they provide better context
if [ -z "$GITHUB_EVENT_PULL_REQUEST_NUMBER" ] && [ "$GITHUB_EVENT_NAME" = "push" ]; then
# For push events, only run on master/dev branches (protected branches)
# Feature branches should use PR events only
if [ "$BRANCH_NAME" != "master" ] && [ "$BRANCH_NAME" != "dev" ]; then
echo "Skipping CI: Push event on feature branch '$BRANCH_NAME' (use PR events instead)"
SKIP=1
fi
fi
# Check branch name (case-insensitive)
if echo "$BRANCH_NAME" | grep -qiF "$SKIP_PATTERN"; then
if [ $SKIP -eq 0 ] && echo "$BRANCH_NAME" | grep -qiF "$SKIP_PATTERN"; then
echo "Skipping CI: branch name contains '$SKIP_PATTERN'"
SKIP=1
fi
@ -65,6 +79,7 @@ jobs:
echo "skip=$SKIP" >> $GITHUB_OUTPUT
echo "Branch: $BRANCH_NAME"
echo "Event: ${GITHUB_EVENT_NAME}"
echo "Commit: ${COMMIT_MSG:0:50}..."
echo "Skip CI: $SKIP"