Skip to content

Commit a2e3f00

Browse files
authored
test lookup only (#57)
* test lookup only
1 parent f3eb2c0 commit a2e3f00

5 files changed

Lines changed: 162 additions & 39 deletions

File tree

.github/workflows/build.yaml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
build:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest]
14+
fail-fast: false
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Setup Node.js
20+
uses: actions/setup-node@v4
21+
with:
22+
node-version: "20.x"
23+
- name: Install Yarn
24+
run: npm install -g yarn
25+
- name: Get yarn cache directory path
26+
id: yarn-cache-dir-path
27+
run: echo "::set-output name=dir::$(yarn cache dir)"
28+
- uses: actions/cache@v3
29+
id: yarn-cache
30+
with:
31+
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
32+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
33+
restore-keys: |
34+
${{ runner.os }}-yarn-
35+
- name: Install Deps
36+
run: yarn install --pure-lockfile
37+
# - name: Build & Test
38+
# run: yarn test
39+
- name: Ensure dist/ folder is up-to-date
40+
run: |
41+
yarn build
42+
if [ "$(git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then
43+
echo "Detected uncommitted changes after build. See status below:"
44+
git diff
45+
exit 1
46+
fi
47+

.github/workflows/lookup-only.yaml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
name: test-lookup-only
2+
3+
on:
4+
push:
5+
branches: [main]
6+
pull_request:
7+
branches: [main]
8+
9+
jobs:
10+
test-save:
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macOS-latest]
14+
fail-fast: false
15+
runs-on: ${{ matrix.os }}
16+
steps:
17+
- name: Checkout
18+
uses: actions/checkout@v4
19+
- name: Generate files in working directory
20+
shell: bash
21+
run: src/create-cache-files.sh ${{ runner.os }} test-cache
22+
- name: Generate files outside working directory
23+
shell: bash
24+
run: src/create-cache-files.sh ${{ runner.os }} ~/test-cache
25+
- name: Save cache
26+
uses: ./
27+
env:
28+
AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY }}
29+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_KEY }}
30+
AWS_REGION: "us-east-1"
31+
with:
32+
endpoint: ${{ secrets.ENDPOINT }}
33+
bucket: ${{ secrets.BUCKET }}
34+
use-fallback: false
35+
key: test-${{ runner.os }}-${{ github.run_id }}
36+
path: |
37+
test-cache
38+
~/test-cache
39+
40+
test-lookup-only:
41+
needs: test-save
42+
strategy:
43+
matrix:
44+
os: [ubuntu-latest, windows-latest, macOS-latest]
45+
fail-fast: false
46+
runs-on: ${{ matrix.os }}
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
- name: Lookup cache
51+
id: lookup
52+
uses: ./
53+
env:
54+
AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY }}
55+
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_KEY }}
56+
# AWS_SESSION_TOKEN: "xxx"
57+
AWS_REGION: "us-east-1"
58+
with:
59+
endpoint: ${{ secrets.ENDPOINT }}
60+
bucket: ${{ secrets.BUCKET }}
61+
key: test-${{ runner.os }}-${{ github.run_id }}
62+
lookup-only: true
63+
path: |
64+
test-cache
65+
~/test-cache
66+
- name: verify cache hit
67+
env:
68+
CACHE_HIT: ${{ steps.lookup.outputs.cache-hit }}
69+
CACHE_SIZE: ${{ steps.lookup.outputs.cache-size }}
70+
shell: bash
71+
run: |
72+
echo "CACHE_HIT $CACHE_HIT"
73+
echo "CACHE_SIZE $CACHE_SIZE"
74+
ls -R ~/test-cache || true
75+
ls -R test-cache || true
76+
src/create-cache-files.sh ${{ runner.os }} test-cache check_not_exist

.github/workflows/test.yml

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,44 +7,6 @@ on:
77
branches: [main]
88

99
jobs:
10-
build:
11-
strategy:
12-
matrix:
13-
os: [ubuntu-latest]
14-
fail-fast: false
15-
runs-on: ${{ matrix.os }}
16-
steps:
17-
- name: Checkout
18-
uses: actions/checkout@v4
19-
- name: Setup Node.js
20-
uses: actions/setup-node@v4
21-
with:
22-
node-version: "20.x"
23-
- name: Install Yarn
24-
run: npm install -g yarn
25-
- name: Get yarn cache directory path
26-
id: yarn-cache-dir-path
27-
run: echo "::set-output name=dir::$(yarn cache dir)"
28-
- uses: actions/cache@v3
29-
id: yarn-cache
30-
with:
31-
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
32-
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
33-
restore-keys: |
34-
${{ runner.os }}-yarn-
35-
- name: Install Deps
36-
run: yarn install --pure-lockfile
37-
# - name: Build & Test
38-
# run: yarn test
39-
- name: Ensure dist/ folder is up-to-date
40-
run: |
41-
yarn build
42-
if [ "$(git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then
43-
echo "Detected uncommitted changes after build. See status below:"
44-
git diff
45-
exit 1
46-
fi
47-
4810
test-save:
4911
strategy:
5012
matrix:
@@ -120,7 +82,7 @@ jobs:
12082
secretKey: ${{ secrets.SECRET_KEY }}
12183
bucket: ${{ secrets.BUCKET }}
12284
use-fallback: false
123-
key: test-${{ runner.os }}-${{ github.run_id }}-${{ github.sha }}
85+
key: test-${{ runner.os }}-${{ github.run_id }}
12486
path: |
12587
test-cache
12688
~/test-cache

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,31 @@ To restore from the cache only:
8686
node_modules
8787
```
8888

89+
To check if cache hits and size is not zero:
90+
91+
```yaml
92+
- name: Check cache
93+
id: cache
94+
uses: tespkg/actions-cache/check@v1
95+
with:
96+
accessKey: "Q3AM3UQ867SPQQA43P2F" # required
97+
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" # required
98+
bucket: actions-cache # required
99+
lookup-only: true
100+
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
101+
path: |
102+
node_modules
103+
104+
- name: verify cache hit
105+
env:
106+
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
107+
CACHE_SIZE: ${{ steps.cache.outputs.cache-size }}
108+
run: |
109+
echo "CACHE_HIT $CACHE_HIT"
110+
echo "CACHE_SIZE $CACHE_SIZE"
111+
```
112+
113+
89114
## Restore keys
90115

91116
`restore-keys` works similar to how github's `@actions/cache@v2` works: It search each item in `restore-keys`

src/verify-cache-files.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,20 @@ if [ -z "$GITHUB_RUN_ID" ]; then
2020
fi
2121

2222
# Verify file exists
23+
check_not_exists="$3"
2324
file="$path/test-file.txt"
25+
26+
if [ -n "$check_not_exists" ]; then
27+
echo "CACHE_HIT $CACHE_HIT"
28+
echo "CACHE_SIZE $CACHE_SIZE"
29+
echo "Checking for $file to not exist"
30+
if [ -e $file ]; then
31+
echo "File exists when it should not"
32+
exit 1
33+
fi
34+
exit 0
35+
fi
36+
2437
echo "Checking for $file"
2538
if [ ! -e $file ]; then
2639
echo "File does not exist"

0 commit comments

Comments
 (0)