@@ -18,17 +18,32 @@ jobs:
1818 outputs :
1919 matrix : ${{ steps.generate.outputs.matrix }}
2020 examples-count : ${{ steps.generate.outputs.count }}
21+ total-count : ${{ steps.generate.outputs.total-count }}
2122 steps :
2223 - uses : actions/checkout@v4
24+ with :
25+ fetch-depth : 0 # Need full history for git diff
26+
27+ - name : Restore example cache
28+ uses : actions/cache@v4
29+ with :
30+ path : .example-cache
31+ key : examples-cache-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
32+ restore-keys : |
33+ examples-cache-${{ github.head_ref || github.ref_name }}-
34+ examples-cache-main-
2335
2436 - name : Generate matrix
2537 id : generate
2638 run : |
2739 matrix=$(bash .github/scripts/list_examples.sh)
2840 echo "matrix=$matrix" >> $GITHUB_OUTPUT
29- count=$(echo "$matrix" | jq '.example | length')
30- echo "count=$count" >> $GITHUB_OUTPUT
31- echo "Found $count runnable examples"
41+ total_count=$(echo "$matrix" | jq '.include | length')
42+ skipped_count=$(echo "$matrix" | jq '[.include[] | select(.skip == true)] | length')
43+ run_count=$((total_count - skipped_count))
44+ echo "total-count=$total_count" >> $GITHUB_OUTPUT
45+ echo "count=$run_count" >> $GITHUB_OUTPUT
46+ echo "Found $total_count total examples ($run_count to run, $skipped_count cached)"
3247 echo "$matrix" | jq .
3348
3449 # Second job: Run examples in parallel
89104
90105 steps :
91106 - uses : actions/checkout@v4
107+ with :
108+ fetch-depth : 0 # Need full history for git diff
92109
93110 - name : Install uv
94111 uses : astral-sh/setup-uv@v2
@@ -104,7 +121,27 @@ jobs:
104121 restore-keys : |
105122 uv-${{ runner.os }}-
106123
124+ - name : Restore example cache
125+ uses : actions/cache@v4
126+ with :
127+ path : .example-cache
128+ key : examples-cache-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
129+ restore-keys : |
130+ examples-cache-${{ github.head_ref || github.ref_name }}-
131+ examples-cache-main-
132+
133+ - name : Check if example should be skipped
134+ id : check-skip
135+ run : |
136+ if [[ "${{ matrix.skip }}" == "true" ]]; then
137+ echo "skip=true" >> $GITHUB_OUTPUT
138+ echo "✅ Skipping ${{ matrix.example }} (cached from previous successful run)"
139+ else
140+ echo "skip=false" >> $GITHUB_OUTPUT
141+ fi
142+
107143 - name : Pre-install common dependencies
144+ if : steps.check-skip.outputs.skip == 'false'
108145 run : |
109146 # Create a temporary environment with common ragbits packages to cache them
110147 uv venv --python 3.10 .temp-env
@@ -121,6 +158,7 @@ jobs:
121158 rm -rf .temp-env
122159
123160 - name : Run example - ${{ matrix.example }}
161+ if : steps.check-skip.outputs.skip == 'false'
124162 env :
125163 PR_BRANCH : ${{ github.head_ref }}
126164 GOOGLE_CLOUD_PROJECT : ${{ secrets.GCP_PROJECT_ID }}
@@ -135,6 +173,13 @@ jobs:
135173 chmod +x .github/scripts/run_single_example.sh
136174 ./.github/scripts/run_single_example.sh "${{ matrix.example }}"
137175
176+ - name : Save example cache
177+ if : always()
178+ uses : actions/cache/save@v4
179+ with :
180+ path : .example-cache
181+ key : examples-cache-${{ github.head_ref || github.ref_name }}-${{ github.sha }}
182+
138183 # Summary job: Report overall results
139184 examples-summary :
140185 name : Examples summary
@@ -143,10 +188,16 @@ jobs:
143188 if : always()
144189 steps :
145190 - name : Check results
191+ env :
192+ TOTAL_COUNT : ${{ needs.generate-matrix.outputs.total-count }}
193+ RUN_COUNT : ${{ needs.generate-matrix.outputs.examples-count }}
146194 run : |
147195 echo "Examples matrix generation: ${{ needs.generate-matrix.result }}"
148196 echo "Examples execution: ${{ needs.examples.result }}"
149- echo "Total examples: ${{ needs.generate-matrix.outputs.examples-count }}"
197+ echo "Total examples: $TOTAL_COUNT"
198+ echo "Examples run: $RUN_COUNT"
199+ cached_count=$((TOTAL_COUNT - RUN_COUNT))
200+ echo "Examples cached: $cached_count"
150201
151202 if [[ "${{ needs.generate-matrix.result }}" != "success" ]]; then
152203 echo "❌ Failed to generate examples matrix"
@@ -158,4 +209,4 @@ jobs:
158209 exit 1
159210 fi
160211
161- echo "✅ All ${{ needs.generate-matrix.outputs. examples-count }} examples completed successfully"
212+ echo "✅ All examples completed successfully ($RUN_COUNT run, $cached_count cached) "
0 commit comments