master
yml 191 lines 6.36 KB
Raw
1 ---
2 # Ci code for building release artifacts.
3 name: Go Tests
4 on:
5 push: # Master branch checks only validate the build and generate artifacts for testing.
6 branches:
7 - master
8 pull_request: null # PR checks only validate the build and generate artifacts for testing.
9 concurrency: # This keeps multiple instances of the job from running concurrently for the same ref and event type.
10 group: go-test-${{ github.ref }}-${{ github.event_name }}
11 cancel-in-progress: true
12 jobs:
13 file-check: # Check what files changed if we’re being run in a PR or on a push.
14 name: Check Modified Files
15 runs-on: ubuntu-latest
16 outputs:
17 run: ${{ steps.check-run.outputs.run }}
18 steps:
19 - name: Checkout
20 id: checkout
21 uses: actions/checkout@v6
22 with:
23 fetch-depth: 0
24 submodules: recursive
25 - name: Check files
26 id: check-files
27 uses: step-security/changed-files@v45
28 with:
29 since_last_remote_commit: ${{ github.event_name != 'pull_request' }}
30 files: |
31 **/*.cmake
32 CMakeLists.txt
33 .github/workflows/go-tests.yml
34 packaging/cmake/
35 src/go/**
36 files_ignore: |
37 **/*.md
38 src/go/**/metadata.yaml
39 packaging/repoconfig/
40 - name: List all changed files in pattern
41 continue-on-error: true
42 env:
43 ALL_CHANGED_FILES: ${{ steps.check-files.outputs.all_changed_files }}
44 run: |
45 for file in ${ALL_CHANGED_FILES}; do
46 echo "$file was changed"
47 done
48 - name: Check Run
49 id: check-run
50 run: |
51 if [ "${{ steps.check-files.outputs.any_modified }}" == "true" ] || [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
52 echo 'run=true' >> "${GITHUB_OUTPUT}"
53 else
54 echo 'run=false' >> "${GITHUB_OUTPUT}"
55 fi
56
57 matrix:
58 name: Generate Build Matrix
59 runs-on: ubuntu-latest
60 outputs:
61 matrix: ${{ steps.get-version.outputs.matrix }}
62 steps:
63 - name: Checkout
64 uses: actions/checkout@v6
65 - name: Install dependencies
66 run: |
67 sudo apt-get update || true
68 sudo apt-get install -y python3-packaging
69 - name: Get Go version and modules
70 id: get-version
71 run: .github/scripts/get-go-version.py
72
73 tests:
74 name: Go toolchain tests
75 runs-on: ubuntu-latest
76 needs:
77 - file-check
78 - matrix
79 strategy:
80 fail-fast: false
81 matrix:
82 include: ${{ fromJson(needs.matrix.outputs.matrix) }}
83 steps:
84 - name: Skip Check
85 id: skip
86 if: needs.file-check.outputs.run != 'true'
87 run: echo "SKIPPED"
88 - name: Install Go
89 uses: actions/setup-go@v6
90 with:
91 go-version: ${{ matrix.version }}
92 - name: Checkout
93 if: needs.file-check.outputs.run == 'true'
94 uses: actions/checkout@v6
95 with:
96 submodules: recursive
97 - name: Go mod download
98 if: needs.file-check.outputs.run == 'true'
99 run: go mod download
100 working-directory: ${{ matrix.module }}
101 - name: Install CGO system dependencies
102 if: needs.file-check.outputs.run == 'true'
103 run: |
104 sudo apt-get update
105 sudo apt-get install -y unixodbc-dev
106 - name: Compile
107 if: needs.file-check.outputs.run == 'true'
108 run: |
109 CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
110 /tmp/go-test-build --help || true
111 working-directory: ${{ matrix.module }}
112 - name: Go fmt
113 if: needs.file-check.outputs.run == 'true'
114 run: |
115 go fmt ./... | tee modified-files
116 [ "$(wc -l modified-files | cut -f 1 -d ' ')" -eq 0 ] || exit 1
117 working-directory: ${{ matrix.module }}
118 - name: Go fix
119 if: needs.file-check.outputs.run == 'true'
120 run: |
121 go fix ./...
122 git diff --exit-code
123 working-directory: ${{ matrix.module }}
124 - name: Go vet
125 if: needs.file-check.outputs.run == 'true'
126 run: |
127 CGO_ENABLED=0 go vet -tests=false ./...
128 working-directory: ${{ matrix.module }}
129 - name: Set up gotestfmt
130 if: needs.file-check.outputs.run == 'true'
131 uses: GoTestTools/gotestfmt-action@v2
132 with:
133 token: ${{ secrets.GITHUB_TOKEN }}
134 version: v2.2.0
135 - name: Go test
136 if: needs.file-check.outputs.run == 'true'
137 run: |
138 set -euo pipefail
139 # The race detector requires CGO; explicitly enable it to avoid go emitting
140 # non-JSON diagnostics that crash gotestfmt when CGO is disabled upstream.
141 # Some toolchain output still lacks package metadata, so normalize the stream
142 # before passing it to gotestfmt.
143 CGO_ENABLED=1 go test -json ./... -race -count=1 2>&1 \
144 | "$GITHUB_WORKSPACE/.github/scripts/normalize-go-test-json.py" \
145 | gotestfmt -hide all
146 working-directory: ${{ matrix.module }}
147
148 build-tests:
149 name: Go build tests
150 runs-on: ubuntu-latest
151 needs:
152 - file-check
153 - matrix
154 strategy:
155 fail-fast: false
156 matrix:
157 platforms:
158 - linux/386
159 - linux/amd64
160 - linux/arm
161 - linux/arm64
162 - linux/ppc64le
163 - windows/amd64
164 include: ${{ fromJson(needs.matrix.outputs.matrix) }}
165 steps:
166 - name: Skip Check
167 id: skip
168 if: needs.file-check.outputs.run != 'true'
169 run: echo "SKIPPED"
170 - name: Install Go
171 uses: actions/setup-go@v6
172 with:
173 go-version: ${{ matrix.version }}
174 - name: Checkout
175 if: needs.file-check.outputs.run == 'true'
176 uses: actions/checkout@v6
177 with:
178 submodules: recursive
179 - name: Set GOOS and GOARCH
180 run: |
181 echo "GOOS=$(echo "${{ matrix.platform }}" | cut -f 1 -d '/')" >> "${GITHUB_ENV}"
182 echo "GOARCH=$(echo "${{ matrix.platform }}" | cut -f 2 -d '/')" >> "${GITHUB_ENV}"
183 - name: Go mod download
184 if: needs.file-check.outputs.run == 'true'
185 run: go mod download
186 working-directory: ${{ matrix.module }}
187 - name: Compile
188 if: needs.file-check.outputs.run == 'true'
189 run: |
190 CGO_ENABLED=0 go build -o /tmp/go-test-build ${{ matrix.build_target }}
191 working-directory: ${{ matrix.module }}