|
4 | 4 | pull_request: |
5 | 5 | branches: |
6 | 6 | - "**" |
7 | | - push: |
8 | | - branches: |
9 | | - - "main" |
10 | | - - "master" |
11 | | - workflow_dispatch: |
12 | 7 |
|
13 | 8 | permissions: |
14 | | - contents: write |
| 9 | + contents: read |
15 | 10 |
|
16 | 11 | jobs: |
17 | 12 | test: |
|
39 | 34 | - name: Coverage |
40 | 35 | run: ./scripts/coverage.sh | tee coverage-report.txt |
41 | 36 |
|
42 | | - - name: Generate coverage badge |
43 | | - if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) |
44 | | - run: | |
45 | | - total=$(go tool cover -func=coverage.out | awk '/^total:/ { sub(/%/,"",$3); print $3 }') |
46 | | - if [[ -z "$total" ]]; then |
47 | | - echo "coverage total not found" >&2 |
48 | | - exit 1 |
49 | | - fi |
50 | | - color="red" |
51 | | - if awk "BEGIN {exit !($total >= 80)}"; then |
52 | | - color="brightgreen" |
53 | | - elif awk "BEGIN {exit !($total >= 60)}"; then |
54 | | - color="yellow" |
55 | | - fi |
56 | | - mkdir -p public/badges |
57 | | - cat > public/badges/coverage.svg <<EOF |
58 | | - <svg xmlns="http://www.w3.org/2000/svg" width="130" height="20" role="img" aria-label="coverage: ${total}%"> |
59 | | - <linearGradient id="s" x2="0" y2="100%"> |
60 | | - <stop offset="0" stop-color="#bbb" stop-opacity=".1"/> |
61 | | - <stop offset="1" stop-opacity=".1"/> |
62 | | - </linearGradient> |
63 | | - <rect rx="3" width="130" height="20" fill="#555"/> |
64 | | - <rect rx="3" x="62" width="68" height="20" fill="${color}"/> |
65 | | - <path fill="${color}" d="M62 0h4v20h-4z"/> |
66 | | - <rect rx="3" width="130" height="20" fill="url(#s)"/> |
67 | | - <g fill="#fff" text-anchor="middle" font-family="Verdana,DejaVu Sans,sans-serif" font-size="11"> |
68 | | - <text x="31" y="14">coverage</text> |
69 | | - <text x="96" y="14">${total}%</text> |
70 | | - </g> |
71 | | - </svg> |
72 | | - EOF |
73 | | -
|
74 | | - - name: Publish coverage badge |
75 | | - if: (github.event_name == 'push' && (github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master')) || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == false) |
76 | | - uses: peaceiris/actions-gh-pages@v4 |
77 | | - with: |
78 | | - github_token: ${{ secrets.GITHUB_TOKEN }} |
79 | | - publish_dir: public |
80 | | - keep_files: true |
81 | | - |
82 | 37 | - name: Upload coverage profile |
83 | 38 | uses: actions/upload-artifact@v4 |
84 | 39 | with: |
|
0 commit comments