Repository navigation
109 lines (97 loc) · 4.26 KB
/
Copy pathcodeql.yml
File metadata and controls
109 lines (97 loc) · 4.26 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
name: "CodeQL"
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
schedule:
- cron: '30 1 * * 0'
workflow_dispatch:
jobs:
analyze:
name: Analyze (${{ matrix.name }})
runs-on: ubuntu-latest
timeout-minutes: 30
permissions:
security-events: write
packages: read
actions: read
contents: read
strategy:
fail-fast: false
matrix:
include:
# Fabric side is one shared source tree (`src/client/java`) resolved per-version by
# Stonecutter; building one representative version is enough for CodeQL to trace real
# compiled output for that source, rather than the templated (pre-Stonecutter) files.
- name: fabric
build: ./gradlew :1.21.1:build --no-daemon
# The three NeoForge ports are separate Gradle projects that intentionally reuse the
# same Java package/class names as the Fabric side (they're 1:1 ports, kept diff-friendly
# against each other) — each needs its own build-mode:manual run and its own analysis
# category, otherwise CodeQL treats the whole checkout as one namespace and silently
# drops ~3/4 of the clashing classes from analysis (see issue tracker for background).
- name: neoforge-1.21.1
build: cd neoforge && ./gradlew build --no-daemon
- name: neoforge-1.21.11
build: cd neoforge-1.21.11 && ./gradlew build --no-daemon
- name: neoforge-26.2
build: cd neoforge-26.2 && ./gradlew build --no-daemon
steps:
- name: Checkout repository
uses: actions/checkout@v4
# All four projects build against Java 21 (NeoGradle specifically requires it regardless
# of target Minecraft version; the shared Fabric root also supports 21 for MC 1.21.1).
- name: Set up JDK 21
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '21'
- name: Initialize CodeQL
uses: github/codeql-action/init@v3
with:
languages: java-kotlin
build-mode: manual
- name: Build (${{ matrix.name }})
run: ${{ matrix.build }}
# build-mode:manual extracts every file the traced build compiles, including
# NeoGradle's own neoForm step decompiling vanilla Minecraft into build/. The
# config-file paths-ignore option does NOT filter compiled-language results that
# come from build tracing (verified: identical results_count with and without
# it) — so filter the SARIF by hand before upload instead of relying on it.
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:java-kotlin-${{ matrix.name }}"
output: ../results
upload: never
- name: Drop NeoForm-decompiled vanilla source from SARIF
run: |
python3 - <<'PY'
import json, glob
def touches_build(result):
locs = result.get("locations", []) + result.get("relatedLocations", [])
for loc in locs:
uri = loc.get("physicalLocation", {}).get("artifactLocation", {}).get("uri", "")
if "/build/" in uri or uri.startswith("build/"):
return True
for flow in result.get("codeFlows", []):
for thread in flow.get("threadFlows", []):
for step in thread.get("locations", []):
uri = step.get("location", {}).get("physicalLocation", {}).get("artifactLocation", {}).get("uri", "")
if "/build/" in uri or uri.startswith("build/"):
return True
return False
for path in glob.glob("../results/*.sarif"):
with open(path) as f:
sarif = json.load(f)
for run in sarif.get("runs", []):
run["results"] = [r for r in run.get("results", []) if not touches_build(r)]
with open(path, "w") as f:
json.dump(sarif, f)
PY
- name: Upload filtered SARIF
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ../results
category: "/language:java-kotlin-${{ matrix.name }}"