Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
on:
push:
branches:
- main
pull_request:

name: Go test coverage

jobs:
coverage:
name: Measure test coverage (unit + integration tests)
runs-on: ubuntu-latest
steps:
- name: Install golang
uses: actions/setup-go@v5
with:
go-version: "1.25"

- name: Check out repository code
uses: actions/checkout@v4

- name: Run unit tests with coverage
run: go test -coverpkg=./... -coverprofile=coverage-unit.out -covermode=atomic ./...

- name: Set up coverage directory
run: |
GOCOVERDIR="$(pwd)/coverage-integration"
echo "GOCOVERDIR=${GOCOVERDIR}" >> "$GITHUB_ENV"
rm -rf "$GOCOVERDIR"
mkdir -p "$GOCOVERDIR"

- name: Run integration tests with coverage
run: |
source test/ci/utils.sh
install_server

passed=0
failed=0
for t in test/ci/test-*.sh; do
echo "=== Running: $t ==="
source "$t"
if run_test; then
passed=$((passed + 1))
else
failed=$((failed + 1))
echo "WARN: $t failed, continuing"
fi
cleanup || true
done
echo "=== Integration tests: $passed passed, $failed failed ==="

- name: Merge coverage profiles
run: |
go tool covdata textfmt -i="$GOCOVERDIR" -o=coverage-integration.out
go install github.com/wadey/gocovmerge@latest
gocovmerge coverage-unit.out coverage-integration.out > coverage.out

- name: Download base coverage breakdown
id: download-main-breakdown
uses: dawidd6/action-download-artifact@v6
with:
branch: main
workflow_conclusion: success
name: main.breakdown
if_no_artifact_found: warn

# continue-on-error: allow workflow to proceed to post PR comment and upload artifacts
- name: Check coverage thresholds
id: coverage
uses: vladopajic/go-test-coverage@v2
continue-on-error: true
with:
config: .testcoverage.yml
breakdown-file-name: ${{ github.ref_name == 'main' && 'main.breakdown' || '' }}
diff-base-breakdown-file-name: ${{ steps.download-main-breakdown.outputs.found_artifact == 'true' && 'main.breakdown' || '' }}

- name: Find pull request ID
run: |
PR_DATA=$(curl -s -H "Authorization: token ${{ github.token }}" \
"https://api.github.com/repos/${{ github.repository }}/pulls?head=${{ github.repository_owner }}:${{ github.head_ref || github.ref_name }}&state=open")
PR_ID=$(echo "$PR_DATA" | jq -r '.[0].number')
if [ "$PR_ID" != "null" ]; then
echo "pull_request_id=$PR_ID" >> "$GITHUB_ENV"
else
echo "No open pull request found for branch ${{ github.head_ref || github.ref_name }}."
fi

- name: Post coverage report to PR
if: env.pull_request_id
uses: thollander/actions-comment-pull-request@v3
with:
github-token: ${{ github.token }}
comment-tag: coverage-report
pr-number: ${{ env.pull_request_id }}
message: |
`go-test-coverage` report
```
${{ fromJSON(steps.coverage.outputs.report) }}```

- name: Upload coverage breakdown
uses: actions/upload-artifact@v4
if: github.ref_name == 'main'
with:
name: main.breakdown
path: main.breakdown
if-no-files-found: error

- name: Generate HTML report
if: always()
run: go tool cover -html=coverage.out -o coverage.html

- name: Upload coverage report
if: always()
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage.html

# fail the workflow if coverage thresholds are not met, after PR comment and artifacts are posted
- name: Fail if coverage thresholds not met
if: steps.coverage.outcome == 'failure'
shell: bash
run: echo "Coverage thresholds are not met." && exit 1
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@ go-fdo-server
go-fdo-server-*.tar.*
rpmbuild
test/workdir
coverage*.out
coverage*.html
coverage-integration/
8 changes: 8 additions & 0 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
profile: coverage.out
threshold:
file: 0
package: 0
total: 0
exclude:
paths:
- \.gen\.go$
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ require (
github.com/jackc/pgx/v5 v5.7.6
github.com/mattn/go-sqlite3 v1.14.32
github.com/mitchellh/mapstructure v1.5.0
github.com/oapi-codegen/runtime v1.1.2
github.com/oapi-codegen/runtime v1.2.0
github.com/spf13/cobra v1.9.1
github.com/spf13/viper v1.20.1
golang.org/x/time v0.11.0
Expand Down Expand Up @@ -38,7 +38,7 @@ require (
github.com/mailru/easyjson v0.7.7 // indirect
github.com/mohae/deepcopy v0.0.0-20170929034955-c48cc78d4826 // indirect
github.com/neilotoole/jsoncolor v0.7.1 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 // indirect
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 // indirect
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 // indirect
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 // indirect
github.com/pelletier/go-toml/v2 v2.2.3 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -105,10 +105,10 @@ github.com/nwidger/jsoncolor v0.3.2/go.mod h1:Cs34umxLbJvgBMnVNVqhji9BhoT/N/KinH
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE=
github.com/nxadm/tail v1.4.8/go.mod h1:+ncqLTQzXmGhMZNUePPaPqPvBxHAIsmXswZKocGu+AU=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1 h1:5vHNY1uuPBRBWqB2Dp0G7YB03phxLQZupZTIZaeorjc=
github.com/oapi-codegen/oapi-codegen/v2 v2.5.1/go.mod h1:ro0npU1BWkcGpCgGD9QwPp44l5OIZ94tB3eabnT7DjQ=
github.com/oapi-codegen/runtime v1.1.2 h1:P2+CubHq8fO4Q6fV1tqDBZHCwpVpvPg7oKiYzQgXIyI=
github.com/oapi-codegen/runtime v1.1.2/go.mod h1:SK9X900oXmPWilYR5/WKPzt3Kqxn/uS/+lbpREv+eCg=
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0 h1:4i+F2cvwBFZeplxCssNdLy3MhNzUD87mI3HnayHZkAU=
github.com/oapi-codegen/oapi-codegen/v2 v2.6.0/go.mod h1:eWHeJSohQJIINJZzzQriVynfGsnlQVh0UkN2UYYcw4Q=
github.com/oapi-codegen/runtime v1.2.0 h1:RvKc1CVS1QeKSNzO97FBQbSMZyQ8s6rZd+LpmzwHMP4=
github.com/oapi-codegen/runtime v1.2.0/go.mod h1:Y7ZhmmlE8ikZOmuHRRndiIm7nf3xcVv+YMweKgG1DT0=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037 h1:G7ERwszslrBzRxj//JalHPu/3yz+De2J+4aLtSRlHiY=
github.com/oasdiff/yaml v0.0.0-20250309154309-f31be36b4037/go.mod h1:2bpvgLBZEtENV5scfDFEtB/5+1M4hkQhDQrccEJ/qGw=
github.com/oasdiff/yaml3 v0.0.0-20250309153720-d2182401db90 h1:bQx3WeLcUWy+RletIKwUIt4x3t8n2SxavmoclizMb8c=
Expand Down Expand Up @@ -173,8 +173,8 @@ github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
github.com/subosito/gotenv v1.6.0 h1:9NlTDc1FTs4qu0DDq7AEtTPNw6SVm7uBMsUCUjABIf8=
github.com/subosito/gotenv v1.6.0/go.mod h1:Dk4QP5c2W3ibzajGcXpNraDfq2IrhjMIvMSWPKKo0FU=
github.com/ugorji/go/codec v1.2.11 h1:BMaWp1Bb6fHwEtbplGBGJ498wD+LKlNSl25MjdZY4dU=
github.com/ugorji/go/codec v1.2.11/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65EE=
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/vmware-labs/yaml-jsonpath v0.3.2 h1:/5QKeCBGdsInyDCyVNLbXyilb61MXGi9NP674f9Hobk=
github.com/vmware-labs/yaml-jsonpath v0.3.2/go.mod h1:U6whw1z03QyqgWdgXxvVnQ90zN1BWz5V+51Ewf8k+rQ=
github.com/woodsbury/decimal128 v1.3.0 h1:8pffMNWIlC0O5vbyHWFZAt5yWvWcrHA+3ovIIjVWss0=
Expand Down
72 changes: 71 additions & 1 deletion internal/handlers/components/models.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading