Skip to content

Commit 632289c

Browse files
authored
fix(turbo): try remote caching (freeCodeCamp#65692)
1 parent 72b22ae commit 632289c

File tree

6 files changed

+131
-1
lines changed

6 files changed

+131
-1
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# Caching Behaviour:
2+
# ┌─────────────────────────┬─────────────────┬──────────────────┐
3+
# │ Context │ Can Read Cache? │ Can Write Cache? │
4+
# ├─────────────────────────┼─────────────────┼──────────────────┤
5+
# │ main (push) │ YES │ YES │
6+
# ├─────────────────────────┼─────────────────┼──────────────────┤
7+
# │ renovate/* │ YES │ YES │
8+
# ├─────────────────────────┼─────────────────┼──────────────────┤
9+
# │ PRs / temp-* / hotfix-* │ YES │ NO │
10+
# ├─────────────────────────┼─────────────────┼──────────────────┤
11+
# │ prod-* │ NO │ NO │
12+
# ├─────────────────────────┼─────────────────┼──────────────────┤
13+
# │ Fork PRs │ NO │ NO │
14+
# └─────────────────────────┴─────────────────┴──────────────────┘
15+
16+
name: 'Setup Turbo Remote Cache'
17+
description: 'Conditionally configure Turbo remote cache based on branch and event context'
18+
19+
inputs:
20+
turbo-token:
21+
description: 'Turbo remote cache authentication token'
22+
required: true
23+
turbo-signature-key:
24+
description: 'Turbo remote cache signature key for artifact signing/verification'
25+
required: true
26+
27+
runs:
28+
using: 'composite'
29+
steps:
30+
- name: Configure Turbo Remote Cache
31+
shell: bash
32+
env:
33+
TURBO_TOKEN: ${{ inputs.turbo-token }}
34+
TURBO_SIGNATURE_KEY: ${{ inputs.turbo-signature-key }}
35+
GITHUB_REF_NAME: ${{ github.ref_name }}
36+
GITHUB_EVENT_NAME: ${{ github.event_name }}
37+
GITHUB_BASE_REF: ${{ github.base_ref }}
38+
run: |
39+
echo "::group::Turbo Cache Configuration"
40+
echo "Branch: $GITHUB_REF_NAME"
41+
echo "Event: $GITHUB_EVENT_NAME"
42+
echo "Base ref: $GITHUB_BASE_REF"
43+
44+
# Skip for deployment branches (pure builds)
45+
if [[ "$GITHUB_REF_NAME" == prod-* ]]; then
46+
echo "::notice::Deployment branch detected - Turbo cache DISABLED for pure build"
47+
echo "::endgroup::"
48+
exit 0
49+
fi
50+
51+
# Skip if secrets are not available (fork PRs)
52+
if [[ -z "$TURBO_TOKEN" || -z "$TURBO_SIGNATURE_KEY" ]]; then
53+
echo "::notice::Turbo secrets not available (likely a fork PR) - Turbo cache DISABLED"
54+
echo "::endgroup::"
55+
exit 0
56+
fi
57+
58+
# Base configuration for all other contexts
59+
echo "TURBO_API=https://turbo-cache.freecodecamp.net" >> $GITHUB_ENV
60+
echo "TURBO_TEAM=team_freecodecamp" >> $GITHUB_ENV
61+
echo "TURBO_TOKEN=$TURBO_TOKEN" >> $GITHUB_ENV
62+
echo "TURBO_REMOTE_CACHE_SIGNATURE_KEY=$TURBO_SIGNATURE_KEY" >> $GITHUB_ENV
63+
echo "TURBO_TELEMETRY_DISABLED=1" >> $GITHUB_ENV
64+
65+
# Determine if this context should have write access
66+
# Write access: main branch push OR renovate branches
67+
# Read-only: PRs and other branches (can read from cache, can't pollute it)
68+
if [[ "$GITHUB_REF_NAME" == "main" && "$GITHUB_EVENT_NAME" == "push" ]]; then
69+
echo "::notice::Main branch push - Turbo cache READ/WRITE enabled"
70+
elif [[ "$GITHUB_REF_NAME" == renovate/* ]]; then
71+
echo "::notice::Renovate branch - Turbo cache READ/WRITE enabled"
72+
else
73+
# All other contexts: read-only
74+
# Use TURBO_CACHE=remote:r for read-only remote cache (local still read/write)
75+
echo "TURBO_CACHE=local:rw,remote:r" >> $GITHUB_ENV
76+
echo "::notice::PR/other branch - Turbo cache READ-ONLY enabled"
77+
fi
78+
79+
echo "::endgroup::"

.github/workflows/curriculum-i18n-submodule.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,12 @@ jobs:
4444
with:
4545
run_install: false
4646

47+
- name: Setup Turbo Cache
48+
uses: ./.github/actions/setup-turbo-cache
49+
with:
50+
turbo-token: ${{ secrets.TURBO_TOKEN }}
51+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
52+
4753
- name: Set Environment variables
4854
run: |
4955
cp sample.env .env

.github/workflows/e2e-playwright.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,12 @@ jobs:
4040
with:
4141
run_install: false
4242

43+
- name: Setup Turbo Cache
44+
uses: ./.github/actions/setup-turbo-cache
45+
with:
46+
turbo-token: ${{ secrets.TURBO_TOKEN }}
47+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
48+
4349
- name: Checkout client-config
4450
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
4551
with:

.github/workflows/i18n-validate-builds.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ jobs:
3333
with:
3434
run_install: false
3535

36+
- name: Setup Turbo Cache
37+
uses: ./.github/actions/setup-turbo-cache
38+
with:
39+
turbo-token: ${{ secrets.TURBO_TOKEN }}
40+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
41+
3642
- name: Set freeCodeCamp Environment Variables
3743
run: |
3844
cp sample.env .env

.github/workflows/node.js-tests.yml

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ on:
66
- 'main'
77
- 'prod-**'
88
- 'renovate/**'
9+
- 'hotfix-**'
10+
- 'temp-**'
911
pull_request:
1012
branches:
1113
- 'main'
@@ -54,6 +56,12 @@ jobs:
5456
with:
5557
run_install: false
5658

59+
- name: Setup Turbo Cache
60+
uses: ./.github/actions/setup-turbo-cache
61+
with:
62+
turbo-token: ${{ secrets.TURBO_TOKEN }}
63+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
64+
5765
- name: Set Environment variables
5866
run: |
5967
cp sample.env .env
@@ -100,6 +108,12 @@ jobs:
100108
with:
101109
run_install: false
102110

111+
- name: Setup Turbo Cache
112+
uses: ./.github/actions/setup-turbo-cache
113+
with:
114+
turbo-token: ${{ secrets.TURBO_TOKEN }}
115+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
116+
103117
- name: Set freeCodeCamp Environment Variables
104118
run: |
105119
cp sample.env .env
@@ -136,6 +150,12 @@ jobs:
136150
with:
137151
run_install: false
138152

153+
- name: Setup Turbo Cache
154+
uses: ./.github/actions/setup-turbo-cache
155+
with:
156+
turbo-token: ${{ secrets.TURBO_TOKEN }}
157+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
158+
139159
- name: Set Environment variables
140160
run: |
141161
cp sample.env .env
@@ -182,6 +202,12 @@ jobs:
182202
with:
183203
run_install: false
184204

205+
- name: Setup Turbo Cache
206+
uses: ./.github/actions/setup-turbo-cache
207+
with:
208+
turbo-token: ${{ secrets.TURBO_TOKEN }}
209+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
210+
185211
- name: Set Environment variables
186212
run: |
187213
cp sample.env .env
@@ -231,6 +257,12 @@ jobs:
231257
with:
232258
run_install: false
233259

260+
- name: Setup Turbo Cache
261+
uses: ./.github/actions/setup-turbo-cache
262+
with:
263+
turbo-token: ${{ secrets.TURBO_TOKEN }}
264+
turbo-signature-key: ${{ secrets.TURBO_REMOTE_CACHE_SIGNATURE_KEY }}
265+
234266
- name: Set Environment variables
235267
run: |
236268
cp sample.env .env

turbo.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
"//#lint-root": {
1212
"dependsOn": ["@freecodecamp/shared#build"]
1313
}
14-
}
14+
},
15+
"remoteCache": { "signature": true }
1516
}

0 commit comments

Comments
 (0)