Skip to content

Commit b3a2e3a

Browse files
committed
Add callable workflow
This moves all the remaining logic into this repository where it can be more easily iterated on.
1 parent 2ba80b6 commit b3a2e3a

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

.github/workflows/codeql-query.yml

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
name: CodeQL query
2+
3+
on:
4+
workflow_call:
5+
secrets:
6+
ACTIONS_STEP_DEBUG:
7+
description: step debug
8+
9+
jobs:
10+
run-query:
11+
runs-on: ubuntu-latest
12+
strategy:
13+
fail-fast: false
14+
matrix:
15+
repoIds: ${{ fromJSON(github.event.inputs.repoIdChunks) }}
16+
17+
steps:
18+
# Use ::add::mask for all tokens.
19+
# Theoretically we'll only output a subset of the tokens. Unless it causes a
20+
# performance issue, we may as well mask all tokens to be extra safe.
21+
# Note that masking does not persist to other/future jobs in the same workflow.
22+
- name: Mask tokens
23+
run: |
24+
jq .inputs.repositories "$GITHUB_EVENT_PATH" --raw-output | \
25+
jq '[.[].token , .[].pat] | map( select( . != null ) ) | .[]' --raw-output | \
26+
xargs -I {} echo "::add-mask::{}"
27+
28+
# Extract the subset of the repositories input that we'll be analysing for this
29+
# job, using the repoIds matrix input.
30+
- name: Compute subset of repos
31+
id: repos
32+
shell: node {0}
33+
run: |
34+
const allRepos = ${{ github.event.inputs.repositories }};
35+
const repoIds = new Set(${{ toJSON(matrix.repoIds) }});
36+
const repositories = allRepos.filter(r => repoIds.has(r.id));
37+
console.log(`::set-output name=repositories::${JSON.stringify(repositories)}`);
38+
39+
# This might not be the cleanest way to get hold of CodeQL but it's reliable
40+
# and widely used. The ugly part is that is initialises a database of the
41+
# given language that we just ignore.
42+
- name: Initialize CodeQL
43+
id: init
44+
uses: github/codeql-action/init@v1
45+
with:
46+
languages: ${{ github.event.inputs.language }}
47+
48+
- name: Run query
49+
uses: dsp-testing/qc-run2/query@rneatherway/usable
50+
with:
51+
query: ${{ github.event.inputs.query }}
52+
language: ${{ github.event.inputs.language }}
53+
repositories: ${{ steps.repos.outputs.repositories }}
54+
codeql: ${{ steps.init.outputs.codeql-path }}
55+
56+
combine-results:
57+
runs-on: ubuntu-latest
58+
needs:
59+
- run-query
60+
61+
steps:
62+
- name: Combine results
63+
uses: dsp-testing/qc-run2/combine-results@rneatherway/usable
64+
with:
65+
query: ${{ github.event.inputs.query }}
66+
language: ${{ github.event.inputs.language }}
67+
token: ${{ github.token }}

.github/workflows/tmp.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CodeQL query
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
query:
7+
description: "Text of CodeQL query to run."
8+
required: true
9+
10+
language:
11+
description: "Language of CodeQL query"
12+
required: true
13+
14+
# Handle this input very carefully as it contains sensitive data such as the authentication tokens!
15+
repositories:
16+
description: "Repositories to run the query against. A JSON encoded array of the form {id: number, nwo: string, token: string}[]"
17+
required: true
18+
19+
repoIdChunks:
20+
description: "Array of arrays of repository ids. Each of the inner arrays will be processed in a separate job"
21+
required: true
22+
23+
jobs:
24+
top:
25+
uses: dsp-testing/qc-run2/.github/workflows/codeql-query.yml@rneatherway/usable
26+
secrets:
27+
ACTIONS_STEP_DEBUG: ${{ secrets.ACTIONS_STEP_DEBUG }}

0 commit comments

Comments
 (0)