Repository navigation
92 lines (89 loc) · 4.43 KB
/
Copy pathcodeql.yml
File metadata and controls
92 lines (89 loc) · 4.43 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
name: CodeQL
# CodeQL's code scanning of the workflows, the TypeScript and the Rust, with the paths in
# .github/codeql/codeql-config.yml left out (the Rust tests). Default setup ran the same languages
# and suite but can't take a config file. Each language uploads under the category default setup
# used, so its alerts carry over.
#
# ci.yml calls it for every pull request into main, merge queue group and push to main but a
# draft's, with every language whatever changed. The "Protect Main" ruleset's code scanning rule
# holds a pull request or a merge queue group until its commit has a result in every category
# main has (netresearch/.github#170 had every queued pull request stuck on "Code scanning is still
# expecting 1 result from CodeQL", and so did #347 when only the languages that changed ran).
# CodeQL's own result is that check. No weekly run: main gets pushes most days, and each analyses
# with the queries of the action's pinned bundle.
#
# A language whose code, CodeQL config and this workflow are as they were at the commit ci.yml
# diffed against has that commit's results, so its job uploads that commit's analysis from main
# again, for this commit, in place of analysing it: about a minute where Rust takes 15 to 19.
# With no such analysis on main yet (its push run hasn't got there), it analyses.
on:
workflow_call:
inputs:
unchanged:
description: The languages whose code didn't change, as a JSON list.
type: string
required: true
base:
description: The commit ci.yml diffed a push or a merge queue group against; empty for a pull request, whose merge commit's first parent is the one.
type: string
required: true
permissions: {}
# Actions are pinned to commits (Dependabot keeps them current, see .github/dependabot.yml).
jobs:
analyze:
name: Analyze (${{ matrix.language }})
runs-on: ubuntu-latest
# Default setup's Rust analysis took 15 to 19 minutes with the tests in.
timeout-minutes: 40
permissions:
# Uploading the results to code scanning.
security-events: write
contents: read
strategy:
fail-fast: false
matrix:
language: [actions, javascript-typescript, rust]
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
# A pull request's merge commit and its first parent.
fetch-depth: 2
# main's analysis of the base commit in this language, when its code is unchanged and main
# has one. The list is filtered here (see .github/actions/last-passed).
- id: reuse
if: contains(fromJSON(inputs.unchanged), matrix.language)
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
BASE: ${{ inputs.base }}
CATEGORY: /language:${{ matrix.language }}
run: |
base=${BASE:-$(git rev-parse HEAD^1)}
id=$(gh api "repos/$GH_REPO/code-scanning/analyses?ref=refs/heads/main&tool_name=CodeQL&per_page=100" |
jq -r --arg category "$CATEGORY" --arg sha "$base" \
'[.[] | select(.category == $category and .commit_sha == $sha and .error == "")][0].id // empty')
if [ -z "$id" ]; then
echo "main has no $CATEGORY analysis of $base yet, so this one analyses"
exit 0
fi
gh api -H "Accept: application/sarif+json" "repos/$GH_REPO/code-scanning/analyses/$id" > "$RUNNER_TEMP/main.sarif"
echo "Reusing analysis $id of $base"
echo "sarif=$RUNNER_TEMP/main.sarif" >> "$GITHUB_OUTPUT"
- if: steps.reuse.outputs.sarif != ''
uses: github/codeql-action/upload-sarif@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
with:
sarif_file: ${{ steps.reuse.outputs.sarif }}
category: /language:${{ matrix.language }}
# Nothing is built: Rust and TypeScript are read from the source, which is also what lets
# paths-ignore leave files out.
- if: steps.reuse.outputs.sarif == ''
uses: github/codeql-action/init@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
with:
languages: ${{ matrix.language }}
build-mode: none
config-file: ./.github/codeql/codeql-config.yml
- if: steps.reuse.outputs.sarif == ''
uses: github/codeql-action/analyze@6f2ac81f5cd81fe351a197ba0b00d91d03cd2aee # v4.39.0
with:
category: /language:${{ matrix.language }}