-
Notifications
You must be signed in to change notification settings - Fork 51
151 lines (131 loc) · 4.38 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
147
148
149
150
151
name: go-test
on:
push:
branches:
- main
pull_request:
branches:
- main
env:
TEST_RESULTS_PATH: /tmp/test-results
permissions:
contents: read
jobs:
linux-tests:
runs-on: ubuntu-latest
strategy:
matrix:
go-version:
- '1.20'
- '1.21.x'
permissions:
id-token: write
contents: read
steps:
- name: Setup go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Check that go.mod does not contain a replace
run: |
if grep -Eq "^\s*replace" <go.mod; then
echo "go.mod contains a replace but should not." >&2
false
fi
- name: Create test directory
run: |
mkdir -p ${{ env.TEST_RESULTS_PATH }}/packer-plugin-sdk
- name: Run gofmt
run: |
make fmt-check
- name: Run Go Generate Check
run: |
make generate-check
- name: Install gotestsum
run: go install gotest.tools/[email protected]
# Required for passing tests as we need to have a replace in the go.mod
# otherwise we'll get compile-time errors when running them
- name: Fix gocty
run: |
make install-gen-deps
packer-sdc fix .
go mod tidy
- name: Run Go tests
run: |
PACKAGE_NAMES="$(go list ./...)"
echo "Running $(echo "$PACKAGE_NAMES" | wc -w) packages"
echo "$PACKAGE_NAMES"
echo "$PACKAGE_NAMES" | xargs -I {} gotestsum --format=short-verbose --junitfile "$TEST_RESULTS_PATH"/packer-plugin-sdk/gotestsum-report.xml -- -count 1 -p 2 {};
windows-tests:
runs-on: windows-latest
strategy:
matrix:
go-version:
- '1.20'
- '1.21.x'
permissions:
id-token: write
contents: read
steps:
- name: Run git config #Windows-only
run: git config --global core.autocrlf false
- name: Setup Go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Install gotestsum
shell: bash
run: go install gotest.tools/[email protected]
# Required for passing tests as we need to have a replace in the go.mod
# otherwise we'll get compile-time errors when running them
- name: Fix gocty
run: |
make install-gen-deps
packer-sdc fix .
go mod tidy
- name: Run Go tests
shell: bash
run: |
PACKAGE_NAMES="$(go list ./...)"
echo "Running $(echo "$PACKAGE_NAMES" | wc -w) packages"
echo "$PACKAGE_NAMES"
echo "$PACKAGE_NAMES" | xargs -I {} gotestsum --format=short-verbose --junitfile "$TEST_RESULTS_PATH"/packer-plugin-sdk/gotestsum-report.xml -- -count 1 -p 2 {};
darwin-tests:
runs-on: macos-latest
strategy:
matrix:
go-version:
- '1.20'
- '1.21.x'
permissions:
id-token: write
contents: read
steps:
- name: Setup go
uses: actions/setup-go@0c52d547c9bc32b1aa3301fd7a9cb496313a4491 # v5.0.0
with:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
- name: Create test directory
run: |
mkdir -p ${{ env.TEST_RESULTS_PATH }}/packer-plugin-sdk
- name: Install gotestsum
run: go install gotest.tools/[email protected]
# Required for passing tests as we need to have a replace in the go.mod
# otherwise we'll get compile-time errors when running them
- name: Fix gocty
run: |
make install-gen-deps
packer-sdc fix .
go mod tidy
- name: Run Go tests
run: |
PACKAGE_NAMES="$(go list ./...)"
echo "Running $(echo "$PACKAGE_NAMES" | wc -w) packages"
echo "$PACKAGE_NAMES"
echo "$PACKAGE_NAMES" | xargs -I {} gotestsum --format=short-verbose --junitfile "$TEST_RESULTS_PATH"/packer-plugin-sdk/gotestsum-report.xml -- -count 1 -p 2 {};