forked from netdata/netdata
-
Notifications
You must be signed in to change notification settings - Fork 0
173 lines (170 loc) · 5.55 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
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
---
# Ci code for building release artifacts.
name: Go Tests
on:
push: # Master branch checks only validate the build and generate artifacts for testing.
branches:
- master
pull_request: null # PR checks only validate the build and generate artifacts for testing.
concurrency: # This keeps multiple instances of the job from running concurrently for the same ref and event type.
group: go-test-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true
jobs:
file-check: # Check what files changed if we’re being run in a PR or on a push.
name: Check Modified Files
runs-on: ubuntu-latest
outputs:
run: ${{ steps.check-run.outputs.run }}
steps:
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
submodules: recursive
- name: Check files
id: check-files
uses: tj-actions/changed-files@v45
with:
since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
files: |
**/*.cmake
CMakeLists.txt
.github/workflows/go-tests.yml
packaging/cmake/
src/go/**
files_ignore: |
**/*.md
src/go/**/metadata.yaml
packaging/repoconfig/
- name: List all changed files in pattern
continue-on-error: true
env:
ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
run: |
for file in ${ALL_CHANGED_FILES}; do
echo "$file was changed"
done
- name: Check Run
id: check-run
run: |
if [ "${{ steps.check-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo 'run=true' >> "${GITHUB_OUTPUT}"
else
echo 'run=false' >> "${GITHUB_OUTPUT}"
fi
matrix:
name: Generate Build Matrix
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.get-version.outputs.matrix }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Install dependencies
run: |
sudo apt-get update || true
sudo apt-get install -y python3-packaging
- name: Get Go version and modules
id: get-version
run: .github/scripts/get-go-version.py
tests:
name: Go toolchain tests
runs-on: ubuntu-latest
needs:
- file-check
- matrix
strategy:
fail-fast: false
matrix:
include: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- name: Skip Check
id: skip
if: needs.file-check.outputs.run != 'true'
run: echo "SKIPPED"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.version }}
- name: Checkout
if: needs.file-check.outputs.run == 'true'
uses: actions/checkout@v4
with:
submodules: recursive
- name: Go mod download
if: needs.file-check.outputs.run == 'true'
run: go mod download
working-directory: ${{ matrix.module }}
- name: Compile
if: needs.file-check.outputs.run == 'true'
run: |
CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
/tmp/go-test-build --help || true
working-directory: ${{ matrix.module }}
- name: Go fmt
if: needs.file-check.outputs.run == 'true'
run: |
go fmt ./... | tee modified-files
[ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
working-directory: ${{ matrix.module }}
- name: Go vet
if: needs.file-check.outputs.run == 'true'
run: go vet ./...
working-directory: ${{ matrix.module }}
- name: Set up gotestfmt
if: needs.file-check.outputs.run == 'true'
uses: GoTestTools/gotestfmt-action@v2
with:
token: ${{ secrets.GITHUB_TOKEN }}
version: v2.0.0
- name: Go test
if: needs.file-check.outputs.run == 'true'
run: |
set -euo pipefail
go test -json ./... -race -count=1 2>&1 | gotestfmt -hide all
working-directory: ${{ matrix.module }}
build-tests:
name: Go build tests
runs-on: ubuntu-latest
needs:
- file-check
- matrix
strategy:
fail-fast: false
matrix:
platforms:
- linux/386
- linux/amd64
- linux/arm
- linux/arm64
- linux/ppc64le
- windows/amd64
include: ${{ fromJson(needs.matrix.outputs.matrix) }}
steps:
- name: Skip Check
id: skip
if: needs.file-check.outputs.run != 'true'
run: echo "SKIPPED"
- name: Install Go
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.version }}
- name: Checkout
if: needs.file-check.outputs.run == 'true'
uses: actions/checkout@v4
with:
submodules: recursive
- name: Set GOOS and GOARCH
run: |
echo "GOOS=$(echo "${{ matrix.platform }}" | cut -f 1 -d '/')" >> "${GITHUB_ENV}"
echo "GOARCH=$(echo "${{ matrix.platform }}" | cut -f 2 -d '/')" >> "${GITHUB_ENV}"
- name: Go mod download
if: needs.file-check.outputs.run == 'true'
run: go mod download
working-directory: ${{ matrix.module }}
- name: Compile
if: needs.file-check.outputs.run == 'true'
run: |
CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
working-directory: ${{ matrix.module }}