Repository navigation
431 lines (377 loc) · 17.9 KB
/
Copy pathpublish.yml
File metadata and controls
431 lines (377 loc) · 17.9 KB
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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
name: Publish CodeQL Packs
# Auto-publish only fires when .release.yml itself changes - that's the
# deliberate "cut a release" signal (see update-release.yml, which bumps
# .release.yml and every pack version together in one PR). Individual pack
# version bumps merged outside of that flow do NOT auto-publish; use
# workflow_dispatch for one-off hotfixes (see CONTRIBUTING.md).
on:
push:
branches: [main]
paths:
- ".release.yml"
workflow_dispatch:
jobs:
queries:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
language: ["actions", "cpp", "csharp", "go", "java", "javascript", "python", "ruby", "rust", "swift"]
steps:
- uses: actions/checkout@v7
- name: Check codeql-LANG-queries (src) pack
id: check_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# A brand-new pack's container doesn't exist on GHCR yet, so `gh api` 404s. On any
# failure, force PUBLISHED_VERSION empty rather than trusting whatever ended up on
# stdout: on error, `gh api` prints the raw (unfiltered) response body there - e.g.
# `{"message":"Package not found.",...}` - even with `--jq` and even with
# `2>/dev/null`. That body's embedded double quotes previously broke out of the
# `--arg previous_version "..."` quoting in the "Record publish result" step below,
# corrupting its jq invocation into writing a bare `true`/`false` instead of a JSON
# object - which then broke the release summary table for every language, not just
# the newly-published one (this is what happened publishing v0.7.1's new go/python
# `ext` packs for the first time).
if ! PUBLISHED_VERSION=$(gh api /orgs/githubsecuritylab/packages/container/codeql-${{ matrix.language }}-queries/versions --jq '.[0].metadata.container.tags[0]' 2>/dev/null); then
PUBLISHED_VERSION=""
fi
CURRENT_VERSION=$(grep -E '^version:' ${{ matrix.language }}/src/qlpack.yml | head -1 | awk '{print $2}')
echo "Published version: $PUBLISHED_VERSION"
echo "Local version: $CURRENT_VERSION"
echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
if [ "$PUBLISHED_VERSION" != "$CURRENT_VERSION" ]; then
echo "publish=true" >> $GITHUB_OUTPUT
fi
- name: Setup CodeQL
if: steps.check_version.outputs.publish == 'true'
uses: ./.github/actions/install-codeql
- name: Publish codeql-LANG-queries (src) pack.
id: publish
if: steps.check_version.outputs.publish == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Publishing codeql-${{ matrix.language }}-queries."
codeql pack install "${{ matrix.language }}/src"
codeql pack publish "${{ matrix.language }}/src"
- name: Record publish result
if: always()
env:
# Passed via env (not raw `${{ }}` interpolation) since these values ultimately
# derive from external content (a GHCR tag, or `gh api`'s error body on a 404 - see
# the `check_version` step above) that could contain a literal `"`. Interpolating
# such a value directly into `--arg previous_version "${{ ... }}"` below would break
# out of that quoting and corrupt the whole jq invocation; referenced as a shell
# variable instead, it's always passed through safely no matter its content.
PREVIOUS_VERSION: ${{ steps.check_version.outputs.published_version }}
TARGET_VERSION: ${{ steps.check_version.outputs.current_version }}
run: |
mkdir -p publish-results
STATUS="up-to-date"
if [ "${{ steps.check_version.outcome }}" != "success" ]; then
STATUS="failed"
elif [ "${{ steps.check_version.outputs.publish }}" == "true" ]; then
if [ "${{ steps.publish.outcome }}" == "success" ]; then
STATUS="published"
else
STATUS="failed"
fi
fi
jq -n \
--arg language "${{ matrix.language }}" \
--arg type "src" \
--arg package "codeql-${{ matrix.language }}-queries" \
--arg previous_version "$PREVIOUS_VERSION" \
--arg target_version "$TARGET_VERSION" \
--arg status "$STATUS" \
'{language: $language, type: $type, package: $package, previous_version: $previous_version, target_version: $target_version, status: $status}' \
> "publish-results/${{ matrix.language }}-src.json"
- name: Upload publish result
if: always()
uses: actions/upload-artifact@v7
with:
name: publish-result-${{ matrix.language }}-src
path: publish-results/${{ matrix.language }}-src.json
retention-days: 1
library:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
language: ["cpp", "csharp", "go", "java", "javascript", "python", "ruby"]
steps:
- uses: actions/checkout@v7
- name: Check codeql-LANG-libs (lib) pack
id: check_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# See the `queries` job above for why PUBLISHED_VERSION is forced empty on any
# `gh api` failure instead of relying on `|| true`.
if ! PUBLISHED_VERSION=$(gh api /orgs/githubsecuritylab/packages/container/codeql-${{ matrix.language }}-libs/versions --jq '.[0].metadata.container.tags[0]' 2>/dev/null); then
PUBLISHED_VERSION=""
fi
CURRENT_VERSION=$(grep -E '^version:' ${{ matrix.language }}/lib/qlpack.yml | head -1 | awk '{print $2}')
echo "Published version: $PUBLISHED_VERSION"
echo "Local version: $CURRENT_VERSION"
echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
if [ "$PUBLISHED_VERSION" != "$CURRENT_VERSION" ]; then
echo "publish=true" >> $GITHUB_OUTPUT
fi
- name: Setup CodeQL
if: steps.check_version.outputs.publish == 'true'
uses: ./.github/actions/install-codeql
- name: Publish codeql-LANG-libs (lib) pack
id: publish
if: steps.check_version.outputs.publish == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Publishing codeql-${{ matrix.language }}-libs."
codeql pack install "${{ matrix.language }}/lib"
codeql pack publish "${{ matrix.language }}/lib"
- name: Record publish result
if: always()
env:
# See the `queries` job above for why these are passed via env, not `${{ }}`.
PREVIOUS_VERSION: ${{ steps.check_version.outputs.published_version }}
TARGET_VERSION: ${{ steps.check_version.outputs.current_version }}
run: |
mkdir -p publish-results
STATUS="up-to-date"
if [ "${{ steps.check_version.outcome }}" != "success" ]; then
STATUS="failed"
elif [ "${{ steps.check_version.outputs.publish }}" == "true" ]; then
if [ "${{ steps.publish.outcome }}" == "success" ]; then
STATUS="published"
else
STATUS="failed"
fi
fi
jq -n \
--arg language "${{ matrix.language }}" \
--arg type "lib" \
--arg package "codeql-${{ matrix.language }}-libs" \
--arg previous_version "$PREVIOUS_VERSION" \
--arg target_version "$TARGET_VERSION" \
--arg status "$STATUS" \
'{language: $language, type: $type, package: $package, previous_version: $previous_version, target_version: $target_version, status: $status}' \
> "publish-results/${{ matrix.language }}-lib.json"
- name: Upload publish result
if: always()
uses: actions/upload-artifact@v7
with:
name: publish-result-${{ matrix.language }}-lib
path: publish-results/${{ matrix.language }}-lib.json
retention-days: 1
extensions:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
language: ["csharp", "go", "java", "python", "rust"]
steps:
- uses: actions/checkout@v7
- name: Check codeql-LANG-extensions (ext) pack
id: check_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# See the `queries` job above for why PUBLISHED_VERSION is forced empty on any
# `gh api` failure instead of relying on `|| true`.
if ! PUBLISHED_VERSION=$(gh api /orgs/githubsecuritylab/packages/container/codeql-${{ matrix.language }}-extensions/versions --jq '.[0].metadata.container.tags[0]' 2>/dev/null); then
PUBLISHED_VERSION=""
fi
CURRENT_VERSION=$(grep -E '^version:' ${{ matrix.language }}/ext/qlpack.yml | head -1 | awk '{print $2}')
echo "Published version: $PUBLISHED_VERSION"
echo "Local version: $CURRENT_VERSION"
echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
if [ "$PUBLISHED_VERSION" != "$CURRENT_VERSION" ]; then
echo "publish=true" >> $GITHUB_OUTPUT
fi
- name: Setup CodeQL
if: steps.check_version.outputs.publish == 'true'
uses: ./.github/actions/install-codeql
- name: Publish codeql-LANG-extensions (ext) pack
id: publish
if: steps.check_version.outputs.publish == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Publishing codeql-${{ matrix.language }}-extensions."
# NOTE: deliberately no `codeql pack install` here. `ext` is a CodeQL model/extension
# pack (`library: true`, `extensionTargets`, no `dependencies`) - installing it just
# (re)writes a `codeql-pack.lock.yml` with an empty `dependencies: {}` map, and a
# checked-in lock file in that state makes a subsequent `codeql pack publish`/`create`
# emit a bogus `addsTo.pack '...' is not an extension target of '...'` warning for every
# data extension in the pack (a known CodeQL CLI bug, see
# https://github.com/github/codeql/issues/20211). See CONTRIBUTING.md.
codeql pack publish "${{ matrix.language }}/ext"
- name: Record publish result
if: always()
env:
# See the `queries` job above for why these are passed via env, not `${{ }}`.
PREVIOUS_VERSION: ${{ steps.check_version.outputs.published_version }}
TARGET_VERSION: ${{ steps.check_version.outputs.current_version }}
run: |
mkdir -p publish-results
STATUS="up-to-date"
if [ "${{ steps.check_version.outcome }}" != "success" ]; then
STATUS="failed"
elif [ "${{ steps.check_version.outputs.publish }}" == "true" ]; then
if [ "${{ steps.publish.outcome }}" == "success" ]; then
STATUS="published"
else
STATUS="failed"
fi
fi
jq -n \
--arg language "${{ matrix.language }}" \
--arg type "ext" \
--arg package "codeql-${{ matrix.language }}-extensions" \
--arg previous_version "$PREVIOUS_VERSION" \
--arg target_version "$TARGET_VERSION" \
--arg status "$STATUS" \
'{language: $language, type: $type, package: $package, previous_version: $previous_version, target_version: $target_version, status: $status}' \
> "publish-results/${{ matrix.language }}-ext.json"
- name: Upload publish result
if: always()
uses: actions/upload-artifact@v7
with:
name: publish-result-${{ matrix.language }}-ext
path: publish-results/${{ matrix.language }}-ext.json
retention-days: 1
library_sources_extensions:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
strategy:
fail-fast: false
matrix:
language: ["csharp", "java"]
steps:
- uses: actions/checkout@v7
- name: Check codeql-LANG-library-sources (ext-library-sources) pack
id: check_version
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# See the `queries` job above for why PUBLISHED_VERSION is forced empty on any
# `gh api` failure instead of relying on `|| true`.
if ! PUBLISHED_VERSION=$(gh api /orgs/githubsecuritylab/packages/container/codeql-${{ matrix.language }}-library-sources/versions --jq '.[0].metadata.container.tags[0]' 2>/dev/null); then
PUBLISHED_VERSION=""
fi
CURRENT_VERSION=$(grep -E '^version:' ${{ matrix.language }}/ext-library-sources/qlpack.yml | head -1 | awk '{print $2}')
echo "Published version: $PUBLISHED_VERSION"
echo "Local version: $CURRENT_VERSION"
echo "published_version=$PUBLISHED_VERSION" >> $GITHUB_OUTPUT
echo "current_version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
if [ "$PUBLISHED_VERSION" != "$CURRENT_VERSION" ]; then
echo "publish=true" >> $GITHUB_OUTPUT
fi
- name: Setup CodeQL
if: steps.check_version.outputs.publish == 'true'
uses: ./.github/actions/install-codeql
- name: Publish codeql-LANG-library-sources (ext-library-sources) pack
id: publish
if: steps.check_version.outputs.publish == 'true'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
echo "Publishing codeql-${{ matrix.language }}-library-sources."
# NOTE: deliberately no `codeql pack install` here - see the matching comment in the
# `extensions` job above.
codeql pack publish "${{ matrix.language }}/ext-library-sources"
- name: Record publish result
if: always()
env:
# See the `queries` job above for why these are passed via env, not `${{ }}`.
PREVIOUS_VERSION: ${{ steps.check_version.outputs.published_version }}
TARGET_VERSION: ${{ steps.check_version.outputs.current_version }}
run: |
mkdir -p publish-results
STATUS="up-to-date"
if [ "${{ steps.check_version.outcome }}" != "success" ]; then
STATUS="failed"
elif [ "${{ steps.check_version.outputs.publish }}" == "true" ]; then
if [ "${{ steps.publish.outcome }}" == "success" ]; then
STATUS="published"
else
STATUS="failed"
fi
fi
jq -n \
--arg language "${{ matrix.language }}" \
--arg type "ext-library-sources" \
--arg package "codeql-${{ matrix.language }}-library-sources" \
--arg previous_version "$PREVIOUS_VERSION" \
--arg target_version "$TARGET_VERSION" \
--arg status "$STATUS" \
'{language: $language, type: $type, package: $package, previous_version: $previous_version, target_version: $target_version, status: $status}' \
> "publish-results/${{ matrix.language }}-ext-library-sources.json"
- name: Upload publish result
if: always()
uses: actions/upload-artifact@v7
with:
name: publish-result-${{ matrix.language }}-ext-library-sources
path: publish-results/${{ matrix.language }}-ext-library-sources.json
retention-days: 1
summary:
name: Publish summary
needs: [queries, library, extensions, library_sources_extensions]
if: always()
runs-on: ubuntu-latest
permissions:
contents: write
actions: read
steps:
- uses: actions/checkout@v7
# Not actions/download-artifact with merge-multiple: a re-run or restarted publish job
# leaves a second same-named artifact in the run, and merge-multiple can let the stale
# (e.g. cancelled/failed) one overwrite the newer result. This keeps the newest per name.
- name: Download publish results
continue-on-error: true
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: .github/scripts/download-latest-publish-results.sh "${{ github.run_id }}" publish-results
- name: Build summary table
run: |
mkdir -p publish-results
echo "Result fragments found:"
ls -la publish-results
.github/scripts/build-publish-summary.sh publish-results > summary.md
echo "summary.md is $(wc -l < summary.md) lines, $(wc -c < summary.md) bytes"
cat summary.md >> "$GITHUB_STEP_SUMMARY"
- name: Build CodeQL library & query pack versions table
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
.github/scripts/build-codeql-lib-versions-table.sh > codeql-lib-versions.md
cat codeql-lib-versions.md >> "$GITHUB_STEP_SUMMARY"
- name: Upsert release table
# Only the release-cut path (push to .release.yml) should touch a GitHub Release's
# notes. A workflow_dispatch run is often a one-off hotfix publish for a single pack
# (see CONTRIBUTING.md's "Manual/one-off hotfix publish") while .release.yml still
# points at the last cut release - upserting this run's tables into that release would
# misleadingly overwrite its notes with a summary of an unrelated hotfix run.
if: github.event_name == 'push'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
.github/scripts/upsert-release-table.sh summary.md publish-summary
.github/scripts/upsert-release-table.sh codeql-lib-versions.md codeql-lib-versions