Skip to content

Commit 5ea2162

Browse files
fix(ci): improve CodeQL analysis quality with Unity build
- Use game-ci/unity-builder to compile Unity scripts before CodeQL analysis for proper type information - Create centralized .github/unity-config.env for Unity CI settings - codeql.yml reads from config file at runtime - unity-tests.yml defaults match config file (with comments) This resolves the "Low C# analysis quality" warning by providing CodeQL with compiled assemblies that have full type information. Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net> Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 55e565d commit 5ea2162

3 files changed

Lines changed: 53 additions & 16 deletions

File tree

.github/unity-config.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Unity CI Configuration
2+
# =====================
3+
# Centralized configuration for all Unity-related GitHub Actions workflows.
4+
# Update these values here to change them across all workflows.
5+
6+
UNITY_VERSION=2022.3.55f1
7+
UNITY_PROJECT_PATH=UnityProject
8+
UNITY_TARGET_PLATFORM=StandaloneLinux64

.github/workflows/codeql.yml

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches: [master]
66
paths:
7-
# Only run when JEngine code changes
87
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
98
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
109
- 'UnityProject/Assets/HotUpdate/Code/**'
@@ -19,7 +18,6 @@ on:
1918
- '.github/codeql/**'
2019
- '.github/workflows/codeql.yml'
2120
schedule:
22-
# Run weekly on Sunday at 00:00 UTC
2321
- cron: '0 0 * * 0'
2422
workflow_dispatch:
2523

@@ -35,16 +33,51 @@ jobs:
3533
steps:
3634
- name: Checkout repository
3735
uses: actions/checkout@v4
36+
with:
37+
lfs: true
38+
39+
# Load centralized Unity configuration
40+
- name: Load Unity config
41+
id: unity-config
42+
run: |
43+
source .github/unity-config.env
44+
echo "version=$UNITY_VERSION" >> $GITHUB_OUTPUT
45+
echo "project_path=$UNITY_PROJECT_PATH" >> $GITHUB_OUTPUT
46+
echo "target_platform=$UNITY_TARGET_PLATFORM" >> $GITHUB_OUTPUT
47+
48+
- name: Cache Unity Library
49+
uses: actions/cache@v4
50+
with:
51+
path: ${{ steps.unity-config.outputs.project_path }}/Library
52+
key: Library-CodeQL-${{ steps.unity-config.outputs.version }}-${{ hashFiles(format('{0}/Packages/packages-lock.json', steps.unity-config.outputs.project_path)) }}
53+
restore-keys: |
54+
Library-CodeQL-${{ steps.unity-config.outputs.version }}-
55+
Library-CodeQL-
3856
3957
- name: Initialize CodeQL
4058
uses: github/codeql-action/init@v4
4159
with:
4260
languages: csharp
4361
config-file: ./.github/codeql/codeql-config.yml
44-
# Use security-and-quality queries for comprehensive analysis
4562
queries: security-and-quality
46-
# Use buildless mode for Unity projects (no standard .NET build)
47-
build-mode: none
63+
build-mode: manual
64+
65+
- name: Compile Unity Scripts
66+
uses: game-ci/unity-builder@v4
67+
env:
68+
UNITY_EMAIL: ${{ secrets.UNITY_EMAIL }}
69+
UNITY_PASSWORD: ${{ secrets.UNITY_PASSWORD }}
70+
UNITY_SERIAL: ${{ secrets.UNITY_SERIAL }}
71+
with:
72+
projectPath: ${{ steps.unity-config.outputs.project_path }}
73+
unityVersion: ${{ steps.unity-config.outputs.version }}
74+
targetPlatform: ${{ steps.unity-config.outputs.target_platform }}
75+
buildName: CodeQL
76+
customParameters: -nographics -quit
77+
78+
- name: Return Unity license
79+
uses: game-ci/unity-return-license@v2
80+
if: always()
4881

4982
- name: Perform CodeQL Analysis
5083
uses: github/codeql-action/analyze@v4

.github/workflows/unity-tests.yml

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
11
name: Unity Tests (Reusable)
22

3+
# Reusable workflow for running Unity tests
4+
# Default values should match .github/unity-config.env
5+
36
on:
47
workflow_call:
58
inputs:
69
unity_version:
7-
description: 'Unity version to use for testing'
10+
description: 'Unity version (default from .github/unity-config.env)'
811
required: false
912
type: string
10-
default: '2022.3.55f1'
13+
default: '2022.3.55f1' # Keep in sync with .github/unity-config.env
1114
test_mode:
1215
description: 'Test mode to run (All, EditMode, PlayMode)'
1316
required: false
1417
type: string
1518
default: 'All'
1619
project_path:
17-
description: 'Path to Unity project directory'
20+
description: 'Path to Unity project (default from .github/unity-config.env)'
1821
required: false
1922
type: string
20-
default: 'UnityProject'
23+
default: 'UnityProject' # Keep in sync with .github/unity-config.env
2124
outputs:
2225
test_results:
2326
description: 'Test results summary'
@@ -38,13 +41,11 @@ jobs:
3841
results: ${{ steps.test-summary.outputs.summary }}
3942

4043
steps:
41-
# Checkout repository
4244
- name: Checkout repository
4345
uses: actions/checkout@v4
4446
with:
4547
lfs: true
4648

47-
# Cache Unity Library folder for faster builds
4849
- name: Cache Unity Library
4950
uses: actions/cache@v4
5051
with:
@@ -54,7 +55,6 @@ jobs:
5455
Library-${{ inputs.project_path }}-${{ inputs.unity_version }}-
5556
Library-${{ inputs.project_path }}-
5657
57-
# Run EditMode tests
5858
- name: Run EditMode tests
5959
if: inputs.test_mode == 'All' || inputs.test_mode == 'EditMode'
6060
uses: game-ci/unity-test-runner@v4
@@ -71,7 +71,6 @@ jobs:
7171
githubToken: ${{ secrets.GITHUB_TOKEN }}
7272
checkName: EditMode Test Results
7373

74-
# Run PlayMode tests
7574
- name: Run PlayMode tests
7675
if: inputs.test_mode == 'All' || inputs.test_mode == 'PlayMode'
7776
uses: game-ci/unity-test-runner@v4
@@ -88,7 +87,6 @@ jobs:
8887
githubToken: ${{ secrets.GITHUB_TOKEN }}
8988
checkName: PlayMode Test Results
9089

91-
# Upload test results as artifacts
9290
- name: Upload EditMode test results
9391
if: always() && (inputs.test_mode == 'All' || inputs.test_mode == 'EditMode')
9492
uses: actions/upload-artifact@v4
@@ -107,7 +105,6 @@ jobs:
107105
if-no-files-found: warn
108106
retention-days: 14
109107

110-
# Generate test summary
111108
- name: Generate test summary
112109
id: test-summary
113110
if: always()
@@ -139,7 +136,6 @@ jobs:
139136
echo -e "$SUMMARY" >> $GITHUB_OUTPUT
140137
echo "EOF" >> $GITHUB_OUTPUT
141138
142-
# Return Unity license
143139
- name: Return Unity license
144140
uses: game-ci/unity-return-license@v2
145141
if: always()

0 commit comments

Comments
 (0)