-
Notifications
You must be signed in to change notification settings - Fork 4
102 lines (98 loc) · 3.66 KB
/
test.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
name: Test & Build
on:
pull_request:
push:
branches:
- main
- release/**
env:
# Even though we can test against multiple versions, this one is considered a target version.
TARGET_GOLANG_VERSION: "1.19"
jobs:
tests:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
go: ["1.20"]
name: Go Tests
steps:
- uses: actions/checkout@v3
- name: Setup go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Setup Golang caches
uses: actions/cache@v3
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-golang-${{ matrix.go }}-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-golang-${{ matrix.go }}-
- name: Create coverage report and run tests
run: |
set -euo pipefail
GODEBUG=netdns=cgo go test -p 1 -json ./ -mod=readonly -timeout 8m -race -coverprofile=coverage.txt -covermode=atomic 2>&1 | tee test_results.json
- name: Sanitize test results
# We're utilizing `tee` above which can capture non-json stdout output so we need to remove non-json lines before additional parsing and submitting it to the external github action.
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
run: cat test_results.json | jq -c -R 'fromjson? | select(type == "object")' > tmp.json && mv tmp.json test_results.json
- name: Output test failures
# Makes it easier to find failed tests so no need to scroll through the whole log.
if: ${{ failure() && env.TARGET_GOLANG_VERSION == matrix.go }}
run: |
jq --argjson fail_tests "$(jq -c -r 'select(.Action == "fail") | select(.Test) | .Test' test_results.json | jq -R -s -c -r 'split("\n") | map(select(length>0))')" 'select(.Test as $t | ($fail_tests | arrays)[] | select($t == .)) | select(.Output) | .Output' test_results.json | jq -r | sed ':a;N;$!ba;s/\n\n/\n/g' > test_failures.json
cat test_failures.json
exit 1
- name: Upload test results
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: actions/upload-artifact@v3
with:
name: test-results
path: |
test_*.json
- name: Annotate tests on GitHub
# Only annotate if the test failed on target version to avoid duplicated annotations on GitHub.
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: guyarb/[email protected]
with:
test-results: test_results.json
- name: Upload coverage to Codecov
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: codecov/codecov-action@v3
with:
files: ./coverage.txt
- name: golangci-lint
if: ${{ always() && env.TARGET_GOLANG_VERSION == matrix.go }}
uses: golangci/golangci-lint-action@v3
with:
version: latest
args: --timeout=10m
skip-cache: true
only-new-issues: true
build:
runs-on: ubuntu-latest
needs: tests
strategy:
fail-fast: false
matrix:
goarch: ["arm64", "amd64"]
go: ["1.20"]
timeout-minutes: 5
name: Build for ${{ matrix.goarch }}
steps:
- uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- uses: actions/checkout@v3
- uses: technote-space/get-diff-action@v4
with:
PATTERNS: |
**/**.go
go.mod
go.sum
- name: Go build
run: GOOS=linux GOARCH=${{ matrix.goarch }} go build
if: env.GIT_DIFF