Skip to content

Commit 10bec97

Browse files
CI: use cache
1 parent e370ced commit 10bec97

35 files changed

Lines changed: 1790 additions & 1072 deletions

.env

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22
# This is disabled for existing workspaces to maintain compatibility
33
# For more info, see: https://nx.dev/concepts/inferred-tasks
44
NX_ADD_PLUGINS=false
5-
NX_SKIP_NX_CACHE=true

.github/_rekey_nx_cache.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
#!/usr/bin/env python3
2+
"""Re-key nx GitHub Actions cache for cross-workflow restore.
3+
4+
SAVE key: move ${{ github.sha }} to the front (right after 'nx-v2-') so sha
5+
becomes a restore prefix; keep workflow/job/matrix + run_attempt so each job
6+
still writes a UNIQUE entry (no save collisions, nothing overwritten).
7+
8+
RESTORE keys: prefix every existing scoped key with the sha, and add a new
9+
'...-nx-v2-<sha>-' tier (any job/workflow at this sha) before the broad
10+
'...-nx-v2-' fallback. Result per step:
11+
...-nx-v2-<sha>-<workflow>-<job>[-<matrix>]- own job, same sha (reruns)
12+
...-nx-v2-<sha>- any job/workflow, same sha
13+
...-nx-v2- any nx cache (cross-commit)
14+
Idempotent.
15+
"""
16+
import glob
17+
18+
FILES = sorted(set(glob.glob('.github/workflows/*.yml'))) + \
19+
['.github/actions/run-qunit-tests/action.yml']
20+
21+
RUNNER = '${{ runner.os }}'
22+
SHA = '${{ github.sha }}'
23+
ATTEMPT = '${{ github.run_attempt }}'
24+
PREFIX = RUNNER + '-nx-v2-'
25+
KEY_TAIL = '-' + SHA + '-' + ATTEMPT
26+
27+
28+
def transform(path):
29+
with open(path) as f:
30+
lines = f.readlines()
31+
out = []
32+
changed = False
33+
for line in lines:
34+
nl = '\n' if line.endswith('\n') else ''
35+
bare = line[:-1] if nl else line
36+
indent = bare[:len(bare) - len(bare.lstrip(' '))]
37+
stripped = bare.strip()
38+
39+
# KEY line: key: ${{ runner.os }}-nx-v2-<MIDDLE>-${{ github.sha }}-${{ github.run_attempt }}
40+
if stripped.startswith('key:'):
41+
val = stripped[len('key:'):].strip()
42+
if val.startswith(PREFIX) and val.endswith(KEY_TAIL):
43+
middle = val[len(PREFIX):-len(KEY_TAIL)]
44+
out.append(indent + 'key: ' + PREFIX + SHA + '-' + middle + '-' + ATTEMPT + nl)
45+
changed = True
46+
continue
47+
out.append(line)
48+
continue
49+
50+
# broad fallback restore-key: exactly ${{ runner.os }}-nx-v2-
51+
if stripped == PREFIX:
52+
same_sha = indent + PREFIX + SHA + '-'
53+
if not (out and out[-1].rstrip('\n') == same_sha):
54+
out.append(same_sha + nl)
55+
changed = True
56+
out.append(line)
57+
continue
58+
59+
# scoped restore-key: ${{ runner.os }}-nx-v2-<non-empty>-
60+
if stripped.startswith(PREFIX) and stripped.endswith('-'):
61+
rest = stripped[len(PREFIX):]
62+
if rest.startswith(SHA + '-'): # already has sha (idempotent)
63+
out.append(line)
64+
continue
65+
out.append(indent + PREFIX + SHA + '-' + rest + nl)
66+
changed = True
67+
continue
68+
69+
out.append(line)
70+
71+
if changed:
72+
with open(path, 'w') as f:
73+
f.writelines(out)
74+
return changed
75+
76+
77+
for path in FILES:
78+
if transform(path):
79+
print('rekeyed:', path)

.github/actions/run-qunit-tests/action.yml

Lines changed: 47 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,17 +69,61 @@ runs:
6969
- uses: actions/cache@v5
7070
name: Setup pnpm cache
7171
with:
72-
path: |
73-
${{ env.STORE_PATH }}
74-
.nx/cache
72+
path: ${{ env.STORE_PATH }}
7573
key: ${{ runner.os }}-pnpm-cache-${{ hashFiles('**/pnpm-lock.yaml') }}
7674
restore-keys: |
7775
${{ runner.os }}-pnpm-cache
7876
77+
- name: Lookup nx cache
78+
id: lookup-nx-cache
79+
uses: actions/cache/restore@v5
80+
with:
81+
path: |
82+
.nx/cache
83+
.nx/workspace-data/*.db
84+
.nx/workspace-data/*.db-wal
85+
.nx/workspace-data/*.db-shm
86+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
87+
restore-keys: |
88+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
89+
${{ runner.os }}-nx-v2-${{ github.sha }}-
90+
${{ runner.os }}-nx-v2-
91+
92+
lookup-only: true
93+
94+
- name: Show nx cache status
95+
shell: bash
96+
run: |
97+
echo "Nx cache lookup exact hit: ${{ steps.lookup-nx-cache.outputs.cache-hit }}"
98+
echo "Nx cache primary key: ${{ steps.lookup-nx-cache.outputs.cache-primary-key }}"
99+
echo "Nx cache matched key: ${{ steps.lookup-nx-cache.outputs.cache-matched-key }}"
100+
if [ -z "${{ steps.lookup-nx-cache.outputs.cache-matched-key }}" ]; then
101+
echo "Nx cache lookup: miss"
102+
elif [ "${{ steps.lookup-nx-cache.outputs.cache-hit }}" = "true" ]; then
103+
echo "Nx cache lookup: exact hit"
104+
else
105+
echo "Nx cache lookup: partial hit via restore-keys"
106+
fi
107+
79108
- name: Install dependencies
80109
shell: bash
81110
run: pnpm install --frozen-lockfile
82111

112+
- name: Setup nx cache
113+
id: setup-nx-cache
114+
uses: actions/cache@v5
115+
with:
116+
path: |
117+
.nx/cache
118+
.nx/workspace-data/*.db
119+
.nx/workspace-data/*.db-wal
120+
.nx/workspace-data/*.db-shm
121+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
122+
restore-keys: |
123+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
124+
${{ runner.os }}-nx-v2-${{ github.sha }}-
125+
${{ runner.os }}-nx-v2-
126+
83127
- name: Run QUnit tests
84128
working-directory: ./packages/devextreme
85129
shell: bash

.github/workflows/build_all.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ on:
1313
default: false
1414
type: boolean
1515

16+
concurrency:
17+
group: wf-${{github.event.pull_request.number || github.ref || github.sha}}-${{github.workflow}}
18+
cancel-in-progress: true
19+
1620
env:
1721
NX_SKIP_NX_CACHE: ${{ contains(github.event.pull_request.labels.*.name, 'skip-cache') && 'true' || 'false' }}
1822

@@ -46,9 +50,55 @@ jobs:
4650
restore-keys: |
4751
${{ runner.os }}-pnpm-cache
4852
53+
- name: Lookup nx cache
54+
id: lookup-nx-cache
55+
uses: actions/cache/restore@v5
56+
with:
57+
path: |
58+
.nx/cache
59+
.nx/workspace-data/*.db
60+
.nx/workspace-data/*.db-wal
61+
.nx/workspace-data/*.db-shm
62+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
63+
restore-keys: |
64+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
65+
${{ runner.os }}-nx-v2-${{ github.sha }}-
66+
${{ runner.os }}-nx-v2-
67+
68+
lookup-only: true
69+
70+
- name: Show nx cache status
71+
shell: bash
72+
run: |
73+
echo "Nx cache lookup exact hit: ${{ steps.lookup-nx-cache.outputs.cache-hit }}"
74+
echo "Nx cache primary key: ${{ steps.lookup-nx-cache.outputs.cache-primary-key }}"
75+
echo "Nx cache matched key: ${{ steps.lookup-nx-cache.outputs.cache-matched-key }}"
76+
if [ -z "${{ steps.lookup-nx-cache.outputs.cache-matched-key }}" ]; then
77+
echo "Nx cache lookup: miss"
78+
elif [ "${{ steps.lookup-nx-cache.outputs.cache-hit }}" = "true" ]; then
79+
echo "Nx cache lookup: exact hit"
80+
else
81+
echo "Nx cache lookup: partial hit via restore-keys"
82+
fi
83+
4984
- name: Install dependencies
5085
run: pnpm install --frozen-lockfile
5186

87+
- name: Setup nx cache
88+
id: setup-nx-cache
89+
uses: actions/cache@v5
90+
with:
91+
path: |
92+
.nx/cache
93+
.nx/workspace-data/*.db
94+
.nx/workspace-data/*.db-wal
95+
.nx/workspace-data/*.db-shm
96+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
97+
restore-keys: |
98+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
99+
${{ runner.os }}-nx-v2-${{ github.sha }}-
100+
${{ runner.os }}-nx-v2-
101+
52102
- name: Build npm packages
53103
run: pnpm run all:build
54104

.github/workflows/default_workflow.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,55 @@ jobs:
4545
restore-keys: |
4646
${{ runner.os }}-pnpm-cache
4747
48+
- name: Lookup nx cache
49+
id: lookup-nx-cache
50+
uses: actions/cache/restore@v5
51+
with:
52+
path: |
53+
.nx/cache
54+
.nx/workspace-data/*.db
55+
.nx/workspace-data/*.db-wal
56+
.nx/workspace-data/*.db-shm
57+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
58+
restore-keys: |
59+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
60+
${{ runner.os }}-nx-v2-${{ github.sha }}-
61+
${{ runner.os }}-nx-v2-
62+
63+
lookup-only: true
64+
65+
- name: Show nx cache status
66+
shell: bash
67+
run: |
68+
echo "Nx cache lookup exact hit: ${{ steps.lookup-nx-cache.outputs.cache-hit }}"
69+
echo "Nx cache primary key: ${{ steps.lookup-nx-cache.outputs.cache-primary-key }}"
70+
echo "Nx cache matched key: ${{ steps.lookup-nx-cache.outputs.cache-matched-key }}"
71+
if [ -z "${{ steps.lookup-nx-cache.outputs.cache-matched-key }}" ]; then
72+
echo "Nx cache lookup: miss"
73+
elif [ "${{ steps.lookup-nx-cache.outputs.cache-hit }}" = "true" ]; then
74+
echo "Nx cache lookup: exact hit"
75+
else
76+
echo "Nx cache lookup: partial hit via restore-keys"
77+
fi
78+
4879
- name: Install dependencies
4980
run: pnpm install --frozen-lockfile
5081

82+
- name: Setup nx cache
83+
id: setup-nx-cache
84+
uses: actions/cache@v5
85+
with:
86+
path: |
87+
.nx/cache
88+
.nx/workspace-data/*.db
89+
.nx/workspace-data/*.db-wal
90+
.nx/workspace-data/*.db-shm
91+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
92+
restore-keys: |
93+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
94+
${{ runner.os }}-nx-v2-${{ github.sha }}-
95+
${{ runner.os }}-nx-v2-
96+
5197
- name: Run targets
5298
run: >
5399
pnpm exec nx run-many

.github/workflows/demos_unit_tests.yml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,55 @@ jobs:
5959
restore-keys: |
6060
${{ runner.os }}-pnpm-cache
6161
62+
- name: Lookup nx cache
63+
id: lookup-nx-cache
64+
uses: actions/cache/restore@v5
65+
with:
66+
path: |
67+
.nx/cache
68+
.nx/workspace-data/*.db
69+
.nx/workspace-data/*.db-wal
70+
.nx/workspace-data/*.db-shm
71+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
72+
restore-keys: |
73+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
74+
${{ runner.os }}-nx-v2-${{ github.sha }}-
75+
${{ runner.os }}-nx-v2-
76+
77+
lookup-only: true
78+
79+
- name: Show nx cache status
80+
shell: bash
81+
run: |
82+
echo "Nx cache lookup exact hit: ${{ steps.lookup-nx-cache.outputs.cache-hit }}"
83+
echo "Nx cache primary key: ${{ steps.lookup-nx-cache.outputs.cache-primary-key }}"
84+
echo "Nx cache matched key: ${{ steps.lookup-nx-cache.outputs.cache-matched-key }}"
85+
if [ -z "${{ steps.lookup-nx-cache.outputs.cache-matched-key }}" ]; then
86+
echo "Nx cache lookup: miss"
87+
elif [ "${{ steps.lookup-nx-cache.outputs.cache-hit }}" = "true" ]; then
88+
echo "Nx cache lookup: exact hit"
89+
else
90+
echo "Nx cache lookup: partial hit via restore-keys"
91+
fi
92+
6293
- name: Install dependencies
6394
run: pnpm install --frozen-lockfile
6495

96+
- name: Setup nx cache
97+
id: setup-nx-cache
98+
uses: actions/cache@v5
99+
with:
100+
path: |
101+
.nx/cache
102+
.nx/workspace-data/*.db
103+
.nx/workspace-data/*.db-wal
104+
.nx/workspace-data/*.db-shm
105+
key: ${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-${{ github.run_attempt }}
106+
restore-keys: |
107+
${{ runner.os }}-nx-v2-${{ github.sha }}-${{ github.workflow }}-${{ github.job }}-
108+
${{ runner.os }}-nx-v2-${{ github.sha }}-
109+
${{ runner.os }}-nx-v2-
110+
65111
- name: Run unit tests
66112
working-directory: apps/demos
67113
run: pnpm exec nx test

0 commit comments

Comments
 (0)