Skip to content

Commit 0dd6f74

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 0dd6f74

1 file changed

Lines changed: 25 additions & 6 deletions

File tree

.github/workflows/ci.yml

Lines changed: 25 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,30 @@ 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+
echo "$output"
36+
# Check that all build steps (except FROM) have a CACHED line
37+
for step in $(echo "$output" | grep -oE '^#[0-9]+ \[[0-9]+/[0-9]+\]' | grep -v FROM | grep -oE '^#[0-9]+'); do
38+
if ! echo "$output" | grep -q "^${step} CACHED"; then
39+
echo "::error::Step $step was rebuilt instead of using cache"
40+
exit 1
41+
fi
42+
done
43+
if echo "$output" | grep -q "added"; then
44+
echo "::error::Packages were downloaded instead of using cached node_modules"
2645
exit 1
2746
fi

0 commit comments

Comments
 (0)