More docs adjusted

pull/1766/head
Boris Staal 3 years ago
parent 1a3e6024cc
commit d43149eba7
No known key found for this signature in database

@ -1 +1,2 @@
* @actions/actions-cache * @justvanilla
* @inossidabile

@ -2,7 +2,7 @@
<img src="https://www.justvanilla.com/wp-content/uploads/2023/04/Vanilla-Logo.svg" height="50" align="left"></img> <img src="https://www.justvanilla.com/wp-content/uploads/2023/04/Vanilla-Logo.svg" height="50" align="left"></img>
> This repo is a drop-in replacement for standard cache action to make it use AWS S3. You can replace cache calls with `uses: justvanilla/shared-gha-cache@s3` directly. Default behavior will be identical. To make task use S3 bucket instead, provide the following inputs: > This repo is a drop-in replacement for standard cache action to make it use AWS S3. You can replace cache calls with `uses: justvanilla/shared-gha-cache-s3@v3` directly. Default behavior will be identical. To make task use S3 bucket instead, provide the following inputs:
> * **aws-region**: us-east-1 > * **aws-region**: us-east-1
> * **aws-bucket**: the-bucketest-bucket > * **aws-bucket**: the-bucketest-bucket
> * **aws-access-key-id**: key id for account having RW access to the bucket > * **aws-access-key-id**: key id for account having RW access to the bucket
@ -109,7 +109,7 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: justvanilla/shared-gha-cache@s3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: prime-numbers path: prime-numbers
key: ${{ runner.os }}-primes key: ${{ runner.os }}-primes
@ -205,7 +205,7 @@ A cache key can include any of the contexts, functions, literals, and operators
For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change. For example, using the [`hashFiles`](https://docs.github.com/en/actions/learn-github-actions/expressions#hashfiles) function allows you to create a new cache when dependencies change.
```yaml ```yaml
- uses: justvanilla/shared-gha-cache@s3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
@ -227,7 +227,7 @@ Additionally, you can use arbitrary command output in a cache key, such as a dat
echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT echo "date=$(/bin/date -u "+%Y%m%d")" >> $GITHUB_OUTPUT
shell: bash shell: bash
- uses: justvanilla/shared-gha-cache@s3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ steps.get-date.outputs.date }}-${{ hashFiles('**/lockfiles') }}
@ -253,11 +253,15 @@ Example:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: justvanilla/shared-gha-cache@s3 - uses: justvanilla/shared-gha-cache-s3@v3
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Install Dependencies - name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'
@ -285,10 +289,14 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: justvanilla/shared-gha-cache@s3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: prime-numbers path: prime-numbers
key: primes key: primes
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Generate Prime Numbers - name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true' if: steps.cache-primes.outputs.cache-hit != 'true'
@ -296,10 +304,14 @@ jobs:
- name: Cache Numbers - name: Cache Numbers
id: cache-numbers id: cache-numbers
uses: justvanilla/shared-gha-cache@s3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: numbers path: numbers
key: primes key: primes
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Generate Numbers - name: Generate Numbers
if: steps.cache-numbers.outputs.cache-hit != 'true' if: steps.cache-numbers.outputs.cache-hit != 'true'
@ -312,10 +324,14 @@ jobs:
- name: Cache Primes - name: Cache Primes
id: cache-primes id: cache-primes
uses: justvanilla/shared-gha-cache@s3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: prime-numbers path: prime-numbers
key: primes key: primes
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Generate Prime Numbers - name: Generate Prime Numbers
if: steps.cache-primes.outputs.cache-hit != 'true' if: steps.cache-primes.outputs.cache-hit != 'true'

@ -1,6 +1,6 @@
name: 'Cache (AWS S3)' name: 'Cache (AWS S3)'
description: 'Cache artifacts like dependencies and build outputs to improve workflow execution time stored in S3' description: 'Cache artifacts like dependencies and build outputs to improve workflow execution time stored in S3'
author: 'GitHub' author: 'Github, Justvanilla'
inputs: inputs:
path: path:
description: 'A list of files, directories, and wildcard patterns to cache and restore' description: 'A list of files, directories, and wildcard patterns to cache and restore'

@ -12,9 +12,13 @@ This document lists some of the strategies (and example workflows if possible) w
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-latest
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
key: ${{ some-metadata }}-cache key: ${{ some-metadata }}-cache
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
In your workflows, you can use different strategies to name your key depending on your use case so that the cache is scoped appropriately for your need. For example, you can have cache specific to OS, or based on the lockfile or commit SHA or even workflow run. In your workflows, you can use different strategies to name your key depending on your use case so that the cache is scoped appropriately for your need. For example, you can have cache specific to OS, or based on the lockfile or commit SHA or even workflow run.
@ -24,12 +28,16 @@ In your workflows, you can use different strategies to name your key depending o
One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile. One of the most common use case is to use hash for lockfile as key. This way, same cache will be restored for a lockfile until there's a change in dependencies listed in lockfile.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: cache-${{ hashFiles('**/lockfiles') }} key: cache-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Using restore keys to download the closest matching cache ### Using restore keys to download the closest matching cache
@ -37,7 +45,7 @@ One of the most common use case is to use hash for lockfile as key. This way, sa
If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time. If cache is not found matching the primary key, restore keys can be used to download the closest matching cache that was recently created. This ensures that the build/install step will need to additionally fetch just a handful of newer dependencies, and hence saving build time.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
@ -45,6 +53,10 @@ If cache is not found matching the primary key, restore keys can be used to down
key: cache-npm-${{ hashFiles('**/lockfiles') }} key: cache-npm-${{ hashFiles('**/lockfiles') }}
restore-keys: | restore-keys: |
cache-npm- cache-npm-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
The restore keys can be provided as a complete name, or a prefix, read more [here](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) on how a cache key is matched using restore keys. The restore keys can be provided as a complete name, or a prefix, read more [here](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#matching-a-cache-key) on how a cache key is matched using restore keys.
@ -54,12 +66,16 @@ The restore keys can be provided as a complete name, or a prefix, read more [her
In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS. In case of workflows with matrix running for multiple Operating Systems, the caches can be stored separately for each of them. This can be used in combination with hashfiles in case multiple caches are being generated per OS.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: ${{ runner.os }}-cache key: ${{ runner.os }}-cache
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Creating a short lived cache ### Creating a short lived cache
@ -73,12 +89,16 @@ Caches scoped to the particular workflow run id or run attempt can be stored and
On similar lines, commit sha can be used to create a very specialized and short lived cache. On similar lines, commit sha can be used to create a very specialized and short lived cache.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: cache-${{ github.sha }} key: cache-${{ github.sha }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Using multiple factors while forming a key depening on the need ### Using multiple factors while forming a key depening on the need
@ -86,12 +106,16 @@ On similar lines, commit sha can be used to create a very specialized and short
Cache key can be formed by combination of more than one metadata, evaluated info. Cache key can be formed by combination of more than one metadata, evaluated info.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
The [GitHub Context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) can be used to create keys using the workflows metadata. The [GitHub Context](https://docs.github.com/en/actions/learn-github-actions/contexts#github-context) can be used to create keys using the workflows metadata.
@ -148,7 +172,7 @@ In case you are using a centralized job to create and save your cache that can b
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/cache/restore@v3 - uses: justvanilla/shared-gha-cache-s3/restore@v3
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
@ -173,7 +197,7 @@ You can use the output of this action to exit the workflow on cache miss. This w
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/cache/restore@v3 - uses: justvanilla/shared-gha-cache-s3/restore@v3
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
@ -194,22 +218,30 @@ steps:
If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action. If you want to avoid re-computing the cache key again in `save` action, the outputs from `restore` action can be used as input to the `save` action.
```yaml ```yaml
- uses: actions/cache/restore@v3 - uses: justvanilla/shared-gha-cache-s3/restore@v3
id: restore-cache id: restore-cache
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
. .
. .
. .
- uses: actions/cache/save@v3 - uses: justvanilla/shared-gha-cache-s3/save@v3
with: with:
path: | path: |
path/to/dependencies path/to/dependencies
some/other/dependencies some/other/dependencies
key: ${{ steps.restore-cache.outputs.cache-primary-key }} key: ${{ steps.restore-cache.outputs.cache-primary-key }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Re-evaluate cache key while saving cache ### Re-evaluate cache key while saving cache
@ -219,33 +251,45 @@ On the other hand, the key can also be explicitly re-computed while executing th
Let's say we have a restore step that computes key at runtime Let's say we have a restore step that computes key at runtime
```yaml ```yaml
uses: actions/cache/restore@v3 uses: justvanilla/shared-gha-cache-s3/restore@v3
id: restore-cache id: restore-cache
with: with:
key: cache-${{ hashFiles('**/lockfiles') }} key: cache-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
Case 1: Where an user would want to reuse the key as it is Case 1: Where an user would want to reuse the key as it is
```yaml ```yaml
uses: actions/cache/save@v3 uses: justvanilla/shared-gha-cache-s3/save@v3
with: with:
key: ${{ steps.restore-cache.outputs.cache-primary-key }} key: ${{ steps.restore-cache.outputs.cache-primary-key }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
Case 2: Where the user would want to re-evaluate the key Case 2: Where the user would want to re-evaluate the key
```yaml ```yaml
uses: actions/cache/save@v3 uses: justvanilla/shared-gha-cache-s3/save@v3
with: with:
key: npm-cache-${{hashfiles(package-lock.json)}} key: npm-cache-${{hashfiles(package-lock.json)}}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Saving cache even if the build fails ### Saving cache even if the build fails
There can be cases where a cache should be saved even if the build job fails. For example, a job can fail due to flaky tests but the caches can still be re-used. You can use `actions/cache/save` action to save the cache by using `if: always()` condition. There can be cases where a cache should be saved even if the build job fails. For example, a job can fail due to flaky tests but the caches can still be re-used. You can use `justvanilla/shared-gha-cache-s3/save` action to save the cache by using `if: always()` condition.
Similarly, `actions/cache/save` action can be conditionally used based on the output of the previous steps. This way you get more control on when to save the cache. Similarly, `justvanilla/shared-gha-cache-s3/save` action can be conditionally used based on the output of the previous steps. This way you get more control on when to save the cache.
```yaml ```yaml
steps: steps:
@ -255,16 +299,20 @@ steps:
. .
- name: Build - name: Build
run: /build.sh run: /build.sh
- uses: actions/cache/save@v3 - uses: justvanilla/shared-gha-cache-s3/save@v3
if: always() // or any other condition to invoke the save action if: always() // or any other condition to invoke the save action
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Saving cache once and reusing in multiple workflows ### Saving cache once and reusing in multiple workflows
In case of multi-module projects, where the built artifact of one project needs to be reused in subsequent child modules, the need of rebuilding the parent module again and again with every build can be eliminated. The `actions/cache` or `actions/cache/save` action can be used to build and save the parent module artifact once, and restored multiple times while building the child modules. In case of multi-module projects, where the built artifact of one project needs to be reused in subsequent child modules, the need of rebuilding the parent module again and again with every build can be eliminated. The `justvanilla/shared-gha-cache-s3` or `justvanilla/shared-gha-cache-s3/save` action can be used to build and save the parent module artifact once, and restored multiple times while building the child modules.
#### Step 1 - Build the parent module and save it #### Step 1 - Build the parent module and save it
@ -275,11 +323,15 @@ steps:
- name: Build - name: Build
run: ./build-parent-module.sh run: ./build-parent-module.sh
- uses: actions/cache/save@v3 - uses: justvanilla/shared-gha-cache-s3/save@v3
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
#### Step 2 - Restore the built artifact from cache using the same key and path #### Step 2 - Restore the built artifact from cache using the same key and path
@ -288,11 +340,15 @@ steps:
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- uses: actions/cache/restore@v3 - uses: justvanilla/shared-gha-cache-s3/restore@v3
id: cache id: cache
with: with:
path: path/to/dependencies path: path/to/dependencies
key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Install Dependencies - name: Install Dependencies
if: steps.cache.outputs.cache-hit != 'true' if: steps.cache.outputs.cache-hit != 'true'

@ -46,7 +46,7 @@
Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies): Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/package-references-in-project-files#locking-dependencies):
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.nuget/packages path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
@ -55,10 +55,10 @@ Using [NuGet lock files](https://docs.microsoft.com/nuget/consume-packages/packa
``` ```
Depending on the environment, huge packages might be pre-installed in the global cache folder. Depending on the environment, huge packages might be pre-installed in the global cache folder.
With `actions/cache@v3` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns) With `justvanilla/shared-gha-cache-s3@v3` you can now exclude unwanted packages with [exclude pattern](https://github.com/actions/toolkit/tree/main/packages/glob#exclude-patterns)
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.nuget/packages ~/.nuget/packages
@ -75,24 +75,32 @@ Or you could move the cache folder like below.
env: env:
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
steps: steps:
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ${{ github.workspace }}/.nuget/packages path: ${{ github.workspace }}/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }} key: ${{ runner.os }}-nuget-${{ hashFiles('**/packages.lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-nuget- ${{ runner.os }}-nuget-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Clojure - Lein Deps ## Clojure - Lein Deps
```yaml ```yaml
- name: Cache lein project dependencies - name: Cache lein project dependencies
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.m2/repository path: ~/.m2/repository
key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }} key: ${{ runner.os }}-clojure-${{ hashFiles('**/project.clj') }}
restore-keys: | restore-keys: |
${{ runner.os }}-clojure ${{ runner.os }}-clojure
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
@ -101,23 +109,31 @@ steps:
### POSIX ### POSIX
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.dub path: ~/.dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-dub- ${{ runner.os }}-dub-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Windows ### Windows
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~\AppData\Local\dub path: ~\AppData\Local\dub
key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }} key: ${{ runner.os }}-dub-${{ hashFiles('**/dub.selections.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-dub- ${{ runner.os }}-dub-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Deno ## Deno
@ -125,40 +141,52 @@ steps:
### Linux ### Linux
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.deno ~/.deno
~/.cache/deno ~/.cache/deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }} key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### macOS ### macOS
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.deno ~/.deno
~/Library/Caches/deno ~/Library/Caches/deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }} key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Windows ### Windows
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~\.deno ~\.deno
~\AppData\Local\deno ~\AppData\Local\deno
key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }} key: ${{ runner.os }}-deno-${{ hashFiles('**/deps.ts') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Elixir - Mix ## Elixir - Mix
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
deps deps
@ -166,6 +194,10 @@ steps:
key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-mix- ${{ runner.os }}-mix-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Erlang - Rebar3 ## Erlang - Rebar3
@ -178,6 +210,10 @@ steps:
key: ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-${{ hashFiles('**/*rebar.lock') }} key: ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-${{ hashFiles('**/*rebar.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-erlang-${{ env.OTP_VERSION }}- ${{ runner.os }}-erlang-${{ env.OTP_VERSION }}-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Go - Modules ## Go - Modules
@ -185,7 +221,7 @@ steps:
### Linux ### Linux
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.cache/go-build ~/.cache/go-build
@ -193,12 +229,16 @@ steps:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### macOS ### macOS
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/Library/Caches/go-build ~/Library/Caches/go-build
@ -206,12 +246,16 @@ steps:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Windows ### Windows
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~\AppData\Local\go-build ~\AppData\Local\go-build
@ -219,6 +263,10 @@ steps:
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: | restore-keys: |
${{ runner.os }}-go- ${{ runner.os }}-go-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Haskell - Cabal ## Haskell - Cabal
@ -227,7 +275,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
```yaml ```yaml
- name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle - name: Cache ~/.cabal/packages, ~/.cabal/store and dist-newstyle
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.cabal/packages ~/.cabal/packages
@ -235,6 +283,10 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
dist-newstyle dist-newstyle
key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze') }} key: ${{ runner.os }}-${{ matrix.ghc }}-${{ hashFiles('**/*.cabal', '**/cabal.project', '**/cabal.project.freeze') }}
restore-keys: ${{ runner.os }}-${{ matrix.ghc }}- restore-keys: ${{ runner.os }}-${{ matrix.ghc }}-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Haskell - Stack ## Haskell - Stack
@ -242,26 +294,34 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
### Linux or macOS ### Linux or macOS
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
name: Cache ~/.stack name: Cache ~/.stack
with: with:
path: ~/.stack path: ~/.stack
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }} key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-stack-global- ${{ runner.os }}-stack-global-
- uses: actions/cache@v3 aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- uses: justvanilla/shared-gha-cache-s3@v3
name: Cache .stack-work name: Cache .stack-work
with: with:
path: .stack-work path: .stack-work
key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }} key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}
restore-keys: | restore-keys: |
${{ runner.os }}-stack-work- ${{ runner.os }}-stack-work-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Windows ### Windows
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack name: Cache %APPDATA%\stack %LOCALAPPDATA%\Programs\stack
with: with:
path: | path: |
@ -270,13 +330,21 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }} key: ${{ runner.os }}-stack-global-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-stack-global- ${{ runner.os }}-stack-global-
- uses: actions/cache@v3 aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- uses: justvanilla/shared-gha-cache-s3@v3
name: Cache .stack-work name: Cache .stack-work
with: with:
path: .stack-work path: .stack-work
key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }} key: ${{ runner.os }}-stack-work-${{ hashFiles('stack.yaml') }}-${{ hashFiles('package.yaml') }}-${{ hashFiles('**/*.hs') }}
restore-keys: | restore-keys: |
${{ runner.os }}-stack-work- ${{ runner.os }}-stack-work-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Java - Gradle ## Java - Gradle
@ -284,7 +352,7 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
> **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons. > **Note** Ensure no Gradle daemons are running anymore when your workflow completes. Creating the cache package might fail due to locks being held by Gradle. Refer to the [Gradle Daemon documentation](https://docs.gradle.org/current/userguide/gradle_daemon.html) on how to disable or stop the Gradle Daemons.
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.gradle/caches ~/.gradle/caches
@ -292,18 +360,26 @@ We cache the elements of the Cabal store separately, as the entirety of `~/.caba
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }} key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: | restore-keys: |
${{ runner.os }}-gradle- ${{ runner.os }}-gradle-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Java - Maven ## Java - Maven
```yaml ```yaml
- name: Cache local Maven repository - name: Cache local Maven repository
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.m2/repository path: ~/.m2/repository
key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }} key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
restore-keys: | restore-keys: |
${{ runner.os }}-maven- ${{ runner.os }}-maven-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Node - npm ## Node - npm
@ -334,23 +410,31 @@ After [deprecation](https://github.blog/changelog/2022-10-11-github-actions-depr
`Get npm cache directory` step can then be used with `actions/cache` as shown below `Get npm cache directory` step can then be used with `actions/cache` as shown below
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true' id: npm-cache # use this to check for `cache-hit` ==> if: steps.npm-cache.outputs.cache-hit != 'true'
with: with:
path: ${{ steps.npm-cache-dir.outputs.dir }} path: ${{ steps.npm-cache-dir.outputs.dir }}
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-node- ${{ runner.os }}-node-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Node - Lerna ## Node - Lerna
```yaml ```yaml
- name: restore lerna - name: restore lerna
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: '**/node_modules' path: '**/node_modules'
key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-${{ hashFiles('**/yarn.lock') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Node - Yarn ## Node - Yarn
@ -361,13 +445,17 @@ The yarn cache directory will depend on your operating system and version of `ya
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn cache dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-yarn- ${{ runner.os }}-yarn-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Node - Yarn 2 ## Node - Yarn 2
@ -379,13 +467,17 @@ The yarn 2 cache directory will depend on your config. See https://yarnpkg.com/c
id: yarn-cache-dir-path id: yarn-cache-dir-path
run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
with: with:
path: ${{ steps.yarn-cache-dir-path.outputs.dir }} path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-yarn- ${{ runner.os }}-yarn-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## OCaml/Reason - esy ## OCaml/Reason - esy
@ -394,12 +486,16 @@ Esy allows you to export built dependencies and import pre-built dependencies.
```yaml ```yaml
- name: Restore Cache - name: Restore Cache
id: restore-cache id: restore-cache
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: _export path: _export
key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }} key: ${{ runner.os }}-esy-${{ hashFiles('esy.lock/index.json') }}
restore-keys: | restore-keys: |
${{ runner.os }}-esy- ${{ runner.os }}-esy-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- name: Esy install - name: Esy install
run: 'esy install' run: 'esy install'
- name: Import Cache - name: Import Cache
@ -423,12 +519,16 @@ Esy allows you to export built dependencies and import pre-built dependencies.
id: composer-cache id: composer-cache
run: | run: |
echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT echo "dir=$(composer config cache-files-dir)" >> $GITHUB_OUTPUT
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ${{ steps.composer-cache.outputs.dir }} path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }} key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: | restore-keys: |
${{ runner.os }}-composer- ${{ runner.os }}-composer-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Python - pip ## Python - pip
@ -444,12 +544,16 @@ Locations:
### Simple example ### Simple example
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.cache/pip path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
Replace `~/.cache/pip` with the correct `path` if not using Ubuntu. Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
@ -457,29 +561,41 @@ Replace `~/.cache/pip` with the correct `path` if not using Ubuntu.
### Multiple OS's in a workflow ### Multiple OS's in a workflow
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
if: startsWith(runner.os, 'Linux') if: startsWith(runner.os, 'Linux')
with: with:
path: ~/.cache/pip path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
if: startsWith(runner.os, 'macOS') if: startsWith(runner.os, 'macOS')
with: with:
path: ~/Library/Caches/pip path: ~/Library/Caches/pip
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
if: startsWith(runner.os, 'Windows') if: startsWith(runner.os, 'Windows')
with: with:
path: ~\AppData\Local\pip\Cache path: ~\AppData\Local\pip\Cache
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Multiple OS's in a workflow with a matrix ### Multiple OS's in a workflow with a matrix
@ -499,12 +615,16 @@ jobs:
- os: windows-latest - os: windows-latest
path: ~\AppData\Local\pip\Cache path: ~\AppData\Local\pip\Cache
steps: steps:
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ${{ matrix.path }} path: ${{ matrix.path }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
### Using pip to get cache location ### Using pip to get cache location
@ -517,12 +637,16 @@ jobs:
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: pip cache - name: pip cache
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ${{ steps.pip-cache.outputs.dir }} path: ${{ steps.pip-cache.outputs.dir }}
key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }}
restore-keys: | restore-keys: |
${{ runner.os }}-pip- ${{ runner.os }}-pip-
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## Python - pipenv ## Python - pipenv
@ -535,10 +659,14 @@ jobs:
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ~/.local/share/virtualenvs path: ~/.local/share/virtualenvs
key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }} key: ${{ runner.os }}-python-${{ steps.setup-python.outputs.python-version }}-pipenv-${{ hashFiles('Pipfile.lock') }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
## R - renv ## R - renv
@ -562,7 +690,7 @@ For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment
cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "") cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
shell: Rscript {0} shell: Rscript {0}
- name: Restore Renv package cache - name: Restore Renv package cache
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: ${{ env.RENV_PATHS_ROOT }} path: ${{ env.RENV_PATHS_ROOT }}
key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }} key: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{ inputs.cache-version }}-${{ hashFiles('renv.lock') }}
@ -588,7 +716,7 @@ whenever possible:
## Rust - Cargo ## Rust - Cargo
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.cargo/bin/ ~/.cargo/bin/
@ -603,7 +731,7 @@ whenever possible:
```yaml ```yaml
- name: Cache SBT - name: Cache SBT
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.ivy2/cache ~/.ivy2/cache
@ -614,7 +742,7 @@ whenever possible:
## Swift, Objective-C - Carthage ## Swift, Objective-C - Carthage
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: Carthage path: Carthage
key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }} key: ${{ runner.os }}-carthage-${{ hashFiles('**/Cartfile.resolved') }}
@ -625,7 +753,7 @@ whenever possible:
## Swift, Objective-C - CocoaPods ## Swift, Objective-C - CocoaPods
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: Pods path: Pods
key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }} key: ${{ runner.os }}-pods-${{ hashFiles('**/Podfile.lock') }}
@ -636,7 +764,7 @@ whenever possible:
## Swift - Swift Package Manager ## Swift - Swift Package Manager
```yaml ```yaml
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: .build path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }} key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
@ -651,7 +779,7 @@ env:
MINT_PATH: .mint/lib MINT_PATH: .mint/lib
MINT_LINK_PATH: .mint/bin MINT_LINK_PATH: .mint/bin
steps: steps:
- uses: actions/cache@v3 - uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: .mint path: .mint
key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }} key: ${{ runner.os }}-mint-${{ hashFiles('**/Mintfile') }}
@ -667,7 +795,7 @@ steps:
```yaml ```yaml
- name: Cache Bazel - name: Cache Bazel
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
~/.cache/bazel ~/.cache/bazel
@ -681,7 +809,7 @@ steps:
```yaml ```yaml
- name: Cache Bazel - name: Cache Bazel
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: | path: |
/private/var/tmp/_bazel_runner/ /private/var/tmp/_bazel_runner/

@ -1,6 +1,6 @@
name: 'Restore Cache (AWS S3)' name: 'Restore Cache (AWS S3)'
description: 'Restore Cache artifacts stored in S3 like dependencies and build outputs to improve workflow execution time' description: 'Restore Cache artifacts stored in S3 like dependencies and build outputs to improve workflow execution time'
author: 'GitHub' author: 'GitHub, Justvanilla'
inputs: inputs:
path: path:
description: 'A list of files, directories, and wildcard patterns to restore' description: 'A list of files, directories, and wildcard patterns to restore'

@ -1,6 +1,6 @@
name: 'Save a cache (AWS S3)' name: 'Save a cache (AWS S3)'
description: 'Save Cache artifacts in S3 like dependencies and build outputs to improve workflow execution time' description: 'Save Cache artifacts in S3 like dependencies and build outputs to improve workflow execution time'
author: 'GitHub' author: 'Github, Justvanilla'
inputs: inputs:
path: path:
description: 'A list of files, directories, and wildcard patterns to cache' description: 'A list of files, directories, and wildcard patterns to cache'

@ -12,12 +12,16 @@ A cache today is immutable and cannot be updated. But some use cases require the
```yaml ```yaml
- name: update cache on every commit - name: update cache on every commit
uses: actions/cache@v3 uses: justvanilla/shared-gha-cache-s3@v3
with: with:
path: prime-numbers path: prime-numbers
key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well
restore-keys: | restore-keys: |
primes-${{ runner.os }} primes-${{ runner.os }}
aws-region: ${{ secrets.CACHE_AWS_REGION }}
aws-bucket: ${{ secrets.CACHE_AWS_BUCKET }}
aws-access-key-id: ${{ secrets.CACHE_AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.CACHE_AWS_SECRET_ACCESS_KEY }}
``` ```
Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits). Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits).

Loading…
Cancel
Save