Add cross-architecture build tests for Go code. (#19195)
Austin S. Hemmelgarn committed
Dec 12, 2024 at 09:57 UTC
50429e8bb5b5e8851e46be9fed5d1798d42f1552
2 files changed
+49
-3
.github/scripts/get-go-version.py
+2
-2
@@ -32,8 +32,8 @@ for modfile in GO_SRC.glob('**/go.mod'):
32
modules.append({
33
'module': str(modfile.parent),
34
'version': str(version),
35
- 'build_target': f'github.com/netdata/netdata/go/plugins/{ str(mainpath) }/',
35
+ 'build_target': f'github.com/netdata/netdata/go/plugins/{str(mainpath)}/',
36
})
37
38
with GITHUB_OUTPUT.open('a') as f:
39
- f.write(f'matrix={ json.dumps({"include": modules}) }\n')
39
+ f.write(f'matrix={json.dumps(modules)}\n')
.github/workflows/go-tests.yml
+47
-1
@@ -78,7 +78,8 @@ jobs:
78
- matrix
79
strategy:
80
fail-fast: false
81
- matrix: ${{ fromJson(needs.matrix.outputs.matrix) }}
81
+ matrix:
82
+ include: ${{ fromJson(needs.matrix.outputs.matrix) }}
83
steps:
84
- name: Skip Check
85
id: skip
@@ -125,3 +126,48 @@ jobs:
126
set -euo pipefail
127
go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
128
working-directory: ${{ matrix.module }}
129
+
130
+ build-tests:
131
+ name: Go build tests
132
+ runs-on: ubuntu-latest
133
+ needs:
134
+ - file-check
135
+ - matrix
136
+ strategy:
137
+ fail-fast: false
138
+ matrix:
139
+ platforms:
140
+ - linux/386
141
+ - linux/amd64
142
+ - linux/arm
143
+ - linux/arm64
144
+ - linux/ppc64le
145
+ - windows/amd64
146
+ include: ${{ fromJson(needs.matrix.outputs.matrix) }}
147
+ steps:
148
+ - name: Skip Check
149
+ id: skip
150
+ if: needs.file-check.outputs.run != 'true'
151
+ run: echo "SKIPPED"
152
+ - name: Install Go
153
+ uses: actions/setup-go@v5
154
+ with:
155
+ go-version: ${{ matrix.version }}
156
+ - name: Checkout
157
+ if: needs.file-check.outputs.run == 'true'
158
+ uses: actions/checkout@v4
159
+ with:
160
+ submodules: recursive
161
+ - name: Set GOOS and GOARCH
162
+ run: |
163
+ echo "GOOS=$(echo "${{ matrix.platform }}" | cut -f 1 -d '/')" >> "${GITHUB_ENV}"
164
+ echo "GOARCH=$(echo "${{ matrix.platform }}" | cut -f 2 -d '/')" >> "${GITHUB_ENV}"
165
+ - name: Go mod download
166
+ if: needs.file-check.outputs.run == 'true'
167
+ run: go mod download
168
+ working-directory: ${{ matrix.module }}
169
+ - name: Compile
170
+ if: needs.file-check.outputs.run == 'true'
171
+ run: |
172
+ CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
173
+ working-directory: ${{ matrix.module }}