From c0267f262dab98875b89943d55a2bc2040b328ac Mon Sep 17 00:00:00 2001 From: Tanya Date: Thu, 8 Jan 2026 10:59:51 -0500 Subject: [PATCH] chore: Refine CI workflow to skip push events on feature branches 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. --- .gitea/workflows/ci.yml | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index 7fe8f06..b79425e 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -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"