🤖 feat: implement KISS badge update using environment variables
All checks were successful
CI/CD Pipeline / Build Docker Cache (push) Successful in 9s
CI/CD Pipeline / CI Pipeline (push) Successful in 4m52s

- Fix badge URLs and remove duplicates
- Add update-all-badges.sh script for single commit updates
- Update CI/CD workflow to use environment variables
- Remove complex sequential commit logic
- Follow KISS principle with simple env var approach
This commit is contained in:
2026-04-08 15:21:41 +02:00
parent 1fb15fc331
commit 0b6f18f33c
3 changed files with 90 additions and 16 deletions

View File

@@ -199,14 +199,10 @@ jobs:
# Generate BDD coverage report
go tool cover -func=coverage.out > bdd_coverage.txt
# Extract BDD coverage percentage
# Extract BDD coverage percentage and set as environment variable
BDD_COVERAGE=$(grep "total:" bdd_coverage.txt | grep -oP '\d+\.\d+' | head -1)
echo "BDD Coverage: ${BDD_COVERAGE}%"
# Update BDD coverage badge
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
export GITHUB_REF_NAME="${{ github.ref_name }}"
./scripts/ci-update-coverage-badge.sh "$BDD_COVERAGE" "bdd"
echo "DLC_BDD_COVERAGE=${BDD_COVERAGE}%" >> $GITHUB_ENV
- name: Run unit tests with coverage
run: |
@@ -217,14 +213,10 @@ jobs:
# Generate unit coverage report
go tool cover -func=unit_coverage.out > unit_coverage.txt
# Extract unit test coverage percentage
# Extract unit test coverage percentage and set as environment variable
UNIT_COVERAGE=$(grep "total:" unit_coverage.txt | grep -oP '\d+\.\d+' | head -1)
echo "Unit Coverage: ${UNIT_COVERAGE}%"
# Update unit test coverage badge
export PACKAGES_TOKEN="${{ secrets.PACKAGES_TOKEN }}"
export GITHUB_REF_NAME="${{ github.ref_name }}"
./scripts/ci-update-coverage-badge.sh "$UNIT_COVERAGE" "unit"
echo "DLC_UNIT_COVERAGE=${UNIT_COVERAGE}%" >> $GITHUB_ENV
- name: Run go fmt
run: go fmt ./...
@@ -244,6 +236,39 @@ jobs:
# path: pkg/server/docs/swagger.json
# retention-days: 1
# Single badge update step using environment variables (KISS approach)
- name: Update all badges (single commit)
if: always() && github.ref == 'refs/heads/main' && github.actor != 'ci-bot'
run: |
echo "🎯 Updating all badges using environment variables..."
echo "BDD Coverage: ${DLC_BDD_COVERAGE:-Not set}"
echo "Unit Coverage: ${DLC_UNIT_COVERAGE:-Not set}"
# Extract coverage values (remove % sign)
BDD_COV=${DLC_BDD_COVERAGE%"%"}
UNIT_COV=${DLC_UNIT_COVERAGE%"%"}
# Update badges only if values are set
if [ -n "$BDD_COV" ] || [ -n "$UNIT_COV" ]; then
./scripts/update-all-badges.sh "$BDD_COV" "$UNIT_COV"
# Configure git
git config user.name "CI Bot"
git config user.email "ci@arcodange.fr"
git add README.md
# Commit only if there are changes
if git commit -m "🤖 chore: update coverage badges [skip ci]"; then
echo "✅ Badges updated, committing changes..."
git push
echo "🎉 Successfully pushed badge updates"
else
echo " No badge changes to commit"
fi
else
echo "⚠️ No coverage data available to update badges"
fi
# Docker build and push (main branch only)
- name: Login to Gitea Container Registry
if: github.ref == 'refs/heads/main'

View File

@@ -4,8 +4,8 @@
[![Go Report Card](https://goreportcard.com/badge/github.com/arcodange/dance-lessons-coach)](https://goreportcard.com/report/github.com/arcodange/dance-lessons-coach)
[![Version](https://img.shields.io/badge/version-1.4.0-blue.svg)](https://gitea.arcodange.fr/arcodange/dance-lessons-coach/releases)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
[![Coverage](https://img.shields.io/badge/coverage-8.4%-red?style=flat-square)](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)
nhttps://img.shields.io/badge/BDD_Coverage-55.9%-yellow?style=flat-square
[![Coverage](https://img.shields.io/badge/coverage-55.9%-red?style=flat-square)](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)
[![BDD Coverage](https://img.shields.io/badge/BDD_Coverage-55.9%-yellow?style=flat-square)](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)
A Go project demonstrating idiomatic package structure, CLI implementation, and JSON API with Chi router.
=======
@@ -105,8 +105,7 @@ echo "DLC_DATABASE_SSL_MODE=disable" >> $GITHUB_ENV
### Status
[![Build Status](https://gitea.arcodange.fr/api/badges/arcodange/dance-lessons-coach/status)](https://gitea.arcodange.fr/arcodange/dance-lessons-coach)
[![Coverage](https://img.shields.io/badge/coverage-0%-red?style=flat-square)](https://gitea.arcodange.lab/arcodange/dance-lessons-coach)
nhttps://img.shields.io/badge/BDD_Coverage-55.9%-yellow?style=flat-square
=======
-**Linting**: Code quality checks with `go fmt` and `go vet`
-**Version Management**: Automatic version detection

50
scripts/update-all-badges.sh Executable file
View File

@@ -0,0 +1,50 @@
#!/bin/bash
# Simple script to update coverage badges in README.md
# Usage: ./scripts/update-all-badges.sh [bdd_coverage] [unit_coverage]
# Both parameters are optional - only updates what's provided
set -e
BDD_COVERAGE=""
UNIT_COVERAGE=""
# Parse arguments (both optional)
if [ -n "$1" ]; then
BDD_COVERAGE=$1
fi
if [ -n "$2" ]; then
UNIT_COVERAGE=$2
fi
echo "🎯 Updating coverage badges..."
if [ -n "$BDD_COVERAGE" ]; then
echo " BDD: ${BDD_COVERAGE}%"
fi
if [ -n "$UNIT_COVERAGE" ]; then
echo " Unit: ${UNIT_COVERAGE}%"
fi
# Update BDD coverage badge if provided
if [ -n "$BDD_COVERAGE" ] && grep -q "BDD_Coverage" README.md; then
sed -i '' "s/BDD_Coverage-[0-9.]\+-%/BDD_Coverage-${BDD_COVERAGE}-%/g" README.md
echo "✅ BDD coverage badge updated to ${BDD_COVERAGE}%"
fi
# Update Unit coverage badge if provided
if [ -n "$UNIT_COVERAGE" ] && grep -q "Unit_Coverage" README.md; then
sed -i '' "s/Unit_Coverage-[0-9.]\+-%/Unit_Coverage-${UNIT_COVERAGE}-%/g" README.md
echo "✅ Unit coverage badge updated to ${UNIT_COVERAGE}%"
fi
# Update main coverage badge if BDD coverage provided
if [ -n "$BDD_COVERAGE" ] && grep -q "coverage-[0-9.]\+-%" README.md; then
sed -i '' "s/coverage-[0-9.]\+-%/coverage-${BDD_COVERAGE}-%/g" README.md
echo "✅ Main coverage badge updated to ${BDD_COVERAGE}%"
fi
if [ -z "$BDD_COVERAGE" ] && [ -z "$UNIT_COVERAGE" ]; then
echo " No coverage values provided - nothing to update"
fi
echo "🎉 Badge update process completed!"