forked from ipdxco/unified-github-workflows
-
Notifications
You must be signed in to change notification settings - Fork 0
146 lines (144 loc) · 5.77 KB
/
go-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
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
name: Go Test
on:
workflow_call:
inputs:
go-versions:
required: false
type: string
default: '["this", "next"]'
go-cache:
required: false
type: boolean
default: false
secrets:
CODECOV_TOKEN:
required: false
defaults:
run:
shell: bash
jobs:
unit:
strategy:
fail-fast: false
matrix:
os: [ "ubuntu", "windows", "macos" ]
go: ${{ fromJSON(inputs.go-versions) }}
env:
GOTESTFLAGS: -cover -coverprofile=module-coverage.txt -coverpkg=./...
GO386FLAGS: ''
GORACEFLAGS: ''
runs-on: ${{ fromJSON(vars[format('UCI_GO_TEST_RUNNER_{0}', matrix.os)] || format('"{0}-latest"', matrix.os)) }}
name: ${{ matrix.os }} (go ${{ matrix.go }})
steps:
- name: Use msys2 on windows
if: matrix.os == 'windows'
# The executable for msys2 is also called bash.cmd
# https://github.com/actions/virtual-environments/blob/main/images/win/Windows2019-Readme.md#shells
# If we prepend its location to the PATH
# subsequent 'shell: bash' steps will use msys2 instead of gitbash
run: echo "C:/msys64/usr/bin" >> $GITHUB_PATH
- name: Check out the repository
uses: actions/checkout@v4
with:
submodules: recursive
- name: Check out the latest stable version of Go
uses: actions/setup-go@v5
with:
go-version: stable
cache: false
- name: Read the Unified GitHub Workflows configuration
id: config
uses: ipdxco/unified-github-workflows/.github/actions/read-config@main
- name: Read the go.mod file
id: go-mod
uses: ipdxco/unified-github-workflows/.github/actions/read-go-mod@main
- name: Determine the Go version to use based on the go.mod file
id: go
env:
MATRIX_GO: ${{ matrix.go }}
GO_MOD_VERSION: ${{ fromJSON(steps.go-mod.outputs.json).Go }}
run: |
if [[ "$MATRIX_GO" == "this" ]]; then
MAJOR=$(echo "$GO_MOD_VERSION" | cut -d. -f1)
MINOR=$(echo "$GO_MOD_VERSION" | cut -d. -f2)
PATCH=$(echo "$GO_MOD_VERSION" | cut -d. -f3)
if [[ -z "$PATCH" ]]; then
echo "version=$MAJOR.$MINOR.x" >> $GITHUB_OUTPUT
else
echo "version=$MAJOR.$MINOR.$PATCH" >> $GITHUB_OUTPUT
fi
elif [[ "$MATRIX_GO" == "next" ]]; then
MAJOR=$(echo "$GO_MOD_VERSION" | cut -d. -f1)
MINOR=$(echo "$GO_MOD_VERSION" | cut -d. -f2)
echo "version=$MAJOR.$(($MINOR+1)).x" >> $GITHUB_OUTPUT
elif [[ "$MATRIX_GO" == "prev" ]]; then
MAJOR=$(echo "$GO_MOD_VERSION" | cut -d. -f1)
MINOR=$(echo "$GO_MOD_VERSION" | cut -d. -f2)
echo "version=$MAJOR.$(($MINOR-1)).x" >> $GITHUB_OUTPUT
else
echo "version=$MATRIX_GO" >> $GITHUB_OUTPUT
fi
- name: Enable shuffle flag for go test command
if: toJSON(fromJSON(steps.config.outputs.json).shuffle) != 'false'
run: |
echo "GOTESTFLAGS=-shuffle=on $GOTESTFLAGS" >> $GITHUB_ENV
echo "GO386FLAGS=-shuffle=on $GO386FLAGS" >> $GITHUB_ENV
echo "GORACEFLAGS=-shuffle=on $GORACEFLAGS" >> $GITHUB_ENV
- name: Enable verbose flag for go test command
if: toJSON(fromJSON(steps.config.outputs.json).verbose) != 'false'
run: |
echo "GOTESTFLAGS=-v $GOTESTFLAGS" >> $GITHUB_ENV
echo "GO386FLAGS=-v $GO386FLAGS" >> $GITHUB_ENV
echo "GORACEFLAGS=-v $GORACEFLAGS" >> $GITHUB_ENV
- name: Set up the Go version read from the go.mod file
uses: actions/setup-go@v5
with:
go-version: ${{ steps.go.outputs.version }}
cache: ${{ inputs.go-cache }}
- name: Display the Go version and environment
run: |
go version
go env
- name: Run repo-specific setup
uses: ./.github/actions/go-test-setup
if: hashFiles('./.github/actions/go-test-setup') != ''
- name: Run tests
if: contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
env:
GOFLAGS: ${{ format('{0} {1}', env.GOTESTFLAGS, env.GOFLAGS) }}
with:
run: go test ./...
- name: Run tests (32 bit)
# can't run 32 bit tests on OSX.
if: matrix.os != 'macos' &&
fromJSON(steps.config.outputs.json).skip32bit != true &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
env:
GOARCH: 386
GOFLAGS: ${{ format('{0} {1}', env.GO386FLAGS, env.GOFLAGS) }}
with:
run: |
export "PATH=$PATH_386:$PATH"
go test ./...
- name: Run tests with race detector
# speed things up. Windows and OSX VMs are slow
if: matrix.os == 'ubuntu' &&
fromJSON(steps.config.outputs.json).skipRace != true &&
contains(fromJSON(steps.config.outputs.json).skipOSes, matrix.os) == false
uses: protocol/[email protected]
env:
GOFLAGS: ${{ format('{0} {1}', env.GORACEFLAGS, env.GOFLAGS) }}
with:
run: go test -race ./...
- name: Collect coverage files
id: coverages
run: echo "files=$(find . -type f -name 'module-coverage.txt' | tr -s '\n' ',' | sed 's/,$//')" >> $GITHUB_OUTPUT
- name: Upload coverage to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
with:
files: ${{ steps.coverages.outputs.files }}
env_vars: OS=${{ matrix.os }}, GO=${{ steps.go.outputs.version }}
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: false