From 69764e42c682280ec882b9eb969d82154b586e7f Mon Sep 17 00:00:00 2001 From: Marc Mintel Date: Sat, 14 Feb 2026 14:00:08 +0100 Subject: [PATCH] fix(pipeline): improve prioritization to prevent redundant branch and tag runs --- .gitea/workflows/pipeline.yml | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/.gitea/workflows/pipeline.yml b/.gitea/workflows/pipeline.yml index 4f74318..95a3acd 100644 --- a/.gitea/workflows/pipeline.yml +++ b/.gitea/workflows/pipeline.yml @@ -26,16 +26,17 @@ jobs: REF: ${{ github.ref }} REF_NAME: ${{ github.ref_name }} EVENT: ${{ github.event_name }} + SHA: ${{ github.sha }} run: | echo "🔎 Debug: Event=$EVENT, Ref=$REF, RefName=$REF_NAME, RunId=$RUN_ID" + # Fetch recent runs for the repository + RUNS=$(curl -s -H "Authorization: token $GITEA_TOKEN" "https://git.infra.mintel.me/api/v1/repos/$REPO/actions/runs?limit=30") + case "$REF" in refs/tags/*) echo "🚀 Release detected ($REF_NAME). Cancelling non-tag runs..." - # Fetch all runs - RUNS=$(curl -s -H "Authorization: token $GITEA_TOKEN" "https://git.infra.mintel.me/api/v1/repos/$REPO/actions/runs") - # Identify runs to cancel: in_progress/queued, NOT this run, and NOT a tag run echo "$RUNS" | jq -c '.workflow_runs[] | select(.status == "in_progress" or .status == "queued") | select(.id | tostring != "'$RUN_ID'")' | while read -r run; do ID=$(echo "$run" | jq -r '.id') @@ -54,7 +55,17 @@ jobs: done ;; *) - echo "â„šī¸ Regular push. No prioritization needed." + echo "â„šī¸ Regular push. Checking for parallel release tag for SHA $SHA..." + + # Check if there's a tag run for the SAME commit + TAG_RUN_ID=$(echo "$RUNS" | jq -r '.workflow_runs[] | select(.ref | startswith("refs/tags/")) | select(.head_sha == "'$SHA'") | .id' | head -n 1) + + if [[ -n "$TAG_RUN_ID" && "$TAG_RUN_ID" != "null" ]]; then + echo "🚀 Found parallel tag run $TAG_RUN_ID for commit $SHA. Cancelling this branch run ($RUN_ID)..." + curl -X POST -s -H "Authorization: token $GITEA_TOKEN" "https://git.infra.mintel.me/api/v1/repos/$REPO/actions/runs/$RUN_ID/cancel" + exit 0 + fi + echo "✅ No parallel tag run found. Proceeding." ;; esac