Skip to content

Commit 0a614ce

Browse files
ci: support conditional required checks with path filtering (#576)
Use dorny/paths-filter to detect file changes at job level instead of workflow level. This ensures workflows always run and report a status to GitHub, solving the "Waiting for status" issue when path filters don't match. Changes: - pr-tests.yml: Add changes detection job, skip-tests job reports success when no relevant files changed - codeql.yml: Add changes detection job, skip-analyze job reports success when no relevant files changed, schedule/dispatch always run Both skip jobs use the same name as their actual counterparts so GitHub Ruleset correctly identifies the check status. Signed-off-by: JasonXuDeveloper - 傑 <jason@xgamedev.net> Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 55e565d commit 0a614ce

2 files changed

Lines changed: 77 additions & 20 deletions

File tree

.github/workflows/codeql.yml

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,29 +3,47 @@ name: CodeQL Security Analysis
33
on:
44
push:
55
branches: [master]
6-
paths:
7-
# Only run when JEngine code changes
8-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
9-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
10-
- 'UnityProject/Assets/HotUpdate/Code/**'
11-
- '.github/codeql/**'
12-
- '.github/workflows/codeql.yml'
6+
# Path filtering moved to job level for push events
137
pull_request:
148
branches: [master]
15-
paths:
16-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
17-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
18-
- 'UnityProject/Assets/HotUpdate/Code/**'
19-
- '.github/codeql/**'
20-
- '.github/workflows/codeql.yml'
9+
# Path filtering moved to job level using dorny/paths-filter
10+
# This ensures the workflow always runs and reports a status
2111
schedule:
2212
# Run weekly on Sunday at 00:00 UTC
2313
- cron: '0 0 * * 0'
2414
workflow_dispatch:
2515

2616
jobs:
17+
changes:
18+
name: Detect Changes
19+
runs-on: ubuntu-latest
20+
# Only run path detection for push/pull_request events
21+
if: github.event_name == 'push' || github.event_name == 'pull_request'
22+
outputs:
23+
should_analyze: ${{ steps.filter.outputs.src }}
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: dorny/paths-filter@v3
27+
id: filter
28+
with:
29+
filters: |
30+
src:
31+
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
32+
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
33+
- 'UnityProject/Assets/HotUpdate/Code/**'
34+
- '.github/codeql/**'
35+
- '.github/workflows/codeql.yml'
36+
2737
analyze:
2838
name: Analyze C# Code
39+
needs: changes
40+
# Run if: 1) changes detected, 2) schedule event, or 3) manual dispatch
41+
if: |
42+
always() && (
43+
needs.changes.outputs.should_analyze == 'true' ||
44+
github.event_name == 'schedule' ||
45+
github.event_name == 'workflow_dispatch'
46+
)
2947
runs-on: ubuntu-latest
3048
permissions:
3149
actions: read
@@ -50,3 +68,16 @@ jobs:
5068
uses: github/codeql-action/analyze@v4
5169
with:
5270
category: "/language:csharp"
71+
72+
skip-analyze:
73+
name: Analyze C# Code
74+
needs: changes
75+
# Only skip for push/pull_request when no relevant changes
76+
if: |
77+
always() &&
78+
(github.event_name == 'push' || github.event_name == 'pull_request') &&
79+
needs.changes.outputs.should_analyze == 'false'
80+
runs-on: ubuntu-latest
81+
steps:
82+
- name: Skip analysis
83+
run: echo "No relevant changes detected, skipping CodeQL analysis"

.github/workflows/pr-tests.yml

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ name: PR Tests
22

33
on:
44
pull_request:
5+
branches: [master]
56
types: [opened, synchronize, reopened]
6-
paths:
7-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
8-
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
9-
- 'UnityProject/Assets/Tests/**'
10-
- '.github/workflows/**'
7+
# Path filtering moved to job level using dorny/paths-filter
8+
# This ensures the workflow always runs and reports a status
119

1210
# Ensure only one test run per PR at a time
1311
concurrency:
@@ -20,19 +18,47 @@ permissions:
2018
statuses: write
2119

2220
jobs:
21+
changes:
22+
name: Detect Changes
23+
runs-on: ubuntu-latest
24+
outputs:
25+
should_test: ${{ steps.filter.outputs.src }}
26+
steps:
27+
- uses: actions/checkout@v4
28+
- uses: dorny/paths-filter@v3
29+
id: filter
30+
with:
31+
filters: |
32+
src:
33+
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.core/**'
34+
- 'UnityProject/Packages/com.jasonxudeveloper.jengine.util/**'
35+
- 'UnityProject/Assets/Tests/**'
36+
- '.github/workflows/**'
37+
2338
run-tests:
2439
name: Run Unity Tests
40+
needs: changes
41+
if: needs.changes.outputs.should_test == 'true'
2542
permissions:
2643
contents: read
2744
checks: write
2845
uses: ./.github/workflows/unity-tests.yml
2946
secrets: inherit
3047

48+
skip-tests:
49+
name: Run Unity Tests
50+
needs: changes
51+
if: needs.changes.outputs.should_test == 'false'
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Skip tests
55+
run: echo "No relevant changes detected, skipping tests"
56+
3157
comment-results:
3258
name: Comment Test Results
33-
needs: run-tests
59+
needs: [changes, run-tests, skip-tests]
3460
runs-on: ubuntu-latest
35-
if: always()
61+
if: always() && needs.changes.outputs.should_test == 'true'
3662
permissions:
3763
pull-requests: write
3864
statuses: write

0 commit comments

Comments
 (0)