From 9f6e6e90c59efa5e7b2b4fdad830781978e86d7c Mon Sep 17 00:00:00 2001 From: knowledgecode Date: Sun, 6 Sep 2026 09:17:12 +0900 Subject: [PATCH] ci: migrate coverage badge from self-hosted SVG to Codecov The coverage job previously generated a badge SVG and pushed it directly to master/develop with a contents:write token. Now that master requires PRs and disallows direct pushes, that push no longer fits the branch protection policy. Upload coverage to Codecov instead, which serves the badge itself and needs no git push, letting the job run with contents:read. --- .github/badges/coverage.svg | 20 -------------------- .github/workflows/test.yml | 29 ++++++----------------------- README.md | 2 +- vitest.config.ts | 2 +- 4 files changed, 8 insertions(+), 45 deletions(-) delete mode 100644 .github/badges/coverage.svg diff --git a/.github/badges/coverage.svg b/.github/badges/coverage.svg deleted file mode 100644 index 969d647..0000000 --- a/.github/badges/coverage.svg +++ /dev/null @@ -1,20 +0,0 @@ - - coverage: 100% - - - - - - - - - - - - - \ No newline at end of file diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1b2a8db..f230b7b 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,7 +41,7 @@ jobs: if: github.event_name == 'push' timeout-minutes: 10 permissions: - contents: write + contents: read steps: - name: Checkout code @@ -59,29 +59,12 @@ jobs: - name: Run tests with coverage run: npm run test:coverage - - name: Read coverage summary - id: coverage - run: | - echo "pct=$(jq '.total.lines.pct' coverage/coverage-summary.json)" >> $GITHUB_OUTPUT - - - name: Create badges directory - run: mkdir -p .github/badges - - - name: Generate coverage badge - uses: emibcn/badge-action@f9150fde070fcca0c4e832437611b44838fcd325 # v2.0.4 + - name: Upload coverage to Codecov + uses: codecov/codecov-action@v5 with: - label: 'coverage' - status: ${{ steps.coverage.outputs.pct }}% - color: ${{ fromJSON(steps.coverage.outputs.pct) >= 80 && 'green' || fromJSON(steps.coverage.outputs.pct) >= 60 && 'yellow' || 'red' }} - path: .github/badges/coverage.svg - - - name: Commit coverage badge - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git add .github/badges/coverage.svg - git diff --staged --quiet || git commit -m "Update coverage badge" - git push + token: ${{ secrets.CODECOV_TOKEN }} + files: coverage/lcov.info + fail_ci_if_error: true - name: Upload coverage reports uses: actions/upload-artifact@v7.0.1 diff --git a/README.md b/README.md index c0cef0e..1af3378 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@
[![CI](https://github.com/knowledgecode/date-and-time/actions/workflows/test.yml/badge.svg)](https://github.com/knowledgecode/date-and-time/actions/workflows/test.yml) -[![Coverage](https://raw.githubusercontent.com/knowledgecode/date-and-time/refs/heads/master/.github/badges/coverage.svg)](https://github.com/knowledgecode/date-and-time/actions/workflows/test.yml) +[![Coverage](https://codecov.io/gh/knowledgecode/date-and-time/graph/badge.svg)](https://codecov.io/gh/knowledgecode/date-and-time) [![npm](https://img.shields.io/npm/v/date-and-time)](https://www.npmjs.com/package/date-and-time)
diff --git a/vitest.config.ts b/vitest.config.ts index dc7f5e4..8d84fb7 100644 --- a/vitest.config.ts +++ b/vitest.config.ts @@ -12,7 +12,7 @@ export default defineConfig({ exclude: ['src/**/*.d.ts'], include: ['src/**/*.ts'], provider: 'v8', - reporter: ['json-summary', 'html'], + reporter: ['html', 'lcov'], thresholds: { lines: 100, statements: 100,