Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: build

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Install Yarn
run: npm install -g yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Deps
run: yarn install --pure-lockfile
# - name: Build & Test
# run: yarn test
- name: Ensure dist/ folder is up-to-date
run: |
yarn build
if [ "$(git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi

76 changes: 76 additions & 0 deletions .github/workflows/lookup-only.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
name: test-lookup-only

on:
push:
branches: [main]
pull_request:
branches: [main]

jobs:
test-save:
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Generate files in working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} test-cache
- name: Generate files outside working directory
shell: bash
run: src/create-cache-files.sh ${{ runner.os }} ~/test-cache
- name: Save cache
uses: ./
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_KEY }}
AWS_REGION: "us-east-1"
with:
endpoint: ${{ secrets.ENDPOINT }}
bucket: ${{ secrets.BUCKET }}
use-fallback: false
key: test-${{ runner.os }}-${{ github.run_id }}
path: |
test-cache
~/test-cache

test-lookup-only:
needs: test-save
strategy:
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Lookup cache
id: lookup
uses: ./
env:
AWS_ACCESS_KEY_ID: ${{ secrets.ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.SECRET_KEY }}
# AWS_SESSION_TOKEN: "xxx"
AWS_REGION: "us-east-1"
with:
endpoint: ${{ secrets.ENDPOINT }}
bucket: ${{ secrets.BUCKET }}
key: test-${{ runner.os }}-${{ github.run_id }}
lookup-only: true
path: |
test-cache
~/test-cache
- name: verify cache hit
env:
CACHE_HIT: ${{ steps.lookup.outputs.cache-hit }}
CACHE_SIZE: ${{ steps.lookup.outputs.cache-size }}
shell: bash
run: |
echo "CACHE_HIT $CACHE_HIT"
echo "CACHE_SIZE $CACHE_SIZE"
ls -R ~/test-cache || true
ls -R test-cache || true
src/create-cache-files.sh ${{ runner.os }} test-cache check_not_exist
40 changes: 1 addition & 39 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,44 +7,6 @@ on:
branches: [main]

jobs:
build:
strategy:
matrix:
os: [ubuntu-latest]
fail-fast: false
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20.x"
- name: Install Yarn
run: npm install -g yarn
- name: Get yarn cache directory path
id: yarn-cache-dir-path
run: echo "::set-output name=dir::$(yarn cache dir)"
- uses: actions/cache@v3
id: yarn-cache
with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: |
${{ runner.os }}-yarn-
- name: Install Deps
run: yarn install --pure-lockfile
# - name: Build & Test
# run: yarn test
- name: Ensure dist/ folder is up-to-date
run: |
yarn build
if [ "$(git diff --ignore-space-at-eol | wc -l)" -gt "0" ]; then
echo "Detected uncommitted changes after build. See status below:"
git diff
exit 1
fi

test-save:
strategy:
matrix:
Expand Down Expand Up @@ -120,7 +82,7 @@ jobs:
secretKey: ${{ secrets.SECRET_KEY }}
bucket: ${{ secrets.BUCKET }}
use-fallback: false
key: test-${{ runner.os }}-${{ github.run_id }}-${{ github.sha }}
key: test-${{ runner.os }}-${{ github.run_id }}
path: |
test-cache
~/test-cache
Expand Down
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,31 @@ To restore from the cache only:
node_modules
```

To check if cache hits and size is not zero:

```yaml
- name: Check cache
id: cache
uses: tespkg/actions-cache/check@v1
with:
accessKey: "Q3AM3UQ867SPQQA43P2F" # required
secretKey: "zuf+tfteSlswRu7BJ86wekitnifILbZam1KYY3TG" # required
bucket: actions-cache # required
lookup-only: true
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
path: |
node_modules

- name: verify cache hit
env:
CACHE_HIT: ${{ steps.cache.outputs.cache-hit }}
CACHE_SIZE: ${{ steps.cache.outputs.cache-size }}
run: |
echo "CACHE_HIT $CACHE_HIT"
echo "CACHE_SIZE $CACHE_SIZE"
```


## Restore keys

`restore-keys` works similar to how github's `@actions/cache@v2` works: It search each item in `restore-keys`
Expand Down
13 changes: 13 additions & 0 deletions src/verify-cache-files.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,20 @@ if [ -z "$GITHUB_RUN_ID" ]; then
fi

# Verify file exists
check_not_exists="$3"
file="$path/test-file.txt"

if [ -n "$check_not_exists" ]; then
echo "CACHE_HIT $CACHE_HIT"
echo "CACHE_SIZE $CACHE_SIZE"
echo "Checking for $file to not exist"
if [ -e $file ]; then
echo "File exists when it should not"
exit 1
fi
exit 0
fi

echo "Checking for $file"
if [ ! -e $file ]; then
echo "File does not exist"
Expand Down
Loading