From 194b2aeb0ed0ac7dc266323670923c1344873f00 Mon Sep 17 00:00:00 2001 From: Gabriel Radureau Date: Wed, 8 Apr 2026 16:43:22 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20ensure=20single=20push=20?= =?UTF-8?q?in=20CI/CD=20workflow?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitea/workflows/ci-cd.yaml | 12 ++++++------ scripts/ci-update-coverage-badge.sh | 30 ++++++++++++++++++++++++++++- scripts/ci-version-bump.sh | 17 +++++++++++++++- 3 files changed, 51 insertions(+), 8 deletions(-) diff --git a/.gitea/workflows/ci-cd.yaml b/.gitea/workflows/ci-cd.yaml index 040ed46..55ddfac 100644 --- a/.gitea/workflows/ci-cd.yaml +++ b/.gitea/workflows/ci-cd.yaml @@ -253,25 +253,25 @@ jobs: BDD_COV=${DLC_BDD_COVERAGE%"%"} UNIT_COV=${DLC_UNIT_COVERAGE%"%"} - # Update BDD coverage badge if value is set + # Update BDD coverage badge if value is set (use --no-push to avoid race conditions) if [ -n "$BDD_COV" ]; then echo "📊 Updating BDD coverage badge to ${BDD_COV}%" - ./scripts/ci-update-coverage-badge.sh "$BDD_COV" "bdd" + ./scripts/ci-update-coverage-badge.sh "$BDD_COV" "bdd" --no-push fi - # Update Unit coverage badge if value is set + # Update Unit coverage badge if value is set (use --no-push to avoid race conditions) if [ -n "$UNIT_COV" ]; then echo "📊 Updating Unit coverage badge to ${UNIT_COV}%" - ./scripts/ci-update-coverage-badge.sh "$UNIT_COV" "unit" + ./scripts/ci-update-coverage-badge.sh "$UNIT_COV" "unit" --no-push fi # Check for version bump on main branch if [ "${{ github.ref }}" = "refs/heads/main" ]; then echo "🔖 Checking for version bump..." - ./scripts/version-bump-auto.sh + ./scripts/ci-version-bump.sh "${{ github.event.head_commit.message }}" --no-push fi - # Single push for all commits + # Single push for all commits (this is the ONLY push in the entire workflow) if [ -n "$(git status --porcelain)" ]; then echo "💾 Changes detected, pushing all commits..." git push diff --git a/scripts/ci-update-coverage-badge.sh b/scripts/ci-update-coverage-badge.sh index b15f70b..4f6a608 100755 --- a/scripts/ci-update-coverage-badge.sh +++ b/scripts/ci-update-coverage-badge.sh @@ -1,7 +1,8 @@ #!/bin/bash # CI script to update coverage badge in README.md -# Usage: scripts/ci-update-coverage-badge.sh [badge_type] +# Usage: scripts/ci-update-coverage-badge.sh [badge_type] [flags] # badge_type can be "bdd", "unit", or empty for combined coverage +# flags: --no-commit (skip git commit), --no-push (skip git push) set -e @@ -13,6 +14,18 @@ fi COVERAGE=$1 BADGE_TYPE=${2:-"combined"} +# Parse flags +NO_COMMIT=false +NO_PUSH=false + +for arg in "$@"; do + if [ "$arg" = "--no-commit" ]; then + NO_COMMIT=true + elif [ "$arg" = "--no-push" ]; then + NO_PUSH=true + fi +done + # Determine badge color if (( $(echo "$COVERAGE >= 80" | bc -l) )); then COLOR="brightgreen" @@ -76,7 +89,22 @@ if [ -n "$PACKAGES_TOKEN" ]; then fi git add README.md + +# Skip commit if --no-commit flag is set +if [ "$NO_COMMIT" = true ]; then + echo "Skipping git commit due to --no-commit flag" + echo "Coverage badge updated to ${COVERAGE}% in README.md (not committed)" + exit 0 +fi + if git commit -m "🤖 chore: update coverage badge to ${COVERAGE}% [skip ci]"; then + # Skip push if --no-push flag is set + if [ "$NO_PUSH" = true ]; then + echo "Skipping git push due to --no-push flag" + echo "Coverage badge updated to ${COVERAGE}% and committed locally" + exit 0 + fi + # Try push with retry logic for race conditions for i in 1 2 3; do if git push; then diff --git a/scripts/ci-version-bump.sh b/scripts/ci-version-bump.sh index b900fc7..cbe9a46 100755 --- a/scripts/ci-version-bump.sh +++ b/scripts/ci-version-bump.sh @@ -1,6 +1,6 @@ #!/bin/bash # CI script to handle automatic version bumping -# Usage: scripts/ci-version-bump.sh +# Usage: scripts/ci-version-bump.sh [--no-push] set -e @@ -11,6 +11,14 @@ fi LAST_COMMIT=$1 VERSION_BUMPED="false" +NO_PUSH=false + +# Parse flags +for arg in "$@"; do + if [ "$arg" = "--no-push" ]; then + NO_PUSH=true + fi +done # Automatic version bump based on commit type if echo "$LAST_COMMIT" | grep -q "^✨ feat:"; then @@ -47,6 +55,13 @@ if [ "$VERSION_BUMPED" = "true" ]; then git add VERSION cmd/server/main.go README.md if git commit -m "chore: auto version bump [skip ci]"; then + # Skip push if --no-push flag is set + if [ "$NO_PUSH" = true ]; then + echo "Skipping git push due to --no-push flag" + echo "Successfully bumped version to $NEW_VERSION (committed locally)" + exit 0 + fi + # Try push with retry logic for race conditions for i in 1 2 3; do if git push; then