Debian Codegraph @

.github/workflows/ci.yml

raw
1 name: ci
2
3 concurrency:
4 group: ${{ github.workflow }}-${{ github.ref }}
5 cancel-in-progress: true
6
7 on:
8 push:
9 branches:
10 - 'main'
11 tags:
12 - 'v*'
13 pull_request:
14 workflow_dispatch:
15 inputs:
16 debug_enabled:
17 description: 'To run with tmate enter "debug_enabled"'
18 required: false
19 default: "false"
20
21 permissions:
22 contents: read # to fetch code (actions/checkout)
23
24 jobs:
25 prepare:
26 runs-on: ubuntu-latest
27 outputs:
28 matrix: ${{ steps.platforms.outputs.matrix }}
29 steps:
30 -
31 name: Checkout
32 uses: actions/checkout@v4
33 -
34 name: Create matrix
35 id: platforms
36 run: |
37 echo matrix=$(docker buildx bake binary-cross --print | jq -cr '.target."binary-cross".platforms') >> $GITHUB_OUTPUT
38 -
39 name: Show matrix
40 run: |
41 echo ${{ steps.platforms.outputs.matrix }}
42
43 validate:
44 runs-on: ubuntu-latest
45 strategy:
46 fail-fast: false
47 matrix:
48 target:
49 - lint
50 - validate-go-mod
51 - validate-headers
52 - validate-docs
53 steps:
54 -
55 name: Checkout
56 uses: actions/checkout@v4
57 -
58 name: Set up Docker Buildx
59 uses: docker/setup-buildx-action@v3
60 -
61 name: Run
62 run: |
63 make ${{ matrix.target }}
64
65 binary:
66 runs-on: ubuntu-latest
67 needs:
68 - prepare
69 strategy:
70 fail-fast: false
71 matrix:
72 platform: ${{ fromJson(needs.prepare.outputs.matrix) }}
73 steps:
74 -
75 name: Checkout
76 uses: actions/checkout@v4
77 -
78 name: Prepare
79 run: |
80 platform=${MATRIX_PLATFORM}
81 echo "PLATFORM_PAIR=${platform//\//-}" >> $GITHUB_ENV
82 env:
83 MATRIX_PLATFORM: ${{ matrix.platform }}
84 -
85 name: Set up QEMU
86 uses: docker/setup-qemu-action@v3
87 -
88 name: Set up Docker Buildx
89 uses: docker/setup-buildx-action@v3
90 -
91 name: Build
92 uses: docker/bake-action@v6
93 with:
94 source: .
95 targets: release
96 provenance: mode=max
97 sbom: true
98 set: |
99 *.platform=${{ matrix.platform }}
100 *.cache-from=type=gha,scope=binary-${{ env.PLATFORM_PAIR }}
101 *.cache-to=type=gha,scope=binary-${{ env.PLATFORM_PAIR }},mode=max
102 -
103 name: Rename provenance and sbom
104 working-directory: ./bin/release
105 run: |
106 binname=$(find . -name 'docker-compose-*')
107 filename=$(basename "$binname" | sed -E 's/\.exe$//')
108 mv "provenance.json" "${filename}.provenance.json"
109 mv "sbom-binary.spdx.json" "${filename}.sbom.json"
110 find . -name 'sbom*.json' -exec rm {} \;
111 -
112 name: List artifacts
113 run: |
114 tree -nh ./bin/release
115 -
116 name: Upload artifacts
117 uses: actions/upload-artifact@v4
118 with:
119 name: compose-${{ env.PLATFORM_PAIR }}
120 path: ./bin/release
121 if-no-files-found: error
122
123 test:
124 runs-on: ubuntu-latest
125 steps:
126 -
127 name: Set up Docker Buildx
128 uses: docker/setup-buildx-action@v3
129 -
130 name: Test
131 uses: docker/bake-action@v6
132 with:
133 targets: test
134 set: |
135 *.cache-from=type=gha,scope=test
136 *.cache-to=type=gha,scope=test
137 -
138 name: Gather coverage data
139 uses: actions/upload-artifact@v4
140 with:
141 name: coverage-data-unit
142 path: bin/coverage/unit/
143 if-no-files-found: error
144 -
145 name: Unit Test Summary
146 uses: test-summary/action@v2
147 with:
148 paths: bin/coverage/unit/report.xml
149 if: always()
150 e2e:
151 runs-on: ubuntu-latest
152 strategy:
153 fail-fast: false
154 matrix:
155 mode:
156 - plugin
157 - standalone
158 engine:
159 - 27 # old stable (latest major - 1)
160 - 28 # current stable
161 steps:
162 - name: Prepare
163 run: |
164 mode=${{ matrix.mode }}
165 engine=${{ matrix.engine }}
166 echo "MODE_ENGINE_PAIR=${mode}-${engine}" >> $GITHUB_ENV
167
168 - name: Checkout
169 uses: actions/checkout@v4
170
171 - name: Install Docker ${{ matrix.engine }}
172 run: |
173 sudo systemctl stop docker.service
174 sudo apt-get purge docker-ce docker-ce-cli containerd.io docker-compose-plugin docker-ce-rootless-extras docker-buildx-plugin
175 sudo apt-get install curl
176 curl -fsSL https://test.docker.com -o get-docker.sh
177 sudo sh ./get-docker.sh --version ${{ matrix.engine }}
178
179 - name: Check Docker Version
180 run: docker --version
181
182 - name: Set up Docker Buildx
183 uses: docker/setup-buildx-action@v3
184
185 - name: Set up Docker Model
186 run: |
187 sudo apt-get install docker-model-plugin
188 docker model version
189
190 - name: Set up Go
191 uses: actions/setup-go@v5
192 with:
193 go-version-file: 'go.mod'
194 check-latest: true
195 cache: true
196
197 - name: Build example provider
198 run: make example-provider
199
200 - name: Build
201 uses: docker/bake-action@v6
202 with:
203 source: .
204 targets: binary-with-coverage
205 set: |
206 *.cache-from=type=gha,scope=binary-linux-amd64
207 *.cache-from=type=gha,scope=binary-e2e-${{ matrix.mode }}
208 *.cache-to=type=gha,scope=binary-e2e-${{ matrix.mode }},mode=max
209 env:
210 BUILD_TAGS: e2e
211
212 - name: Setup tmate session
213 if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled }}
214 uses: mxschmitt/action-tmate@8b4e4ac71822ed7e0ad5fb3d1c33483e9e8fb270 # v3.11
215 with:
216 limit-access-to-actor: true
217 github-token: ${{ secrets.GITHUB_TOKEN }}
218
219 - name: Test plugin mode
220 if: ${{ matrix.mode == 'plugin' }}
221 run: |
222 rm -rf ./bin/coverage/e2e
223 mkdir -p ./bin/coverage/e2e
224 make e2e-compose GOCOVERDIR=bin/coverage/e2e TEST_FLAGS="-v"
225
226 - name: Gather coverage data
227 if: ${{ matrix.mode == 'plugin' }}
228 uses: actions/upload-artifact@v4
229 with:
230 name: coverage-data-e2e-${{ env.MODE_ENGINE_PAIR }}
231 path: bin/coverage/e2e/
232 if-no-files-found: error
233
234 - name: Test standalone mode
235 if: ${{ matrix.mode == 'standalone' }}
236 run: |
237 rm -f /usr/local/bin/docker-compose
238 cp bin/build/docker-compose /usr/local/bin
239 make e2e-compose-standalone
240
241 - name: e2e Test Summary
242 uses: test-summary/action@v2
243 with:
244 paths: /tmp/report/report.xml
245 if: always()
246 coverage:
247 runs-on: ubuntu-latest
248 needs:
249 - test
250 - e2e
251 steps:
252 # codecov won't process the report without the source code available
253 - name: Checkout
254 uses: actions/checkout@v4
255 - name: Set up Go
256 uses: actions/setup-go@v5
257 with:
258 go-version-file: 'go.mod'
259 check-latest: true
260 - name: Download unit test coverage
261 uses: actions/download-artifact@v4
262 with:
263 name: coverage-data-unit
264 path: coverage/unit
265 merge-multiple: true
266 - name: Download E2E test coverage
267 uses: actions/download-artifact@v4
268 with:
269 pattern: coverage-data-e2e-*
270 path: coverage/e2e
271 merge-multiple: true
272 - name: Merge coverage reports
273 run: |
274 go tool covdata textfmt -i=./coverage/unit,./coverage/e2e -o ./coverage.txt
275 - name: Store coverage report in GitHub Actions
276 uses: actions/upload-artifact@v4
277 with:
278 name: go-covdata-txt
279 path: ./coverage.txt
280 if-no-files-found: error
281 - name: Upload coverage to Codecov
282 uses: codecov/codecov-action@v3
283 with:
284 files: ./coverage.txt
285
286 release:
287 permissions:
288 contents: write # to create a release (ncipollo/release-action)
289
290 runs-on: ubuntu-latest
291 needs:
292 - binary
293 steps:
294 -
295 name: Checkout
296 uses: actions/checkout@v4
297 -
298 name: Download artifacts
299 uses: actions/download-artifact@v4
300 with:
301 pattern: compose-*
302 path: ./bin/release
303 merge-multiple: true
304 -
305 name: Create checksums
306 working-directory: ./bin/release
307 run: |
308 find . -type f -print0 | sort -z | xargs -r0 shasum -a 256 -b | sed 's# \*\./# *#' > $RUNNER_TEMP/checksums.txt
309 shasum -a 256 -U -c $RUNNER_TEMP/checksums.txt
310 mv $RUNNER_TEMP/checksums.txt .
311 cat checksums.txt | while read sum file; do
312 if [[ "${file#\*}" == docker-compose-* && "${file#\*}" != *.provenance.json && "${file#\*}" != *.sbom.json ]]; then
313 echo "$sum $file" > ${file#\*}.sha256
314 fi
315 done
316 -
317 name: List artifacts
318 run: |
319 tree -nh ./bin/release
320 -
321 name: Check artifacts
322 run: |
323 find bin/release -type f -exec file -e ascii -- {} +
324 -
325 name: GitHub Release
326 if: startsWith(github.ref, 'refs/tags/v')
327 uses: ncipollo/release-action@58ae73b360456532aafd58ee170c045abbeaee37 # v1.10.0
328 with:
329 artifacts: ./bin/release/*
330 generateReleaseNotes: true
331 draft: true
332 token: ${{ secrets.GITHUB_TOKEN }}