-
Notifications
You must be signed in to change notification settings - Fork 150
85 lines (76 loc) · 2.38 KB
/
go-test.yml
File metadata and controls
85 lines (76 loc) · 2.38 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
name: go test
on:
push:
tags:
- v*
branches:
- master
pull_request:
jobs:
lint:
name: Lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: stable
check-latest: true
cache: true
cache-dependency-path: '**/go.sum'
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: latest
only-new-issues: true
skip-cache: true
module-test:
name: Run unit tests on all modules in this repo
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ ubuntu-latest, macos-latest, windows-latest ]
go_version: ['oldstable', 'stable']
steps:
- uses: actions/checkout@v6
- uses: actions/setup-go@v6
with:
go-version: '${{ matrix.go_version }}'
check-latest: true
cache: true
cache-dependency-path: '**/go.sum'
- name: Run unit tests
shell: bash
env:
# *.coverage.* pattern is automatically detected by codecov
COVER_PROFILE: 'all_modules.coverage.${{ matrix.os }}.${{ matrix.go_version }}.out'
run: |
# when go1.25 becomes the oldstable, we may replace this bash with "go work test"
declare -a ALL_MODULES
BASH_MAJOR=$(echo $BASH_VERSION|cut -d'.' -f1)
if [[ "${BASH_MAJOR}" -ge 4 ]] ; then
mapfile ALL_MODULES < <(go list -f '{{.Dir}}/...' -m)
else
# for older bash versions, e.g. on macOS runner. This fallback will eventually disappear.
while read line ; do
ALL_MODULES+=("${line}")
done < <(go list -f '{{.Dir}}/...' -m)
fi
echo "::notice title=Modules found::${ALL_MODULES[@]}"
# with go.work file enabled, go test recognizes sub-modules and collects all packages to be covered
# without specifying -coverpkg.
go test -v -race -coverprofile="${COVER_PROFILE}" -covermode=atomic ${ALL_MODULES[@]}
- name: Upload coverage to codecov
uses: codecov/codecov-action@v5
with:
flags: '${{ matrix.go_version }}-${{ matrix.os }}'
fail_ci_if_error: false
verbose: true
test:
needs: [ module-test ]
name: Test
runs-on: ubuntu-latest
steps:
- name: Tests complete
run: |
echo "All tests completed"