Skip to content

Commit 1440945

Browse files
Try to get Windows to use the cache
1 parent 991d838 commit 1440945

File tree

2 files changed

+43
-23
lines changed

2 files changed

+43
-23
lines changed

.github/workflows/build-and-test.yml

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,40 +14,54 @@ on:
1414
types: [ labeled, opened, synchronize, reopened ]
1515

1616
jobs:
17-
# Warm LFS cache once, generate a stable .lfs-assets-id with LF endings, and save it as an artifact
18-
WarmLfs:
17+
# Warm up LFS cache once, on a single runner, and compute a stable cache key
18+
WarmLFS:
1919
runs-on: ubuntu-latest
20-
steps:
21-
- name: Git Config
22-
shell: bash
23-
run: |
24-
git config --global core.autocrlf false
25-
git config --global core.longpaths true
2620

27-
- name: Git Checkout
28-
uses: actions/checkout@v4
21+
# Expose the computed cache key so matrix jobs can use it
22+
outputs:
23+
lfs_key: ${{ steps.compute-key.outputs.lfs_key }}
24+
25+
steps:
26+
# Checkout repo with full history and submodules so we can see all LFS files
27+
- uses: actions/checkout@v4
2928
with:
3029
fetch-depth: 0
3130
submodules: recursive
3231

33-
# Generate the LFS id list once and normalise to LF so hashFiles() matches across OS
34-
- name: Git Create LFS FileList
32+
# Create a deterministic list of LFS object IDs:
33+
# - `git lfs ls-files -l` lists all tracked LFS objects with their SHA-256
34+
# - `awk '{print $1}'` extracts just the SHA field
35+
# - `sort` sorts in byte order (hex hashes sort the same everywhere)
36+
# This ensures the file content is identical regardless of OS or locale
37+
- name: Git Create LFS id list
3538
shell: bash
36-
run: git lfs ls-files -l | cut -d' ' -f1 | sort | tr -d '\r' > .lfs-assets-id
39+
run: git lfs ls-files -l | awk '{print $1}' | sort > .lfs-assets-id
3740

41+
# Compute a stable cache key by hashing the list file itself.
42+
# This guarantees the same key across all OSes and all matrix jobs.
43+
- name: Git Compute LFS cache key
44+
id: compute-key
45+
shell: bash
46+
run: |
47+
# sha256sum outputs "<hash> <filename>"
48+
KEY_HASH=$(sha256sum .lfs-assets-id | awk '{print $1}')
49+
echo "lfs_key=lfs-${KEY_HASH}-v1" >> "$GITHUB_OUTPUT"
50+
51+
# Restore or populate the cache for .git/lfs using the computed key
3852
- name: Git Setup LFS Cache
3953
uses: actions/cache@v4
40-
id: lfs-cache
4154
with:
4255
path: .git/lfs
43-
key: lfs-${{ hashFiles('.lfs-assets-id') }}-v1
56+
key: ${{ steps.compute-key.outputs.lfs_key }}
4457

58+
# Ensure all LFS files for this commit are present locally
4559
- name: Git Pull LFS
4660
shell: bash
4761
run: git lfs pull
4862

4963
Build:
50-
needs: WarmLfs # Ensure the cache and id file exist before starting the matrix
64+
needs: WarmLFS # Ensure the cache and id file exist before starting the matrix
5165
strategy:
5266
matrix:
5367
isARM:
@@ -124,10 +138,12 @@ jobs:
124138
fetch-depth: 0
125139
submodules: recursive
126140

127-
# Each job restores the now-primed cache, and pulls only if needed
128-
- name: Git Create LFS FileList
129-
shell: bash
130-
run: git lfs ls-files -l | cut -d' ' -f1 | sort | tr -d '\r' > .lfs-assets-id
141+
# Use the *exact same key* computed in WarmLFS to restore the warmed cache.
142+
# This avoids regenerating the key per-OS and ensures all matrix jobs hit the same cache.
143+
- uses: actions/cache@v4
144+
with:
145+
path: .git/lfs
146+
key: ${{ needs.WarmLFS.outputs.lfs_key }}
131147

132148
- name: Git Setup LFS Cache
133149
uses: actions/cache@v4

.github/workflows/code-coverage.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,14 @@ jobs:
3636
fetch-depth: 0
3737
submodules: recursive
3838

39-
# Normalize the LFS id list to LF so the cache key is stable across environments
40-
- name: Git Create LFS FileList
39+
# Create a deterministic list of LFS object IDs:
40+
# - `git lfs ls-files -l` lists all tracked LFS objects with their SHA-256
41+
# - `awk '{print $1}'` extracts just the SHA field
42+
# - `sort` sorts in byte order (hex hashes sort the same everywhere)
43+
# This ensures the file content is identical regardless of OS or locale
44+
- name: Git Create LFS id list
4145
shell: bash
42-
run: git lfs ls-files -l | cut -d' ' -f1 | sort | tr -d '\r' > .lfs-assets-id
46+
run: git lfs ls-files -l | awk '{print $1}' | sort > .lfs-assets-id
4347

4448
- name: Git Setup LFS Cache
4549
uses: actions/cache@v4

0 commit comments

Comments
 (0)