From 020a412c274f2031f05eba9c64b181a1961b89b8 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 5 Dec 2022 12:34:45 +0000 Subject: [PATCH] Readme draft for new actions --- README.md | 4 ++ restore/README.md | 117 ++++++++++++++++++++++++++++++++++++++++++++++ save/README.md | 7 +++ 3 files changed, 128 insertions(+) create mode 100644 restore/README.md create mode 100644 save/README.md diff --git a/README.md b/README.md index 8117b58..41a7709 100644 --- a/README.md +++ b/README.md @@ -8,6 +8,10 @@ This action allows caching dependencies and build outputs to improve workflow ex See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows). +[Restore action](./restore/README.md) + +[Save action](./save/README.md) + ## What's New ### v3 * Added support for caching from GHES 3.5. diff --git a/restore/README.md b/restore/README.md new file mode 100644 index 0000000..d752902 --- /dev/null +++ b/restore/README.md @@ -0,0 +1,117 @@ +# Restore action + +The restore action restores cache just like the main `cache` action, except it doesn't save the cache. So for cases where users only want to restore cache and not save anything in return, this action is pretty helpful. Moreover, this action accepts the same set of inputs as the `cache` action. + +## Inputs + +* `path` - A list of files, directories, and wildcard patterns to cache and restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. +* `key` - String used while saving cache for restoring the cache +* `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. +> **Note** +It is very important to use the same `key` and `path` that were used by either `actions/cache` or `actions/cache/save` while saving the cache. + +### Environment Variables +* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `60`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/workarounds.md#cache-segment-restore-timeout) + +## Outputs + +* `cache-hit` - A boolean value to indicate an exact match was found for the key. +* `key` - + +> **Note** +`cache-hit` will be set to `true` only when cache hit occurs for the exact `key` match. For a partial key match via `restore-keys` or a cache miss, it will be set to `false`. + +## Use cases + +As this is a newly introduced action to give users more control in their workflows, below are some use cases where one can use this action. + +### Only restore cache + +In case you are using another workflow to create and save your cache that can be reused by other jobs in your repository, this action will take care of your restore only needs. + +``` +steps: + - uses: actions/checkout@v3 + + - uses: actions/cache/restore@v3 + id: cache + with: + path: path/to/dependencies + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Install Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: /install.sh + + - name: Build + run: /build.sh + + - name: Publish package to public + run: /publish.sh +``` + +Once the cache is restored, this action won't run any post step to do post-processing like `actions/cache` and the rest of the workflow will run as usual. + +### Save intermediate private build artifacts + +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. + + +#### Step 1 - Build the parent module and save it +``` +steps: + - uses: actions/checkout@v3 + + - name: Build + run: /build-parent-module.sh + + - uses: actions/cache/save@v3 + id: cache + with: + path: path/to/dependencies + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} +``` + +#### Step 2 - Restore the built artifact from cache using the same key and path +``` +steps: + - uses: actions/checkout@v3 + + - uses: actions/cache/restore@v3 + id: cache + with: + path: path/to/dependencies + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Install Dependencies + if: steps.cache.outputs.cache-hit != 'true' + run: /install.sh + + - name: Build + run: /build-child-module.sh + + - name: Publish package to public + run: /publish.sh +``` + +### Exit workflow on cache miss + +You can use the output of this action to exit the workflow on cache miss. This way you can restrict your workflow to only initiate the build when `cache-hit` occurs, in other words, cache with exact key is found. + +``` +steps: + - uses: actions/checkout@v3 + + - uses: actions/cache/restore@v3 + id: cache + with: + path: path/to/dependencies + key: ${{ runner.os }}-${{ hashFiles('**/lockfiles') }} + + - name: Check cache hit + if: steps.cache.outputs.cache-hit != 'true' + run: exit 1 + + - name: Build + run: /build.sh +``` \ No newline at end of file diff --git a/save/README.md b/save/README.md new file mode 100644 index 0000000..31dcb1d --- /dev/null +++ b/save/README.md @@ -0,0 +1,7 @@ +# Save action + +## Inputs + +## Outputs + +## Use cases \ No newline at end of file