Repository navigation
125 lines (118 loc) · 5.96 KB
/
Copy pathcodeql.yml
File metadata and controls
125 lines (118 loc) · 5.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
name: "CodeQL Advanced"
on:
push:
branches: [ "main" ]
# Markdown can't change the analysis. This isn't a required status
# check, so skipping the whole workflow is safe here (unlike ci.yml,
# whose jobs skip themselves so their checks still report).
paths-ignore: [ "**.md" ]
pull_request:
branches: [ "main" ]
paths-ignore: [ "**.md" ]
schedule:
- cron: '35 2 * * 0'
# Keyed on the pull request, not its branch's name: pull requests from two forks often share a branch name
# (`main`, `patch-1`), and would cancel each other's runs.
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: true
jobs:
analyze:
name: Analyze (${{ matrix.language }})
# Swift analysis requires macOS; the Actions-workflow analysis
# doesn't, and macOS runners are capped at five concurrent jobs.
runs-on: ${{ matrix.runs-on }}
permissions:
security-events: write
packages: read
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
- language: actions
build-mode: none
runs-on: ubuntu-latest
- language: swift
build-mode: manual
runs-on: macos-26
# CodeQL supports the following values keywords for 'language': 'actions', 'c-cpp', 'csharp', 'go', 'java-kotlin', 'javascript-typescript', 'python', 'ruby', 'rust', 'swift'
# Use `c-cpp` to analyze code written in C, C++ or both
# Use 'java-kotlin' to analyze code written in Java, Kotlin or both
# Use 'javascript-typescript' to analyze code written in JavaScript, TypeScript or both
# To learn more about changing the languages that are analyzed or customizing the build mode for your analysis,
# see https://docs.github.com/en/code-security/code-scanning/creating-an-advanced-setup-for-code-scanning/customizing-your-advanced-setup-for-code-scanning.
# If you are analyzing a compiled language, you can modify the 'build-mode' for that language to customize how
# 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
steps:
- name: Checkout repository
uses: actions/checkout@v7
- if: matrix.language == 'swift'
name: Select Xcode Version
run: sudo xcode-select --switch /Applications/Xcode_26.4.app/Contents/Developer
# CodeQL analyzes whatever the compiler is invoked on during the
# traced build. Restoring `.build` keeps the dependency build
# products (swift-syntax was ~90% of the build) so they aren't
# recompiled, and the Build step touches SafeDI's own sources so
# every target in this package is recompiled under the tracer.
# GitHub's guidance for Swift is to build only the code you want
# analyzed.
# GitHub's macOS images export ImageVersion (for example
# 20261102.0473.1) from ~/.bashrc; it is not in the `env` context, so a
# step reads it for the cache key below. The OS build stands in if an
# image ever stops exporting it.
- if: matrix.language == 'swift'
name: Read Runner Image Version
id: runner-image
run: echo "version=${ImageVersion:-$(sw_vers -buildVersion)}" >> "$GITHUB_OUTPUT"
- if: matrix.language == 'swift'
name: Cache Build Directory
uses: actions/cache@v6
with:
path: .build
# "native" distinguishes this cache from the one the emulated
# build wrote: an exact key hit is never re-saved, so reusing the
# old key would leave the arm64 build products uncached forever.
# The runner image is in the key for the same reason: when runner
# image 20261102.0473 rolled out, CI's macOS test job restored the
# previous image's cache and rebuilt swift-syntax (~8 min) on every
# run. The first run on a new image restores an older image's
# cache, builds incrementally, and saves under its own key.
key: codeql-swift-native-${{ runner.os }}-xcode-26.4-${{ steps.runner-image.outputs.version }}-${{ hashFiles('Package.resolved') }}
restore-keys: |
codeql-swift-native-${{ runner.os }}-xcode-26.4-${{ steps.runner-image.outputs.version }}-
codeql-swift-native-${{ runner.os }}-xcode-26.4-
# Initializes the CodeQL tools for scanning.
- name: Initialize CodeQL
uses: github/codeql-action/init@v4
with:
languages: ${{ matrix.language }}
build-mode: ${{ matrix.build-mode }}
# CodeQL's Swift extractor ships x86_64 only, so on Apple Silicon the
# tracer relocates the arm64e system binaries it needs to inject into
# (/bin/bash, /usr/bin/xcrun) and falls back to their x86_64 slices.
# Everything they spawn inherits that, so `xcrun swift build` ran
# SwiftPM itself under Rosetta: every toolchain binary paid a
# first-launch translation (swift --version alone took 2-4 minutes),
# the manifests compiled for x86_64, and the build went to
# .build/x86_64-apple-macosx, a directory no cache of ours warms.
#
# Launching the toolchain's own swift with `arch -arm64`, with Xcode's
# toolchain first on PATH so swiftc and git resolve to Xcode's arm64
# binaries, keeps SwiftPM and the compiler native; only the extractor
# runs under Rosetta. Measured on a warm cache: 797 s -> 446 s.
- if: matrix.language == 'swift'
name: Build
run: |
find Sources -name '*.swift' -exec touch {} +
DEVELOPER_DIR=$(xcode-select -p)
TOOLCHAIN="$DEVELOPER_DIR/Toolchains/XcodeDefault.xctoolchain/usr/bin"
export PATH="$TOOLCHAIN:$DEVELOPER_DIR/usr/bin:$PATH"
SDKROOT=$(xcrun --sdk macosx --show-sdk-path)
export SDKROOT
arch -arm64 "$TOOLCHAIN/swift" build --target SafeDI --target SafeDITool
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v4
with:
category: "/language:${{matrix.language}}"