|
| 1 | +<!-- |
| 2 | +# Copyright (c) The stash contributors |
| 3 | +# |
| 4 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | +# you may not use this file except in compliance with the License. |
| 6 | +# You may obtain a copy of the License at |
| 7 | +# |
| 8 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | +# |
| 10 | +# Unless required by applicable law or agreed to in writing, software |
| 11 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | +# See the License for the specific language governing permissions and |
| 14 | +# limitations under the License. |
| 15 | +--> |
| 16 | + |
| 17 | +# Stash GitHub Action |
| 18 | + |
| 19 | +`Stash` provides a solution for managing large build caches in your workflows, that doesn't require any secrets and can therefore be used in fork PRs. |
| 20 | +It's designed as an alternative to `actions/cache` which struggles with big build caches such as `.ccache` directories due to the repository wide [size limit](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy) of 10GB and the fact that caches are [immutable](https://github.com/actions/toolkit/issues/505). |
| 21 | +With workflows running multiple configurations across PRs and merge commits this limit is quickly reached, leading to cache evictions, causing CI times to increase. |
| 22 | + |
| 23 | +This action is split into two distinct operations: |
| 24 | +- `infrastructure-actions/stash/restore` for fetching a previously stored stash |
| 25 | +- `infrastructure-actions/stash/save` for storing a new stash after a build has been completed. |
| 26 | + |
| 27 | +## Features |
| 28 | + |
| 29 | +- Each stash is uploaded as a workflow artifact. In contrasts to `actions/cache` there is no repository wide size limit for artifacts. |
| 30 | + - There is no cache eviction, stashes will expire after 5 days by default. |
| 31 | +- Artifact storage is free for public repositories and much cheaper than CI minutes (~ 1 Cent/1GB/day) for private repositories. |
| 32 | +- No secrets required, stash can be used in fork PRs. |
| 33 | +- Follows the same search scope as `actions/cache`: will look for the cache in the current workflow, current branch and finally the base branch of a PR. |
| 34 | +This prevents untrusted user caches (e.g. from fork PR CI runs) from being used on the default branch (where actions have elevated permissions by default) or other repo or PR branches. |
| 35 | + |
| 36 | +## Usage |
| 37 | + |
| 38 | +> [!IMPORTANT] |
| 39 | +> You have to explicitly save your stash by using `infrastructure-actions/stash/save` action, |
| 40 | +> it will not be saved automatically by using `infrastructure-actions/stash/restore`. |
| 41 | +
|
| 42 | +To restore a stash before your build process, use the `infrastructure-actions/stash/restore` action in your workflow: |
| 43 | + |
| 44 | + |
| 45 | +```yaml |
| 46 | +steps: |
| 47 | +- uses: actions/checkout@v2 |
| 48 | +- uses: infrastructure-actions/stash/restore@v1 |
| 49 | + with: |
| 50 | + key: 'cache-key' |
| 51 | + path: 'path/to/cache' |
| 52 | +``` |
| 53 | +
|
| 54 | +After your build completes, save the stash using the `infrastructure-actions/stash/save` action: |
| 55 | + |
| 56 | +```yaml |
| 57 | +steps: |
| 58 | +- uses: infrastructure-actions/stash/save@v1 |
| 59 | + with: |
| 60 | + key: 'cache-key' |
| 61 | + path: 'path/to/cache' |
| 62 | +``` |
| 63 | +Stashes will expire after 5 days by default. |
| 64 | +You can set this from 1-90 days with the `retention-days` input. |
| 65 | +Using the `save` action again in the same workflow run will overwrite the existing cache with the same key. |
| 66 | +This does apply to each invocation in a matrix job as well! |
| 67 | +If you want to keep the old cache, you can use a different key or set `overwrite` to `false`. |
| 68 | + |
| 69 | +### Inputs and Outputs |
| 70 | + |
| 71 | +Each action (restore and save) has specific inputs tailored to its functionality, |
| 72 | +they are specifically modeled after `actions/cache` and `actions/upload-artifact` to provide a drop in replacement. |
| 73 | +Please refer to the action metadata (`action.yml`) for a comprehensive list of inputs, including descriptions and default values. |
| 74 | + |
| 75 | +Additionally the `restore` action has an output `stash-hit` which is set to `true` if the cache was restored successfully, |
| 76 | +`false` if no cache was restored and '' if the action failed (an error will be thrown unless `continue-on-error` is set). |
| 77 | +A technical limitation of composite actions like `Stash` is that all outputs are **strings**. |
| 78 | +Therefore an explicit comparison has to be used when using the output: |
| 79 | +`if: ${{ steps.restore-stash.outputs.stash-hit == 'true' }}` |
0 commit comments