From 2b1170cac718253b43c38b9c5b964dd0fd88950f Mon Sep 17 00:00:00 2001 From: Duncan Tourolle Date: Sat, 7 Jun 2025 19:10:12 +0200 Subject: [PATCH] put badges in different branch --- .gitea/workflows/ci.yml | 81 ++++++++++++++++++++++------------------- README.md | 4 +- 2 files changed, 45 insertions(+), 40 deletions(-) diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml index fef49cb..fc96ea5 100644 --- a/.gitea/workflows/ci.yml +++ b/.gitea/workflows/ci.yml @@ -36,12 +36,15 @@ jobs: run: | echo "Downloading initial failed badges..." + # Create cov_info directory first + mkdir -p cov_info + # Download failed badges as defaults - curl -o coverage.svg "https://img.shields.io/badge/coverage-failed-red.svg" - curl -o coverage-docs.svg "https://img.shields.io/badge/docs-failed-red.svg" + curl -o cov_info/coverage.svg "https://img.shields.io/badge/coverage-failed-red.svg" + curl -o cov_info/coverage-docs.svg "https://img.shields.io/badge/docs-failed-red.svg" echo "Initial failed badges created:" - ls -la coverage*.svg + ls -la cov_info/coverage*.svg - name: Run tests with pytest id: pytest @@ -64,13 +67,19 @@ jobs: # Exit-zero treats all errors as warnings flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics + - name: Create coverage info directory + if: always() + run: | + mkdir -p cov_info + echo "Created cov_info directory for coverage data" + - name: Update test coverage badge on success if: steps.pytest.outcome == 'success' && always() run: | echo "Tests passed! Generating successful coverage badge..." if [ -f coverage.json ]; then - coverage-badge -o coverage.svg -f + coverage-badge -o cov_info/coverage.svg -f echo "✅ Test coverage badge updated with actual results" else echo "⚠️ No coverage.json found, keeping failed badge" @@ -82,8 +91,8 @@ jobs: echo "Docs check passed! Generating successful docs badge..." # Remove existing badge first to avoid overwrite error - rm -f coverage-docs.svg - interrogate --generate-badge coverage-docs.svg pyWebLayout/ + rm -f cov_info/coverage-docs.svg + interrogate --generate-badge cov_info/coverage-docs.svg pyWebLayout/ echo "✅ Docs coverage badge updated with actual results" - name: Generate coverage reports @@ -98,8 +107,8 @@ jobs: with open('coverage.json', 'r') as f: coverage_data = json.load(f) total_coverage = round(coverage_data['totals']['percent_covered'], 1) - # Create coverage summary file - with open('coverage-summary.txt', 'w') as f: + # Create coverage summary file in cov_info directory + with open('cov_info/coverage-summary.txt', 'w') as f: f.write(f'{total_coverage}%') print(f'Test Coverage: {total_coverage}%') covered_lines = coverage_data['totals']['covered_lines'] @@ -109,6 +118,11 @@ jobs: print('No coverage data found') " + # Copy other coverage files to cov_info + if [ -f coverage.json ]; then cp coverage.json cov_info/; fi + if [ -f coverage.xml ]; then cp coverage.xml cov_info/; fi + if [ -d htmlcov ]; then cp -r htmlcov cov_info/; fi + - name: Final badge status if: always() run: | @@ -116,48 +130,30 @@ jobs: echo "Test outcome: ${{ steps.pytest.outcome }}" echo "Docs outcome: ${{ steps.docs.outcome }}" - if [ -f coverage.svg ]; then - echo "✅ Test coverage badge: $(ls -lh coverage.svg)" + if [ -f cov_info/coverage.svg ]; then + echo "✅ Test coverage badge: $(ls -lh cov_info/coverage.svg)" else echo "❌ Test coverage badge: MISSING" fi - if [ -f coverage-docs.svg ]; then - echo "✅ Docs coverage badge: $(ls -lh coverage-docs.svg)" + if [ -f cov_info/coverage-docs.svg ]; then + echo "✅ Docs coverage badge: $(ls -lh cov_info/coverage-docs.svg)" else echo "❌ Docs coverage badge: MISSING" fi - echo "All SVG files:" - ls -la *.svg 2>/dev/null || echo "No SVG files found" + echo "Coverage info directory contents:" + ls -la cov_info/ 2>/dev/null || echo "No cov_info directory found" - name: Upload coverage artifacts uses: actions/upload-artifact@v3 with: name: coverage-reports path: | - coverage.svg - coverage-docs.svg - htmlcov/ - coverage.json - coverage.xml - coverage-summary.txt + cov_info/ - - name: Safety check - prevent infinite loops + - name: Commit badges to badges branch if: github.ref == 'refs/heads/master' - run: | - # Check if this is a CI-generated commit - LAST_COMMIT_MSG=$(git log -1 --pretty=%B) - if [[ "$LAST_COMMIT_MSG" == *"[skip ci]"* ]] || [[ "$LAST_COMMIT_MSG" == *"Update coverage badges"* ]]; then - echo "Last commit was CI-generated, skipping badge update to prevent loops" - echo "SKIP_BADGE_COMMIT=true" >> $GITHUB_ENV - else - echo "Safe to update badges" - echo "SKIP_BADGE_COMMIT=false" >> $GITHUB_ENV - fi - - - name: Commit badges to repository - if: github.ref == 'refs/heads/master' && env.SKIP_BADGE_COMMIT != 'true' run: | git config --local user.email "action@gitea.local" git config --local user.name "Gitea Action" @@ -165,15 +161,24 @@ jobs: # Set the remote URL to use the token git remote set-url origin https://${{ secrets.PUSH_TOKEN }}@gitea.tourolle.paris/dtourolle/pyWebLayout.git - # Force add the SVG files (ignore .gitignore) - git add -f coverage.svg coverage-docs.svg + # Create or switch to badges branch + git fetch origin badges:badges 2>/dev/null || git checkout --orphan badges + if git show-ref --verify --quiet refs/heads/badges; then + git checkout badges + fi + + # Remove all files except cov_info + git rm -rf . 2>/dev/null || true + + # Add the coverage info directory + git add -f cov_info/ if git diff --staged --quiet; then echo "No badge changes to commit" else - echo "Committing updated badges..." + echo "Committing updated badges to badges branch..." git commit -m "Update coverage badges [skip ci]" - git push origin HEAD:master + git push origin badges fi - name: Test package installation diff --git a/README.md b/README.md index 221f145..8903a3b 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,8 @@ | Badge | Description | |-------|-------------| -| ![Test Coverage](./coverage.svg) | **Test Coverage** - Percentage of code covered by unit tests | -| ![Documentation Coverage](./coverage-docs.svg) | **Documentation Coverage** - Percentage of code with docstrings | +| ![Test Coverage](https://gitea.tourolle.paris/dtourolle/pyWebLayout/raw/branch/badges/cov_info/coverage.svg) | **Test Coverage** - Percentage of code covered by unit tests | +| ![Documentation Coverage](https://gitea.tourolle.paris/dtourolle/pyWebLayout/raw/branch/badges/cov_info/coverage-docs.svg) | **Documentation Coverage** - Percentage of code with docstrings | | ![License](https://img.shields.io/badge/license-MIT-blue.svg) | **License** - Project licensing information | A Python library for HTML-like layout and rendering. > 📋 **Note**: Badges show results from the commit referenced in the URLs. Red "error" badges indicate build failures for that specific step.