Skip to content

Commit 3892e52

Browse files
committed
Test that image layers and compose volumes are getting cached
https://ampcode.com/threads/T-019b9de3-53bf-72ff-970b-6e25b1db5b09
1 parent 0c759be commit 3892e52

1 file changed

Lines changed: 28 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
branches: [main]
77

88
jobs:
9-
verify-dist:
9+
setup-and-cache:
1010
runs-on: ubuntu-latest
1111
steps:
1212
- uses: actions/checkout@v4
@@ -17,11 +17,33 @@ jobs:
1717
volumes: |
1818
node_modules: ${{ hashFiles('package-lock.json') }}
1919
- run: bin/setup
20-
- run: bin/npm run build
21-
- name: Check for uncommitted changes
20+
21+
test:
22+
needs: setup-and-cache
23+
runs-on: ubuntu-latest
24+
steps:
25+
- uses: actions/checkout@v4
26+
- uses: docker/setup-buildx-action@v3
27+
- uses: docker/setup-compose-action@v1
28+
- uses: ./
29+
with:
30+
volumes: |
31+
node_modules: ${{ hashFiles('package-lock.json') }}
32+
- name: Verify caches are used
2233
run: |
23-
if [ -n "$(git status --porcelain dist/)" ]; then
24-
echo "::error::dist/ is out of date. Run 'npm run build' and commit the changes."
25-
git diff dist/
34+
output=$(bin/setup 2>&1)
35+
# Check that all build steps (except FROM) have a CACHED line
36+
for step in $(echo "$output" | grep -E '^#[0-9]+ \[[0-9]+/[0-9]+\]' | grep -v FROM | grep -oE '^#[0-9]+'); do
37+
if ! echo "$output" | grep -q "^${step} CACHED"; then
38+
echo "::error::Step $step was rebuilt instead of using cache"
39+
echo "$output"
40+
exit 1
41+
fi
42+
done
43+
echo "All build steps used cache."
44+
if echo "$output" | grep -q "added"; then
45+
echo "::error::Packages were downloaded instead of using cached node_modules"
46+
echo "$output"
2647
exit 1
2748
fi
49+
echo "node_modules cache was used."

0 commit comments

Comments
 (0)