[PPSC-1141] fix(ci): pin PR scan logo URL to main (#270) #988
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: CI | |
| on: | |
| pull_request: | |
| branches: [main] | |
| push: | |
| branches: [main] | |
| permissions: | |
| contents: read | |
| jobs: | |
| test: | |
| name: Test & Coverage (${{ matrix.os }}) | |
| runs-on: ${{ matrix.os }} | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| include: | |
| # Race detector adds 2-10x overhead; running only on Linux is sufficient | |
| - os: ubuntu-latest | |
| race: true | |
| - os: macos-latest | |
| race: false | |
| - os: windows-latest | |
| race: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 # v7 | |
| - name: Set up Go | |
| uses: actions/setup-go@924ae3a1cded613372ab5595356fb5720e22ba16 # v6 | |
| with: | |
| go-version: "1.25" | |
| cache: true | |
| - name: Install gotestsum | |
| run: go install gotest.tools/gotestsum@v1.13.0 | |
| - name: Run tests | |
| shell: bash | |
| run: | | |
| TEST_FLAGS="" | |
| if [ "${{ matrix.race }}" = "true" ]; then | |
| TEST_FLAGS="-race -coverprofile=coverage.out -covermode=atomic" | |
| fi | |
| gotestsum --format testdox -- $(go list ./... | grep -v -e '/testutil$' -e '/test$') $TEST_FLAGS | |
| - name: Coverage summary | |
| if: matrix.race == true | |
| id: coverage | |
| shell: bash | |
| run: | | |
| go tool cover -func=coverage.out | tee coverage.txt | |
| total=$(go tool cover -func=coverage.out | awk '/total:/ {print $3}') | |
| echo "total=${total}" >> "$GITHUB_OUTPUT" | |
| - name: Upload coverage artifact | |
| if: matrix.race == true | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: coverage | |
| path: | | |
| coverage.out | |
| coverage.txt | |
| lint: | |
| uses: ./.github/workflows/reusable-lint.yml | |
| # Posts a sticky coverage comment to PRs (updates in place, details collapsed) | |
| coverage-comment: | |
| name: Coverage Comment | |
| needs: test | |
| if: github.event_name == 'pull_request' | |
| runs-on: ubuntu-latest | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Download Linux coverage | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8 | |
| with: | |
| name: coverage | |
| path: coverage | |
| - name: Post PR comment | |
| uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9 | |
| with: | |
| retries: 3 | |
| script: | | |
| const fs = require('fs'); | |
| const summary = fs.readFileSync('coverage/coverage.txt', 'utf8'); | |
| const total = summary.split('\n').find(line => line.includes('total:')); | |
| const marker = '<!-- coverage-comment -->'; | |
| const body = `${marker}\n### Test Coverage Report\n\n**${total || 'Coverage data not found'}**\n\n<details>\n<summary>Coverage by function</summary>\n\n\`\`\`\n${summary}\n\`\`\`\n</details>`; | |
| // Find existing comment | |
| const { data: comments } = await github.rest.issues.listComments({ | |
| ...context.repo, | |
| issue_number: context.issue.number | |
| }); | |
| const existing = comments.find(c => c.body.includes(marker)); | |
| if (existing) { | |
| await github.rest.issues.updateComment({ | |
| ...context.repo, | |
| comment_id: existing.id, | |
| body | |
| }); | |
| } else { | |
| await github.rest.issues.createComment({ | |
| ...context.repo, | |
| issue_number: context.issue.number, | |
| body | |
| }); | |
| } |