Skip to content

Commit 7cd7f70

Browse files
authored
Refactor CodeQL workflow for improved clarity
1 parent 7452287 commit 7cd7f70

1 file changed

Lines changed: 50 additions & 71 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 50 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,28 @@
1-
# For most projects, this workflow file will not need changing; you simply need
2-
# to commit it to your repository.
3-
#
4-
# You may wish to alter this file to override the set of languages analyzed,
5-
# or to provide custom queries or build logic.
6-
#
7-
# ******** NOTE ********
8-
# We have attempted to detect the languages in your repository. Please check
9-
# the `language` matrix defined below to confirm you have the correct set of
10-
# supported CodeQL languages.
11-
#
121
name: "CodeQL Advanced"
132

143
on:
154
push:
16-
branches: [ "main" ]
5+
branches: ["main"]
176
pull_request:
18-
branches: [ "main" ]
7+
branches: ["main"]
198
schedule:
20-
- cron: '35 19 * * 5'
9+
- cron: "35 19 * * 5"
10+
workflow_dispatch:
11+
12+
concurrency:
13+
group: codeql-${{ github.workflow }}-${{ github.ref }}
14+
cancel-in-progress: true
2115

2216
jobs:
2317
analyze:
2418
name: Analyze (${{ matrix.language }})
25-
# Runner size impacts CodeQL analysis time. To learn more, please see:
26-
# - https://gh.io/recommended-hardware-resources-for-running-codeql
27-
# - https://gh.io/supported-runners-and-hardware-resources
28-
# - https://gh.io/using-larger-runners (GitHub.com only)
29-
# Consider using larger runners or machines with greater resources for possible analysis time improvements.
3019
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') || 'ubuntu-latest' }}
20+
3121
permissions:
32-
# required for all workflows
3322
security-events: write
34-
35-
# required to fetch internal or private CodeQL packs
36-
packages: read
37-
38-
# only required for workflows in private repositories
3923
actions: read
4024
contents: read
25+
packages: read
4126

4227
strategy:
4328
fail-fast: false
@@ -47,55 +32,49 @@ jobs:
4732
build-mode: none
4833
- language: javascript-typescript
4934
build-mode: none
50-
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
51-
# Use `c-cpp` to analyze code written in C, C++ or both
52-
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
53-
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
54-
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
55-
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
56-
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
57-
# your codebase is analyzed, see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/codeql-code-scanning-for-compiled-languages
35+
5836
steps:
59-
- name: Checkout repository
60-
uses: actions/checkout@v4
37+
- name: Checkout repository
38+
uses: actions/checkout@v4
39+
with:
40+
fetch-depth: 0
41+
42+
- name: Setup Node.js
43+
if: matrix.language == 'javascript-typescript'
44+
uses: actions/setup-node@v4
45+
with:
46+
node-version: 20
47+
cache: npm
6148

62-
# Add any setup steps before running the `github/codeql-action/init` action.
63-
# This includes steps like installing compilers or runtimes (`actions/setup-node`
64-
# or others). This is typically only required for manual builds.
65-
# - name: Setup runtime (example)
66-
# uses: actions/setup-example@v1
49+
- name: Install dependencies
50+
if: matrix.language == 'javascript-typescript'
51+
shell: bash
52+
run: |
53+
if [ -f package-lock.json ] || [ -f npm-shrinkwrap.json ]; then
54+
npm ci
55+
else
56+
echo "No npm lockfile found; skipping npm install"
57+
fi
6758
68-
# Initializes the CodeQL tools for scanning.
69-
- name: Initialize CodeQL
70-
uses: github/codeql-action/init@v4
71-
with:
72-
languages: ${{ matrix.language }}
73-
build-mode: ${{ matrix.build-mode }}
74-
# If you wish to specify custom queries, you can do so here or in a config file.
75-
# By default, queries listed here will override any specified in a config file.
76-
# Prefix the list here with "+" to use these queries and those in the config file.
59+
- name: Initialize CodeQL
60+
uses: github/codeql-action/init@v4
61+
with:
62+
languages: ${{ matrix.language }}
63+
build-mode: ${{ matrix.build-mode }}
64+
config-file: ./.github/codeql/codeql-config.yml
7765

78-
# For more details on CodeQL's query packs, refer to: https://docs.github.com/en/code-security/code-scanning/automatically-scanning-your-code-for-vulnerabilities-and-errors/configuring-code-scanning#using-queries-in-ql-packs
79-
# queries: security-extended,security-and-quality
66+
- name: Autobuild
67+
if: matrix.build-mode == 'autobuild'
68+
uses: github/codeql-action/autobuild@v4
8069

81-
# If the analyze step fails for one of the languages you are analyzing with
82-
# "We were unable to automatically build your code", modify the matrix above
83-
# to set the build mode to "manual" for that language. Then modify this step
84-
# to build your code.
85-
# ℹ️ Command-line programs to run using the OS shell.
86-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
87-
- name: Run manual build steps
88-
if: matrix.build-mode == 'manual'
89-
shell: bash
90-
run: |
91-
echo 'If you are using a "manual" build mode for one or more of the' \
92-
'languages you are analyzing, replace this with the commands to build' \
93-
'your code, for example:'
94-
echo ' make bootstrap'
95-
echo ' make release'
96-
exit 1
70+
- name: Run manual build steps
71+
if: matrix.build-mode == 'manual'
72+
shell: bash
73+
run: |
74+
echo "Add your manual build commands here"
75+
exit 1
9776
98-
- name: Perform CodeQL Analysis
99-
uses: github/codeql-action/analyze@v4
100-
with:
101-
category: "/language:${{matrix.language}}"
77+
- name: Perform CodeQL Analysis
78+
uses: github/codeql-action/analyze@v4
79+
with:
80+
category: "/language:${{ matrix.language }}"

0 commit comments

Comments
 (0)