📝 refactor: extract CI logic into reusable scripts
Some checks failed
CI/CD Pipeline / CI Pipeline (push) Has been cancelled
CI/CD Pipeline / CI Pipeline (pull_request) Failing after 11m26s

This commit is contained in:
2026-04-07 08:20:12 +02:00
parent 77b7416d1f
commit 0cc2824222
3 changed files with 144 additions and 78 deletions

View File

@@ -89,56 +89,10 @@ jobs:
COVERAGE=$(grep "total:" coverage.txt | grep -oP '\d+\.\d+' | head -1)
echo "Coverage: ${COVERAGE}%"
# Determine badge color
if (( $(echo "$COVERAGE >= 80" | bc -l) )); then
COLOR="brightgreen"
elif (( $(echo "$COVERAGE >= 50" | bc -l) )); then
COLOR="yellow"
else
COLOR="red"
fi
# Update README with new badge
BADGE_URL="https://img.shields.io/badge/coverage-${COVERAGE}%-${COLOR}?style=flat-square"
sed -i "s|https://img.shields.io/badge/coverage-.*-.*?style=flat-square|${BADGE_URL}|" README.md
# Set up git authentication and commit
git config --global user.name "CI Bot"
git config --global user.email "ci@arcodange.fr"
# Set up credentials using Gitea token
git config --global credential.helper store
echo "https://${{ secrets.PACKAGES_TOKEN }}@gitea.arcodange.lab" > ~/.git-credentials
# Only update if coverage has actually changed
if grep -q "coverage-${COVERAGE}%" README.md; then
echo "Coverage badge already up to date at ${COVERAGE}%"
else
git add README.md
git commit -m "🤖 chore: update coverage badge to ${COVERAGE}% [skip ci]" || echo "No coverage change to commit"
# Try push with retry logic for race conditions
for i in 1 2 3; do
if git push; then
echo "Successfully updated coverage badge to ${COVERAGE}%"
# Update local repo to the new HEAD after successful push
git fetch origin
git reset --hard origin/${{ github.ref_name }}
break
else
echo "Push attempt $i failed, retrying..."
if [ $i -eq 3 ]; then
echo "Final push attempt failed - another job may have updated the badge"
git pull --rebase || true
git push || echo "Recovery push also failed"
# Ensure we're on the latest commit even if push failed
git fetch origin
git reset --hard origin/${{ github.ref_name }}
fi
sleep 2
fi
done
fi
# Update coverage badge using script
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
export GITHUB_REF_NAME="${{ github.ref_name }}"
./scripts/ci-update-coverage-badge.sh "$COVERAGE"
- name: Run go fmt
run: go fmt ./...
@@ -188,34 +142,9 @@ jobs:
NEW_VERSION="$MAJOR.$MINOR.$PATCH${PRERELEASE:+-$PRERELEASE}"
sed -i "s|// @version [0-9.]*|// @version $NEW_VERSION|" cmd/server/main.go
# Commit version changes if bumped
if [ "$VERSION_BUMPED" = "true" ]; then
git config --global user.name "CI Bot"
git config --global user.email "ci@arcodange.fr"
# Set up credentials using Gitea token
git config --global credential.helper store
echo "https://${{ secrets.PACKAGES_TOKEN }}@gitea.arcodange.lab" > ~/.git-credentials
git add VERSION cmd/server/main.go README.md
git commit -m "chore: auto version bump [skip ci]" || echo "No changes to commit"
# Try push with retry logic for race conditions
for i in 1 2 3; do
if git push; then
echo "Successfully bumped version"
break
else
echo "Version bump push attempt $i failed, retrying..."
if [ $i -eq 3 ]; then
echo "Final version bump push attempt failed - another job may have bumped version"
git pull --rebase || true
git push || echo "Version bump recovery push also failed"
fi
sleep 2
fi
done
fi
# Handle version bump using script
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
./scripts/ci-version-bump.sh "$LAST_COMMIT"
- name: Login to Gitea Container Registry
if: github.ref == 'refs/heads/main'