-
Notifications
You must be signed in to change notification settings - Fork 2
129 lines (118 loc) · 3.73 KB
/
go-test.yml
File metadata and controls
129 lines (118 loc) · 3.73 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
name: go-test
permissions:
pull-requests: read
contents: read
on:
workflow_call:
inputs:
extra-flags:
description: extra flags to add to go test
type: string
required: false
defaults:
run:
shell: bash
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
-
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: stable
check-latest: true
cache: true
-
name: golangci-lint
uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 # v9.2.0
with:
version: latest
only-new-issues: true
skip-cache: true
test:
name: Unit tests
runs-on: ${{ matrix.os }}
needs: [lint]
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go: ['oldstable', 'stable' ]
steps:
-
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
-
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
with:
go-version: '${{ matrix.go }}'
check-latest: true
cache: true
-
name: Install gotestsum
uses: go-openapi/gh-actions/install/gotestsum@23cdaeff454807ac293a6e98cff552a2ea49be63 # v1.4.7
-
name: Ensure TMP is created on windows runners
# On windows, some tests require testing.TempDir to reside on the same drive as the code.
# TMP is used by os.TempDir() to determine the location of temporary files.
if: ${{ runner.os == 'Windows' }}
shell: bash
run: |
TMP="${{ github.workspace }}\..\tmp"
mkdir -p ${TMP}
echo "TMP=${TMP}" >> "${GITHUB_ENV}"
-
name: Run unit tests
env:
EXTRA_FLAGS: ${{ inputs.extra-flags }}
run: >
gotestsum
--jsonfile 'unit.report.${{ matrix.os }}-${{ matrix.go }}.json'
--
-race
-p 2
-count 1
-timeout=20m
-coverprofile='unit.coverage.${{ matrix.os }}-${{ matrix.go }}.out'
-covermode=atomic
-coverpkg="$(go list)"/... ${EXTRA_FLAGS}
./...
-
name: Upload coverage artifacts
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
# *.coverage.* pattern is automatically detected by codecov
path: '**/*.coverage.*.out'
name: 'unit.coverage.${{ matrix.os }}-${{ matrix.go }}'
retention-days: 1
-
name: Upload test report artifacts
# upload report even if test fail. BTW, this is when they are valuable.
if: ${{ !cancelled() }}
uses: actions/upload-artifact@bbbca2ddaa5d8feaa63e36b76fdaad77386f024f # v7.0.0
with:
path: '**/unit.report.*.json'
name: 'unit.report.${{ matrix.os }}-${{ matrix.go }}'
retention-days: 1
fuzz-test:
uses: ./.github/workflows/fuzz-test.yml
test-complete:
# description: |
# Be explicit about all tests being passed. This allows for setting up only a few status checks on PRs.
name: tests completed
needs: [test,fuzz-test]
runs-on: ubuntu-latest
steps:
-
name: Tests completed
run: |
echo "::notice title=Success::All tests passed"
collect-coverage:
needs: [test-complete]
if: ${{ !cancelled() && needs.test-complete.result == 'success' }}
uses: ./.github/workflows/collect-coverage.yml
collect-reports:
needs: [test]
if: ${{ !cancelled() }}
uses: ./.github/workflows/collect-reports.yml