Skip to content

ci: pin GitHub Actions to commit SHAs (#211) #996

ci: pin GitHub Actions to commit SHAs (#211)

ci: pin GitHub Actions to commit SHAs (#211) #996

Workflow file for this run

name: Unit tests
on:
workflow_call:
pull_request:
push:
branches:
- "main"
paths:
- "**.go"
- "go.mod"
- "go.sum"
- ".github/workflows/*.yaml"
- "example/**"
jobs:
test-go:
name: Run unit tests
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Checkout
uses: actions/checkout@34e114876b0b11c390a56381ad16ebd13914f8d5 # v4
- uses: actions/setup-go@40f1582b2485089dde7abd97c1529aa768e1baff # v5
with:
go-version-file: ./go.mod
- name: Install dependencies
run: |
rm cmd/hasura-ndc-go/go.mod
rm cmd/hasura-ndc-go/go.sum
go get golang.org/x/tools@latest
go get golang.org/x/mod@latest
go mod tidy
go mod download
- name: Run Go unit tests for the SDK
run: |
rm -rf ./coverage
mkdir -p ./coverage/sdk
mkdir -p ./coverage/codegen
cp go.work.testing go.work
go test -v -coverpkg=./... -race -timeout 3m -cover ./... -args -test.gocoverdir=$PWD/coverage/sdk ./...
go test -v -race -coverpkg=./... -cover ./example/codegen/... -args -test.gocoverdir=$PWD/coverage/codegen ./example/codegen/...
go tool covdata textfmt -i=./coverage/sdk,./coverage/codegen -o ./coverage/profile.tmp
cat ./coverage/profile.tmp | grep -v "main.go" > ./coverage/profile
- name: Run Go unit tests for the generation example
run: |
make build-codegen
pushd example/codegen
../../_output/hasura-ndc-go update
go test -v -race -timeout 3m ./...
popd
- name: Run ndc-test
run: |
./example/codegen/test.sh
- name: Go coverage format
if: ${{ github.event_name == 'pull_request' }}
run: |
go get github.com/boumenot/gocover-cobertura
go install github.com/boumenot/gocover-cobertura
gocover-cobertura < ./coverage/profile > coverage.xml
- name: Code Coverage Summary Report
uses: irongut/CodeCoverageSummary@51cc3a756ddcd398d447c044c02cb6aa83fdae95 # v1.3.0
if: ${{ github.event_name == 'pull_request' }}
with:
filename: coverage.xml
badge: true
fail_below_min: true
format: markdown
hide_branch_rate: false
hide_complexity: true
indicators: true
output: both
thresholds: "40 70"
- name: Add Coverage PR Comment
uses: marocchino/sticky-pull-request-comment@773744901bac0e8cbb5a0dc842800d45e9b2b405 # v2
if: ${{ github.event_name == 'pull_request' }}
with:
path: code-coverage-results.md
- name: Dump docker logs on failure
if: failure()
uses: jwalton/gh-docker-logs@eb53a99ccbbb34d4243439c2c3dac3ed78a926ed # v2