Skip to content

Commit b5d7ade

Browse files
Merge pull request #1979 from kristof-mattei/manual-rust-build
fix: manually build Rust for codeql as per our standard build
2 parents ea1a516 + af9390e commit b5d7ade

File tree

1 file changed

+67
-46
lines changed

1 file changed

+67
-46
lines changed

.github/workflows/codeql.yml

Lines changed: 67 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ on:
88
schedule:
99
- cron: "32 23 * * 5"
1010

11+
env:
12+
CARGO_TERM_COLOR: always
13+
1114
jobs:
1215
analyze:
1316
name: Analyze (${{ matrix.language }})
@@ -21,13 +24,6 @@ jobs:
2124
# required for all workflows
2225
security-events: write
2326

24-
# required to fetch internal or private CodeQL packs
25-
packages: read
26-
27-
# only required for workflows in private repositories
28-
actions: read
29-
contents: read
30-
3127
strategy:
3228
fail-fast: false
3329
matrix:
@@ -36,56 +32,81 @@ jobs:
3632
build-mode: none
3733
- language: javascript-typescript
3834
build-mode: none
39-
- language: rust
40-
build-mode: none
41-
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
42-
# Use `c-cpp` to analyze code written in C, C++ or both
43-
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
44-
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
45-
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
46-
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
47-
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
48-
# 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+
4936
steps:
50-
- name: Checkout repository
37+
- name: Checkout
5138
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
39+
with:
40+
show-progress: false
5241

53-
# Add any setup steps before running the `github/codeql-action/init` action.
54-
# This includes steps like installing compilers or runtimes (`actions/setup-node`
55-
# or others). This is typically only required for manual builds.
56-
# - name: Setup runtime (example)
57-
# uses: actions/setup-example@v1
58-
59-
# Initializes the CodeQL tools for scanning.
6042
- name: Initialize CodeQL
6143
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
6244
with:
6345
languages: ${{ matrix.language }}
6446
build-mode: ${{ matrix.build-mode }}
65-
# If you wish to specify custom queries, you can do so here or in a config file.
66-
# By default, queries listed here will override any specified in a config file.
67-
# Prefix the list here with "+" to use these queries and those in the config file.
68-
69-
# 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
70-
# queries: security-extended,security-and-quality
71-
72-
# If the analyze step fails for one of the languages you are analyzing with
73-
# "We were unable to automatically build your code", modify the matrix above
74-
# to set the build mode to "manual" for that language. Then modify this step
75-
# to build your code.
76-
# ℹ️ Command-line programs to run using the OS shell.
77-
# 📚 See https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstepsrun
78-
- if: matrix.build-mode == 'manual'
47+
queries: security-extended,security-and-quality
48+
49+
- name: Perform CodeQL Analysis
50+
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
51+
with:
52+
category: "/language:${{matrix.language}}"
53+
54+
analyze-rust:
55+
name: Analyze (Rust)
56+
runs-on: "ubuntu-latest"
57+
permissions:
58+
# required for all workflows
59+
security-events: write
60+
61+
steps:
62+
- name: Checkout
63+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
64+
with:
65+
show-progress: false
66+
67+
- name: Initialize CodeQL
68+
uses: github/codeql-action/init@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
69+
with:
70+
languages: rust
71+
build-mode: manual
72+
queries: security-extended,security-and-quality
73+
74+
- name: Cache dependencies
75+
uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
76+
env:
77+
CACHE_NAME: cargo-cache-dependencies
78+
with:
79+
path: |
80+
~/.cargo
81+
./target
82+
key: ${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-build
83+
restore-keys: |
84+
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-${{ hashFiles('Cargo.lock') }}-
85+
${{ runner.os }}-${{ runner.arch }}-build-${{ env.CACHE_NAME }}-
86+
87+
- name: Set up mold
88+
uses: rui314/setup-mold@85c79d00377f0d32cdbae595a46de6f7c2fa6599 # v1
89+
90+
- name: Set up toolchain
91+
shell: bash
92+
run: |
93+
rm ${HOME}/.cargo/bin/cargo-fmt
94+
rm ${HOME}/.cargo/bin/rust-analyzer
95+
rm ${HOME}/.cargo/bin/rustfmt
96+
97+
rustup self update
98+
rustup update
99+
rustup show active-toolchain || rustup toolchain install
100+
rustup show
101+
102+
cargo --version
103+
104+
- name: Build
79105
shell: bash
80106
run: |
81-
echo 'If you are using a "manual" build mode for one or more of the' \
82-
'languages you are analyzing, replace this with the commands to build' \
83-
'your code, for example:'
84-
echo ' make bootstrap'
85-
echo ' make release'
86-
exit 1
107+
cargo build --all-targets --workspace --verbose
87108
88109
- name: Perform CodeQL Analysis
89110
uses: github/codeql-action/analyze@181d5eefc20863364f96762470ba6f862bdef56b # v3.29.2
90111
with:
91-
category: "/language:${{matrix.language}}"
112+
category: "/language:rust"

0 commit comments

Comments
 (0)