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"