88
99on :
1010 pull_request :
11+ paths :
12+ - " formal-spec/**"
13+ - " simulation/**"
14+ - " sim-rs/**"
15+ - " data/**"
16+ - " site/**"
17+ - " docs/**"
1118 push :
1219 branches :
1320 - main
21+ paths :
22+ - " formal-spec/**"
23+ - " simulation/**"
24+ - " sim-rs/**"
25+ - " data/**"
26+ - " site/**"
27+ - " docs/**"
1428
1529jobs :
1630 # ###############################################################################
1731 # Formal Specification in Agda - under /formal-spec/
1832 # ###############################################################################
19-
2033 formal-spec-typecheck :
2134 name : " formal-spec: Typecheck"
35+ if : |
36+ github.event_name == 'push' ||
37+ contains(github.event.pull_request.files.*.path, 'formal-spec/')
2238 runs-on : ubuntu-22.04
2339 steps :
2440 - name : 📥 Checkout repository
6177
6278 simulation-test :
6379 name : " simulation: Test on ${{ matrix.os }} with GHC ${{ matrix.ghc-version }}"
80+ if : |
81+ github.event_name == 'push' ||
82+ contains(github.event.pull_request.files.*.path, 'simulation/') ||
83+ contains(github.event.pull_request.files.*.path, 'data/')
6484 runs-on : ${{ matrix.os }}
6585 strategy :
6686 fail-fast : false
@@ -127,6 +147,10 @@ jobs:
127147
128148 simulation-hlint :
129149 name : " simulation: Check with HLint"
150+ if : |
151+ github.event_name == 'push' ||
152+ contains(github.event.pull_request.files.*.path, 'simulation/') ||
153+ contains(github.event.pull_request.files.*.path, 'data/')
130154 runs-on : ubuntu-22.04
131155 steps :
132156 - name : 📥 Checkout repository
@@ -143,6 +167,10 @@ jobs:
143167
144168 simulation-fourmolu :
145169 name : " simulation: Check with fourmolu"
170+ if : |
171+ github.event_name == 'push' ||
172+ contains(github.event.pull_request.files.*.path, 'simulation/') ||
173+ contains(github.event.pull_request.files.*.path, 'data/')
146174 runs-on : ubuntu-22.04
147175 steps :
148176 - name : 📥 Checkout repository
@@ -159,6 +187,10 @@ jobs:
159187
160188 sim-rs-check :
161189 name : " sim-rs: Test"
190+ if : |
191+ github.event_name == 'push' ||
192+ contains(github.event.pull_request.files.*.path, 'sim-rs/') ||
193+ contains(github.event.pull_request.files.*.path, 'data/')
162194 runs-on : ubuntu-22.04
163195 steps :
164196 - uses : actions/checkout@v4
@@ -177,6 +209,9 @@ jobs:
177209
178210 docs-generate-d2-diagrams :
179211 name : " docs: Generate D2 Diagrams"
212+ if : |
213+ github.event_name == 'push' ||
214+ endsWith(github.event.pull_request.files.*.path, '.d2')
180215 runs-on : ubuntu-22.04
181216 permissions :
182217 contents : write
@@ -185,21 +220,34 @@ jobs:
185220 uses : actions/checkout@v4
186221 with :
187222 ref : ${{ github.head_ref || github.ref_name }}
223+ fetch-depth : 2 # Needed to get previous commit for comparison
188224
189225 - name : Install D2
190226 run : |
191227 curl -fsSL https://d2lang.com/install.sh | sh -s --
192228 d2 --version
193229
194- - name : Generate PNG files
230+ - name : Generate PNG files for changed D2 files
195231 run : |
196- find . -name "*.d2" -type f -exec sh -c '
197- for file do
232+ # Get list of changed .d2 files
233+ CHANGED_FILES=$(git diff --name-only HEAD^ HEAD | grep '\.d2$' || true)
234+
235+ if [ -z "$CHANGED_FILES" ]; then
236+ echo "No .d2 files were changed"
237+ exit 0
238+ fi
239+
240+ echo "Changed .d2 files:"
241+ echo "$CHANGED_FILES"
242+
243+ # Process each changed file
244+ echo "$CHANGED_FILES" | while read -r file; do
245+ if [ -f "$file" ]; then
198246 output_file="${file%.d2}.png"
199247 echo "Converting $file to $output_file"
200248 d2 "$file" "$output_file"
201- done
202- ' sh {} +
249+ fi
250+ done
203251
204252 - name : Check for changes
205253 id : changes
@@ -223,28 +271,52 @@ jobs:
223271
224272 docs-build :
225273 name : " docs: Build"
274+ if : |
275+ github.event_name == 'push' ||
276+ contains(github.event.pull_request.files.*.path, 'site/')
226277 runs-on : ubuntu-22.04
278+ outputs :
279+ has_changes : ${{ steps.check_changes.outputs.has_changes }}
227280 steps :
228281 - name : 📥 Checkout repository
229282 uses : actions/checkout@v4
283+ with :
284+ fetch-depth : 2
285+
286+ - name : Check for site changes
287+ id : check_changes
288+ run : |
289+ SITE_CHANGES=$(git diff --name-only HEAD^ HEAD -- site/ || true)
290+ if [ -z "$SITE_CHANGES" ]; then
291+ echo "No changes in site directory"
292+ echo "has_changes=false" >> $GITHUB_OUTPUT
293+ else
294+ echo "Changes detected in site directory:"
295+ echo "$SITE_CHANGES"
296+ echo "has_changes=true" >> $GITHUB_OUTPUT
297+ fi
230298
231299 - name : 🛠️ Setup Node.js
300+ if : steps.check_changes.outputs.has_changes == 'true'
232301 uses : actions/setup-node@v4
233302 with :
234303 node-version : 20
235304 cache : " yarn"
236305 cache-dependency-path : site/yarn.lock
237306
238307 - name : 📦 Install dependencies
308+ if : steps.check_changes.outputs.has_changes == 'true'
239309 working-directory : site
240310 run : yarn install
241311
242312 - name : 🏗️ Build Docusaurus site
313+ if : steps.check_changes.outputs.has_changes == 'true'
243314 working-directory : site
244315 run : |
245316 yarn build
246317
247318 - name : 🚀 Publish Docusaurus build
319+ if : steps.check_changes.outputs.has_changes == 'true'
248320 uses : actions/upload-artifact@v4
249321 with :
250322 name : docusaurus-build
@@ -254,7 +326,9 @@ jobs:
254326
255327 docs-publish :
256328 name : " docs: Publish"
257- if : github.event_name == 'push' && github.ref == 'refs/heads/main'
329+ if : |
330+ github.ref == 'refs/heads/main' &&
331+ needs.docs-build.outputs.has_changes == 'true'
258332 runs-on : ubuntu-22.04
259333 needs : docs-build
260334 steps :
0 commit comments