> 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
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.
### 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
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.
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
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
### 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.
@ -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.
@ -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