Skip to content

Commit 34803e7

Browse files
Merge branch 'main' of github.com:JamesonRGrieve/Workflows into james
2 parents 9b09b7a + 6ea4c68 commit 34803e7

1 file changed

Lines changed: 24 additions & 11 deletions

File tree

.github/workflows/run-branch-test.yml

Lines changed: 24 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ on:
2222
required: false
2323
type: string
2424
default: ""
25+
use_target_cache:
26+
description: "Whether to use caching for target branch test results. When false, always runs fresh tests."
27+
required: false
28+
type: boolean
29+
default: false
2530
secrets:
2631
DISCORD_WEBHOOK_URL:
2732
required: false
@@ -93,6 +98,7 @@ jobs:
9398
# Define cache keys
9499
- name: Set cache keys
95100
id: cache-keys
101+
if: inputs.use_target_cache
96102
run: |
97103
# Version bump forces cache invalidation when extraction logic changes
98104
CACHE_VERSION="v4"
@@ -104,6 +110,7 @@ jobs:
104110
# Try to restore complete results first
105111
- name: Check for complete cache
106112
id: cache-complete
113+
if: inputs.use_target_cache
107114
uses: actions/cache/restore@v4
108115
with:
109116
path: cached_target
@@ -112,7 +119,7 @@ jobs:
112119
# If no complete cache, check for any pending cache (someone else is running)
113120
- name: Check for pending cache
114121
id: cache-pending
115-
if: steps.cache-complete.outputs.cache-hit != 'true'
122+
if: inputs.use_target_cache && steps.cache-complete.outputs.cache-hit != 'true'
116123
uses: actions/cache/restore@v4
117124
with:
118125
path: cached_pending
@@ -123,7 +130,10 @@ jobs:
123130
- name: Determine initial status
124131
id: initial-status
125132
run: |
126-
if [ "${{ steps.cache-complete.outputs.cache-hit }}" == "true" ]; then
133+
if [ "${{ inputs.use_target_cache }}" != "true" ]; then
134+
echo "status=disabled" >> $GITHUB_OUTPUT
135+
echo "🔄 Cache disabled - will run fresh tests"
136+
elif [ "${{ steps.cache-complete.outputs.cache-hit }}" == "true" ]; then
127137
echo "status=complete" >> $GITHUB_OUTPUT
128138
echo "✅ Found complete cache - will use it"
129139
elif [ "${{ steps.cache-pending.outputs.cache-hit }}" == "true" ]; then
@@ -136,15 +146,15 @@ jobs:
136146
137147
# If cache miss, immediately save a pending marker so others know to wait
138148
- name: Create pending marker
139-
if: steps.initial-status.outputs.status == 'miss'
149+
if: inputs.use_target_cache && steps.initial-status.outputs.status == 'miss'
140150
run: |
141151
mkdir -p cached_pending_marker
142152
echo "pending" > cached_pending_marker/status
143153
echo "started=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> cached_pending_marker/status
144154
echo "run_id=${{ github.run_id }}" >> cached_pending_marker/status
145155
146156
- name: Save pending marker
147-
if: steps.initial-status.outputs.status == 'miss'
157+
if: inputs.use_target_cache && steps.initial-status.outputs.status == 'miss'
148158
uses: actions/cache/save@v4
149159
with:
150160
path: cached_pending_marker
@@ -153,7 +163,7 @@ jobs:
153163
# If pending found, poll for complete cache with exponential backoff
154164
- name: Poll for complete cache
155165
id: poll-cache
156-
if: steps.initial-status.outputs.status == 'pending'
166+
if: inputs.use_target_cache && steps.initial-status.outputs.status == 'pending'
157167
env:
158168
GH_TOKEN: ${{ github.token }}
159169
run: |
@@ -191,7 +201,7 @@ jobs:
191201
# Restore complete cache after polling found it
192202
- name: Restore cache after poll
193203
id: cache-after-poll
194-
if: steps.poll-cache.outputs.found == 'true'
204+
if: inputs.use_target_cache && steps.poll-cache.outputs.found == 'true'
195205
uses: actions/cache/restore@v4
196206
with:
197207
path: cached_target
@@ -200,7 +210,10 @@ jobs:
200210
- name: Determine final status
201211
id: final-status
202212
run: |
203-
if [ "${{ steps.cache-complete.outputs.cache-hit }}" == "true" ]; then
213+
if [ "${{ inputs.use_target_cache }}" != "true" ]; then
214+
echo "cache_hit=false" >> $GITHUB_OUTPUT
215+
echo "🔄 Cache disabled - running fresh tests"
216+
elif [ "${{ steps.cache-complete.outputs.cache-hit }}" == "true" ]; then
204217
echo "cache_hit=true" >> $GITHUB_OUTPUT
205218
echo "✅ Using complete cache (found immediately)"
206219
elif [ "${{ steps.cache-after-poll.outputs.cache-hit }}" == "true" ]; then
@@ -213,15 +226,15 @@ jobs:
213226
214227
- name: Load cached results
215228
id: load-cache
216-
if: steps.final-status.outputs.cache_hit == 'true'
229+
if: inputs.use_target_cache && steps.final-status.outputs.cache_hit == 'true'
217230
run: |
218231
echo "✅ Loading cached target results (skipping test run)"
219232
if [ -f cached_target/outputs.env ]; then
220233
cat cached_target/outputs.env >> $GITHUB_OUTPUT
221234
fi
222235
223236
- name: Upload cached artifact
224-
if: steps.final-status.outputs.cache_hit == 'true'
237+
if: inputs.use_target_cache && steps.final-status.outputs.cache_hit == 'true'
225238
uses: actions/upload-artifact@v4
226239
with:
227240
name: pytest_target_${{ github.event.pull_request.number || github.run_id }}
@@ -462,7 +475,7 @@ jobs:
462475
"
463476
464477
- name: Save results to cache
465-
if: steps.final-status.outputs.cache_hit != 'true'
478+
if: inputs.use_target_cache && steps.final-status.outputs.cache_hit != 'true'
466479
run: |
467480
echo "💾 Saving results to cache..."
468481
mkdir -p cached_target
@@ -497,7 +510,7 @@ jobs:
497510
498511
# Save complete results so other PRs can find it
499512
- name: Upload to cache
500-
if: steps.final-status.outputs.cache_hit != 'true'
513+
if: inputs.use_target_cache && steps.final-status.outputs.cache_hit != 'true'
501514
uses: actions/cache/save@v4
502515
with:
503516
path: cached_target

0 commit comments

Comments
 (0)