Repository navigation
111 lines (101 loc) · 3.96 KB
/
Copy pathcodeql.yml
File metadata and controls
111 lines (101 loc) · 3.96 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
name: CodeQL
on:
workflow_call:
push:
branches: [main]
pull_request:
branches: [main]
schedule:
- cron: "17 6 * * 2"
workflow_dispatch:
permissions: {}
concurrency:
group: codeql-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: true
# A content-only pull request (a submission; see content-only.yml) skips the
# analysis. The skip is per step, not per job: a job-level `if:` is evaluated
# before the matrix is applied, so a skipped job would never report the
# required "Analyze javascript-typescript" and "Analyze ruby" contexts.
jobs:
changes:
permissions:
contents: read
uses: ./.github/workflows/content-only.yml
analyze:
name: Analyze ${{ matrix.language }}
needs: changes
# Runs even when the classification failed; the steps then run too.
if: ${{ !cancelled() }}
runs-on: ubuntu-latest
timeout-minutes: 20
permissions:
contents: read
security-events: write
strategy:
fail-fast: false
matrix:
language: [javascript-typescript, ruby]
steps:
- name: Skip the analysis of a content-only change
if: needs.changes.outputs.content_only == 'true'
run: echo "Content-only change, so the CodeQL analysis was skipped." >> "$GITHUB_STEP_SUMMARY"
- name: Checkout repository
if: needs.changes.outputs.content_only != 'true'
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Initialize CodeQL
if: needs.changes.outputs.content_only != 'true'
uses: github/codeql-action/init@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
with:
languages: ${{ matrix.language }}
build-mode: none
queries: security-extended
- name: Analyze repository
if: needs.changes.outputs.content_only != 'true'
uses: github/codeql-action/analyze@2892aa5e19bbd11bc0cff5427e3b750a04d9e3c2 # v4.38.2
with:
category: /language:${{ matrix.language }}
status:
name: Report the dispatched run on its commit
if: ${{ always() && github.event_name == 'workflow_dispatch' }}
needs: [changes, analyze]
runs-on: ubuntu-latest
timeout-minutes: 5
permissions:
contents: read
statuses: write
steps:
- name: Post a commit status
uses: actions/github-script@3a2844b7e9c422d3c10d287c895573f7108da1b3 # v9.0.0
with:
script: |
const contentOnly = ${{ toJSON(needs.changes.outputs.content_only) }} === 'true';
const result = ${{ toJSON(needs.analyze.result) }};
// The analysis skips by step, so a content-only run normally
// succeeds; the skipped case is kept for parity with the others.
const skipped = contentOnly && result === 'skipped';
const passed = result === 'success' || skipped;
const targetUrl = `${context.serverUrl}/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}`;
// A reusable-workflow dispatch prefixes matrix check names with the
// caller job. Publish the same canonical contexts as a normal PR so
// generated PRs satisfy the repository's required-status rules.
for (const statusContext of [
'Analyze javascript-typescript',
'Analyze ruby',
'CodeQL (dispatch)',
]) {
await github.rest.repos.createCommitStatus({
owner: context.repo.owner,
repo: context.repo.repo,
sha: context.sha,
state: passed ? 'success' : 'failure',
context: statusContext,
target_url: targetUrl,
description: contentOnly && passed
? 'Skipped: content-only change'
: passed
? 'CodeQL passed'
: 'CodeQL reported problems',
});
}