@@ -56,22 +56,106 @@ jobs:
5656 file-changes :
5757 name : Detect File Changes
5858 runs-on : ' ubuntu-latest'
59- outputs :
59+ outputs :
6060 checkall : ${{ steps.changes.outputs.checkall }}
61+ cases_py : ${{ steps.changes.outputs.cases_py }}
62+ dep_changed : ${{ steps.dep-check.outputs.dep_changed }}
6163 steps :
6264 - name : Clone
6365 uses : actions/checkout@v4
6466
6567 - name : Detect Changes
6668 uses : dorny/paths-filter@v3
6769 id : changes
68- with :
70+ with :
6971 filters : " .github/file-filter.yml"
7072
73+ - name : Check for Fortran dependency changes
74+ id : dep-check
75+ env :
76+ GH_TOKEN : ${{ github.token }}
77+ run : |
78+ # Detect added/removed use/include statements that change the
79+ # Fortran dependency graph, which would make the coverage cache stale.
80+ if [ "${{ github.event_name }}" = "pull_request" ]; then
81+ DIFF=$(gh pr diff ${{ github.event.pull_request.number }})
82+ elif [ "${{ github.event_name }}" = "push" ]; then
83+ DIFF=$(git diff ${{ github.event.before }}..${{ github.event.after }} 2>/dev/null || echo "")
84+ else
85+ DIFF=""
86+ fi
87+ if echo "$DIFF" | \
88+ grep -qP '^\+\s*(use[\s,]+\w|#:include\s|include\s+['"'"'"])'; then
89+ echo "dep_changed=true" >> "$GITHUB_OUTPUT"
90+ echo "Fortran dependency change detected — will rebuild coverage cache."
91+ else
92+ echo "dep_changed=false" >> "$GITHUB_OUTPUT"
93+ fi
94+
95+ rebuild-cache :
96+ name : Rebuild Coverage Cache
97+ needs : [lint-gate, file-changes]
98+ if : >-
99+ github.repository == 'MFlowCode/MFC' &&
100+ (
101+ (github.event_name == 'pull_request' &&
102+ (needs.file-changes.outputs.cases_py == 'true' ||
103+ needs.file-changes.outputs.dep_changed == 'true')) ||
104+ (github.event_name == 'push' &&
105+ (needs.file-changes.outputs.cases_py == 'true' ||
106+ needs.file-changes.outputs.dep_changed == 'true')) ||
107+ github.event_name == 'workflow_dispatch'
108+ )
109+ timeout-minutes : 240
110+ runs-on :
111+ group : phoenix
112+ labels : gt
113+ permissions :
114+ contents : write
115+ steps :
116+ - name : Clone
117+ uses : actions/checkout@v4
118+ with :
119+ ref : ${{ github.event_name == 'pull_request' && github.event.pull_request.head.sha || github.sha }}
120+ clean : false
121+
122+ - name : Rebuild Cache via SLURM
123+ run : bash .github/workflows/phoenix/submit.sh .github/workflows/phoenix/rebuild-cache.sh cpu none
124+
125+ - name : Print Logs
126+ if : always()
127+ run : cat rebuild-cache-cpu-none.out
128+
129+ - name : Upload Cache Artifact
130+ if : github.event_name == 'pull_request'
131+ uses : actions/upload-artifact@v4
132+ with :
133+ name : coverage-cache
134+ path : toolchain/mfc/test/test_coverage_cache.json.gz
135+ retention-days : 1
136+
137+ - name : Commit Cache to Master
138+ if : github.event_name == 'push' || github.event_name == 'workflow_dispatch'
139+ run : |
140+ git config user.name "github-actions[bot]"
141+ git config user.email "github-actions[bot]@users.noreply.github.com"
142+ git add toolchain/mfc/test/test_coverage_cache.json.gz
143+ if git diff --cached --quiet; then
144+ echo "Coverage cache unchanged."
145+ else
146+ git commit -m "Regenerate gcov coverage cache [skip ci]"
147+ git push
148+ fi
149+
71150 github :
72151 name : Github
73- if : needs.file-changes.outputs.checkall == 'true'
74- needs : [lint-gate, file-changes]
152+ needs : [lint-gate, file-changes, rebuild-cache]
153+ if : >-
154+ always() &&
155+ needs.lint-gate.result == 'success' &&
156+ needs.file-changes.result == 'success' &&
157+ needs.rebuild-cache.result != 'cancelled' &&
158+ needs.file-changes.outputs.checkall == 'true'
75159 strategy :
76160 matrix :
77161 os : ['ubuntu', 'macos']
@@ -91,13 +175,26 @@ jobs:
91175 intel : false
92176
93177 fail-fast : false
94- continue-on-error : true
95178 runs-on : ${{ matrix.os }}-latest
96179
97180 steps :
98181 - name : Clone
99182 uses : actions/checkout@v4
100183
184+ - name : Fetch master for coverage diff
185+ run : |
186+ git fetch origin master:master --depth=1
187+ git fetch --deepen=200
188+ continue-on-error : true
189+
190+ - name : Download Coverage Cache
191+ if : needs.rebuild-cache.result == 'success'
192+ uses : actions/download-artifact@v4
193+ with :
194+ name : coverage-cache
195+ path : toolchain/mfc/test
196+ continue-on-error : true
197+
101198 - name : Setup MacOS
102199 if : matrix.os == 'macos'
103200 run : |
@@ -159,7 +256,7 @@ jobs:
159256 run : |
160257 rm -f tests/failed_uuids.txt
161258 TEST_EXIT=0
162- /bin/bash mfc.sh test -v --max-attempts 3 -j "$(nproc)" $TEST_ALL $TEST_PCT || TEST_EXIT=$?
259+ /bin/bash mfc.sh test -v --max-attempts 3 -j "$(nproc)" $ONLY_CHANGES $ TEST_ALL $TEST_PCT || TEST_EXIT=$?
163260
164261 # Retry only if a small number of tests failed (sporadic failures)
165262 if [ -s tests/failed_uuids.txt ]; then
@@ -180,11 +277,19 @@ jobs:
180277 env :
181278 TEST_ALL : ${{ matrix.mpi == 'mpi' && '--test-all' || '' }}
182279 TEST_PCT : ${{ matrix.debug == 'debug' && '-% 20' || '' }}
280+ ONLY_CHANGES : ${{ github.event_name == 'pull_request' && '--only-changes' || '' }}
183281
184282 self :
185283 name : " ${{ matrix.cluster_name }} (${{ matrix.device }}${{ matrix.interface != 'none' && format('-{0}', matrix.interface) || '' }}${{ matrix.shard != '' && format(' [{0}]', matrix.shard) || '' }})"
186- if : github.repository == 'MFlowCode/MFC' && needs.file-changes.outputs.checkall == 'true' && github.event.pull_request.draft != true
187- needs : [lint-gate, file-changes]
284+ needs : [lint-gate, file-changes, rebuild-cache]
285+ if : >-
286+ always() &&
287+ needs.lint-gate.result == 'success' &&
288+ needs.file-changes.result == 'success' &&
289+ needs.rebuild-cache.result != 'cancelled' &&
290+ github.repository == 'MFlowCode/MFC' &&
291+ needs.file-changes.outputs.checkall == 'true' &&
292+ github.event.pull_request.draft != true
188293 continue-on-error : false
189294 timeout-minutes : 480
190295 strategy :
@@ -265,6 +370,14 @@ jobs:
265370 with :
266371 clean : false
267372
373+ - name : Download Coverage Cache
374+ if : needs.rebuild-cache.result == 'success'
375+ uses : actions/download-artifact@v4
376+ with :
377+ name : coverage-cache
378+ path : toolchain/mfc/test
379+ continue-on-error : true
380+
268381 - name : Build
269382 if : matrix.cluster != 'phoenix'
270383 uses : nick-fields/retry@ce71cc2ab81d554ebbe88c79ab5975992d79ba08 # v3
@@ -299,3 +412,4 @@ jobs:
299412 with :
300413 name : logs-${{ strategy.job-index }}-${{ steps.log.outputs.slug }}
301414 path : ${{ steps.log.outputs.slug }}.out
415+
0 commit comments