-
Notifications
You must be signed in to change notification settings - Fork 58
Add stash action #32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add stash action #32
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
ca56a74
add stash action
assignUser 8b52b53
fix workflow path
assignUser 4d4f602
update ratelimit for test
assignUser 1aa6d3f
improve readme
assignUser cc97379
remove LICENSE
assignUser 3b9d736
fix typos and improve readme
assignUser 93418db
remove 'required' from inputs with defaults
assignUser c094cc9
add doc strings to python functions
assignUser 2e58ef1
fix more typos
assignUser 5ecbeeb
fix: update actions/upload-artifact to 4.3.5
assignUser 035099f
prevent download errors from failing the workflow
assignUser c94b890
update upload action
assignUser 944d42f
use non-hidden files for tests
assignUser File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,150 @@ | ||
| # Copyright (c) The stash contributors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| name: Test Stash Action | ||
|
|
||
| on: | ||
| pull_request: | ||
| push: | ||
| branches: | ||
| - main | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| jobs: | ||
| test-deps: | ||
| name: "check for dependencies" | ||
| runs-on: ubuntu-latest | ||
| container: quay.io/centos/centos:stream8 | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Run action | ||
| continue-on-error: true | ||
| id: fail | ||
| uses: ./stash/restore | ||
| with: | ||
| path: ./stash | ||
| key: this-must-fail | ||
|
|
||
| - name: It did not fail | ||
| if: ${{ steps.fail.outputs.stash-hit != '' }} | ||
| run: | | ||
| echo "::error ::Dependency check should have failed!" | ||
| exit 1 | ||
|
|
||
| test-save: | ||
| name: "stash/save on ${{ matrix.os }}" | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-13, macos-14] | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Run unittests | ||
| shell: bash | ||
| env: | ||
| GH_TOKEN: "${{ github.token }}" | ||
| run: | | ||
| cd stash/restore | ||
| python3 test_get_stash.py | ||
|
|
||
| - name: Test Save | ||
| uses: ./stash/save | ||
| with: | ||
| path: stash/ | ||
| # Create a unique key to test intra workflow artifacts. | ||
| key: test/stash-${{ matrix.os }}-${{ github.sha }} | ||
| retention-days: '1' | ||
|
|
||
| - name: Show rate limit | ||
| env: | ||
| GH_TOKEN: "${{ github.token }}" | ||
| run: gh api -q '.rate' rate_limit | ||
|
|
||
| - name: Test Overwrite | ||
| id: test | ||
| uses: ./stash/save | ||
| with: | ||
| path: stash/ | ||
| # Create a unique key to test intra workflow artifacts. | ||
| key: test/stash-${{ matrix.os }}-${{ github.sha }} | ||
| retention-days: '1' | ||
|
|
||
| - name: Show rate limit | ||
| env: | ||
| GH_TOKEN: "${{ github.token }}" | ||
| run: gh api -q '.rate' rate_limit | ||
|
|
||
| - name: Check Output | ||
| shell: bash | ||
| env: | ||
| ID: ${{ steps.test.outputs.stash-id }} | ||
| URL: ${{ steps.test.outputs.stash-url }} | ||
| run: | | ||
| if [ -z "$ID" -o -z "$URL" ]; then | ||
| echo "Output empty" | ||
| exit 1 | ||
| fi | ||
|
|
||
| - name: Check if inter-workflow stash exists | ||
| id: stash | ||
| uses: ./stash/restore | ||
| with: | ||
| key: test-stash-cross-${{ matrix.os }} | ||
| path: test-stash | ||
|
|
||
| - name: Show rate limit | ||
| env: | ||
| GH_TOKEN: "${{ github.token }}" | ||
| run: gh api -q '.rate' rate_limit | ||
|
|
||
| - name: Save cross-workflow Stash | ||
| if: ${{ steps.stash.outputs.stash-hit == 'false' }} | ||
| uses: ./stash/save | ||
| with: | ||
| path: stash/ | ||
| key: test-stash-cross-${{ matrix.os }} | ||
| retention-days: '90' | ||
|
|
||
| test-restore: | ||
| name: "stash/restore on ${{ matrix.os }}" | ||
| strategy: | ||
| fail-fast: false | ||
| matrix: | ||
| os: [ubuntu-latest, windows-latest, macos-13, macos-14] | ||
| needs: test-save | ||
| runs-on: ${{ matrix.os }} | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
|
|
||
| - name: Test intra-workflow stash | ||
| uses: ./stash/restore | ||
| with: | ||
| key: test/stash-${{ matrix.os }}-${{ github.sha }} | ||
| path: intra/stash/ | ||
|
|
||
| - shell: bash | ||
| run: ls -laR intra | ||
|
|
||
| - name: Test inter-workflow stash | ||
| uses: ./stash/restore | ||
| with: | ||
| key: test-stash-cross-${{ matrix.os }} | ||
| path: inter/stash/ | ||
|
|
||
| - shell: bash | ||
| run: ls -laR inter/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| # Copyright (c) The stash contributors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| __pycache__ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <!-- | ||
| # Copyright (c) The stash contributors | ||
| # | ||
| # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| # you may not use this file except in compliance with the License. | ||
| # You may obtain a copy of the License at | ||
| # | ||
| # http://www.apache.org/licenses/LICENSE-2.0 | ||
| # | ||
| # Unless required by applicable law or agreed to in writing, software | ||
| # distributed under the License is distributed on an "AS IS" BASIS, | ||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| # See the License for the specific language governing permissions and | ||
| # limitations under the License. | ||
| --> | ||
|
|
||
| # Stash GitHub Action | ||
|
|
||
| `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. | ||
| 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). | ||
| With workflows running multiple configurations across PRs and merge commits this limit is quickly reached, leading to cache evictions, causing CI times to increase. | ||
|
|
||
| This action is split into two distinct operations: | ||
| - `infrastructure-actions/stash/restore` for fetching a previously stored stash | ||
| - `infrastructure-actions/stash/save` for storing a new stash after a build has been completed. | ||
|
|
||
| ## Features | ||
|
|
||
| - Each stash is uploaded as a workflow artifact. In contrasts to `actions/cache` there is no repository wide size limit for artifacts. | ||
| - There is no cache eviction, stashes will expire after 5 days by default. | ||
| - Artifact storage is free for public repositories and much cheaper than CI minutes (~ 1 Cent/1GB/day) for private repositories. | ||
| - No secrets required, stash can be used in fork PRs. | ||
| - 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. | ||
| 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. | ||
|
|
||
| ## Usage | ||
|
|
||
| > [!IMPORTANT] | ||
| > You have to explicitly save your stash by using `infrastructure-actions/stash/save` action, | ||
| > it will not be saved automatically by using `infrastructure-actions/stash/restore`. | ||
|
|
||
| To restore a stash before your build process, use the `infrastructure-actions/stash/restore` action in your workflow: | ||
|
|
||
|
|
||
| ```yaml | ||
| steps: | ||
| - uses: actions/checkout@v2 | ||
| - uses: infrastructure-actions/stash/restore@v1 | ||
| with: | ||
| key: 'cache-key' | ||
| path: 'path/to/cache' | ||
| ``` | ||
|
|
||
| After your build completes, save the stash using the `infrastructure-actions/stash/save` action: | ||
|
|
||
| ```yaml | ||
| steps: | ||
| - uses: infrastructure-actions/stash/save@v1 | ||
| with: | ||
| key: 'cache-key' | ||
| path: 'path/to/cache' | ||
| ``` | ||
| Stashes will expire after 5 days by default. | ||
| You can set this from 1-90 days with the `retention-days` input. | ||
| Using the `save` action again in the same workflow run will overwrite the existing cache with the same key. | ||
| This does apply to each invocation in a matrix job as well! | ||
| If you want to keep the old cache, you can use a different key or set `overwrite` to `false`. | ||
|
|
||
| ### Inputs and Outputs | ||
|
|
||
| Each action (restore and save) has specific inputs tailored to its functionality, | ||
| they are specifically modeled after `actions/cache` and `actions/upload-artifact` to provide a drop in replacement. | ||
| Please refer to the action metadata (`action.yml`) for a comprehensive list of inputs, including descriptions and default values. | ||
|
|
||
| Additionally the `restore` action has an output `stash-hit` which is set to `true` if the cache was restored successfully, | ||
| `false` if no cache was restored and '' if the action failed (an error will be thrown unless `continue-on-error` is set). | ||
| A technical limitation of composite actions like `Stash` is that all outputs are **strings**. | ||
| Therefore an explicit comparison has to be used when using the output: | ||
| `if: ${{ steps.restore-stash.outputs.stash-hit == 'true' }}` | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.