-
Notifications
You must be signed in to change notification settings - Fork 150
74 lines (61 loc) · 2.46 KB
/
go-tests.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
name: go-tests
on: [push]
env:
TEST_RESULTS: /tmp/test-results
jobs:
go-tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ 1.15.3, 1.19 ]
steps:
- name: Setup go
uses: actions/setup-go@cdcb36043654635271a94b9a6d1392de5bb323a7 # v5.0.1
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
- name: Create test directory
run: |
mkdir -p ${{ env.TEST_RESULTS }}
- name: Download go modules
run: go mod download
- name: Cache / restore go modules
uses: actions/cache@0c45773b623bea8c8e75f6c82b208c3cf94ea4f9 # v4.0.2
with:
path: |
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
# Check go fmt output because it does not report non-zero when there are fmt changes
- name: Run gofmt
run: |
go fmt ./...
files=$(go fmt ./...)
if [ -n "$files" ]; then
echo "The following file(s) do not conform to go fmt:"
echo "$files"
exit 1
fi
# Install gotestsum with go get for 1.15.3; otherwise default to go install
- name: Install gotestsum
run: |
GTS="gotest.tools/[email protected]"
# We use the same error message prefix in either failure case, so just define it once here.
ERROR="Failed to install $GTS"
# First try to 'go install', if that fails try 'go get'...
go install "$GTS" || go get "$GTS" || { echo "$ERROR: both 'go install' and 'go get' failed"; exit 1; }
# Check that the gotestsum command was actually installed in the path...
command -v gotestsum > /dev/null 2>&1 || { echo "$ERROR: gotestsum command not installed"; exit 1; }
echo "OK: Command 'gotestsum' installed ($GTS)"
- name: Run go tests
run: |
PACKAGE_NAMES=$(go list ./...)
gotestsum --format=short-verbose --junitfile $TEST_RESULTS/gotestsum-report.xml -- $PACKAGE_NAMES
# Save coverage report parts
- name: Upload and save artifacts
uses: actions/upload-artifact@65462800fd760344b1a7b4382951275a0abb4808 # v4.3.3
with:
name: Test Results
path: ${{ env.TEST_RESULTS }}