🎧 Your Personal Streaming Service
Go airsonicmadsonicmedia-servermusicmusic-servernavidromeopensubsonicraspberry-piself-hostedstreamerstreaming-apistreaming-audiosubsonicsubsonic-server
ci: report Go test coverage on pull requests (#6061)
Deluan Quintão4ed7494a3293
diff --git a/.github/workflows/download-link-on-pr.yml b/.github/workflows/download-link-on-pr.ymlindex 5b421331b..80ec18e90 100644--- a/.github/workflows/download-link-on-pr.yml+++ b/.github/workflows/download-link-on-pr.yml@@ -34,16 +34,19 @@ jobs:}const {data: {artifacts}} = await github.rest.actions.listWorkflowRunArtifacts({owner, repo, run_id});- if (!artifacts.length) {+ const downloadable = artifacts.filter((art) => !art.name.startsWith('octocov-'));+ if (!downloadable.length) {return core.error(`No artifacts found`);}- let body = `Download the artifacts for this pull request:\n`;- for (const art of artifacts) {+ const header = `Download the artifacts for this pull request:`;+ let body = `${header}\n`;+ for (const art of downloadable) {body += `\n* [${art.name}.zip](https://nightly.link/${owner}/${repo}/actions/artifacts/${art.id}.zip)`;}const {data: comments} = await github.rest.issues.listComments({repo, owner, issue_number});- const existing_comment = comments.find((c) => c.user.login === 'github-actions[bot]');+ // Match on the body too: octocov also comments as github-actions[bot].+ const existing_comment = comments.find((c) => c.user.login === 'github-actions[bot]' && c.body.startsWith(header));if (existing_comment) {core.info(`Updating comment ${existing_comment.id}`);await github.rest.issues.updateComment({repo, owner, comment_id: existing_comment.id, body});diff --git a/.github/workflows/pipeline.yml b/.github/workflows/pipeline.ymlindex 37b532eb0..7625cf410 100644--- a/.github/workflows/pipeline.yml+++ b/.github/workflows/pipeline.yml@@ -137,8 +137,10 @@ jobs:- name: Download dependenciesrun: go mod download- - name: Test- run: go test -shuffle=on -tags netgo,sqlite_fts5 -race -v $(go list ./... | grep -v '/plugins$')+ # Name must stay unique across the workflow: octocov matches step names+ # by name across every job, and waits for each match to finish.+ - name: Test with coverage+ run: go test -shuffle=on -tags netgo,sqlite_fts5 -race -v -covermode=atomic -coverprofile=coverage.out $(go list ./... | grep -v '/plugins$')- name: Test ndpgenrun: |@@ -147,6 +149,13 @@ jobs:go build -o ndpgen ../ndpgen --help+ - name: Upload coverage profile+ uses: actions/upload-artifact@v7+ with:+ name: octocov-go+ path: coverage.out+ if-no-files-found: error+go-plugins:name: Test Go pluginsruns-on: ubuntu-latest@@ -169,7 +178,39 @@ jobs:restore-keys: wazero-${{ runner.os }}-- name: Test plugins- run: go tool ginkgo -p -race -tags netgo,sqlite_fts5 ./plugins/+ run: go tool ginkgo -p -race -tags netgo,sqlite_fts5 --cover --covermode=atomic --coverprofile=coverage.out --output-dir=. ./plugins/++ - name: Upload coverage profile+ uses: actions/upload-artifact@v7+ with:+ name: octocov-plugins+ path: coverage.out+ if-no-files-found: error++ coverage:+ name: Report coverage+ runs-on: ubuntu-latest+ needs: [go, go-plugins]+ permissions:+ contents: read+ pull-requests: write+ actions: write+ steps:+ - uses: actions/checkout@v7++ - uses: actions/download-artifact@v8+ with:+ pattern: octocov-*++ # Merge here rather than letting octocov do it: octocov reports statement+ # coverage for a single profile, but switches to line counting for several.+ - name: Merge coverage profiles+ run: |+ echo "mode: atomic" > coverage.out+ awk 'FNR==1 && /^mode:/ {next} {k=$1" "$2; c[k]+=$3} END {for (k in c) print k, c[k]}' \+ octocov-*/coverage.out | sort >> coverage.out++ - uses: k1LoW/octocov-action@v1go-windows:name: Test Go code (Windows)diff --git a/.octocov.yml b/.octocov.ymlnew file mode 100644index 000000000..397b5b364--- /dev/null+++ b/.octocov.yml@@ -0,0 +1,33 @@+# Code coverage reporting for pull requests. See https://github.com/k1LoW/octocov+# The 30s default is not enough: scanning this repo's artifacts for the baseline+# eats most of it, leaving none for the report upload.+timeout: 5m+coverage:+ # A single pre-merged profile: octocov reports statements for one path, but+ # switches to line counting when it merges several itself.+ paths:+ - coverage.out+codeToTestRatio:+ code:+ - '**/*.go'+ - '!**/*_test.go'+ - '!**/*_gen.go'+ test:+ - '**/*_test.go'+testExecutionTime:+ if: true+ steps:+ - Test with coverage+ - Test plugins+diff:+ datastores:+ - artifact://${GITHUB_REPOSITORY}+comment:+ if: is_pull_request+ updatePrevious: true+summary:+ if: true+report:+ if: is_default_branch+ datastores:+ - artifact://${GITHUB_REPOSITORY}