From 77eb7eb198e1383478da175398ace52efd5464d0 Mon Sep 17 00:00:00 2001 From: Lovepreet Singh Date: Thu, 23 Feb 2023 11:59:31 +0530 Subject: [PATCH 1/9] Update Cross-OS Caching tips --- tips-and-workarounds.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tips-and-workarounds.md b/tips-and-workarounds.md index 7c1bb4a..cb57809 100644 --- a/tips-and-workarounds.md +++ b/tips-and-workarounds.md @@ -21,10 +21,10 @@ Reusing cache across feature branches is not allowed today to provide cache [iso ## Cross OS cache From `v3.2.3` cache is cross-os compatible when `enableCrossOsArchive` input is passed as true. This means that a cache created on `ubuntu-latest` or `mac-latest` can be used by `windows-latest` and vice versa, provided the workflow which runs on `windows-latest` have input `enableCrossOsArchive` as true. This is useful to cache dependencies which are independent of the runner platform. This will help reduce the consumption of the cache quota and help build for multiple platforms from the same cache. Things to keep in mind while using this feature: -- Only cache those files which are compatible across OSs. -- Caching symlinks might cause issues while restoration as they work differently on different OSs. -- Only cache files from within your github workspace directory. -- Avoid using directory pointers such as `${{ github.workspace }}` or `~` (home) which eventually evaluate to an absolute path and will not match across OSs. +- Only cache files that are compatible across OSs. +- Caching symlinks might cause issues while restoring them as they behave differently on different OSs. +- Be mindful when caching files from outside your github workspace directory as the directory is located at different places across OS. +- Avoid using directory pointers such as `${{ github.workspace }}` or `~` (home) which eventually evaluate to an absolute path that does not match across OSs. ## Force deletion of caches overriding default cache eviction policy Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches. From 789348181295a042e491d6810ced9549adabaf10 Mon Sep 17 00:00:00 2001 From: Bishal Prasad Date: Sat, 11 Mar 2023 21:32:05 +0530 Subject: [PATCH 2/9] Change two new actions mention as quoted text --- README.md | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9852657..8ab46a5 100644 --- a/README.md +++ b/README.md @@ -2,11 +2,9 @@ This action allows caching dependencies and build outputs to improve workflow execution time. -Two other actions are available in addition to the primary `cache` action: - -* [Restore action](./restore/README.md) - -* [Save action](./save/README.md) +>Two other actions are available in addition to the primary `cache` action: +>* [Restore action](./restore/README.md) +>* [Save action](./save/README.md) [![Tests](https://github.com/actions/cache/actions/workflows/workflow.yml/badge.svg)](https://github.com/actions/cache/actions/workflows/workflow.yml) From 4b381be638ae4084d217360e1d78b875ea63721e Mon Sep 17 00:00:00 2001 From: David Bernard Date: Thu, 29 Apr 2021 19:58:13 +0200 Subject: [PATCH 3/9] Add example for Bazel --- examples.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/examples.md b/examples.md index 05482ce..7319a10 100644 --- a/examples.md +++ b/examples.md @@ -39,6 +39,7 @@ - [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods) - [Swift - Swift Package Manager](#swift---swift-package-manager) - [Swift - Mint](#swift---mint) +- [* - Bazel](#---bazel) ## C# - NuGet @@ -657,3 +658,17 @@ steps: restore-keys: | ${{ runner.os }}-mint- ``` + +## * - Bazel + +Bazel cache has a good handle to check if cached content should be rebuild or not based on its inputs like a hash(command + files). So using the latest cache of the branch is enough, no need to suffix with `hashFiles('**/...')`. + +```yaml +- name: Cache Bazel + uses: actions/cache@v2 + with: + path: | + ~/.cache/bazelisk + ~/.cache/bazel + key: ${{ runner.os }}-bazel +``` From ef11f54eee2bfc69a7adcf6cd1b0423068dce940 Mon Sep 17 00:00:00 2001 From: Michael Vorburger Date: Sat, 11 Mar 2023 19:40:53 +0100 Subject: [PATCH 4/9] Fix example for Bazel --- examples.md | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/examples.md b/examples.md index 7319a10..4136623 100644 --- a/examples.md +++ b/examples.md @@ -661,14 +661,18 @@ steps: ## * - Bazel -Bazel cache has a good handle to check if cached content should be rebuild or not based on its inputs like a hash(command + files). So using the latest cache of the branch is enough, no need to suffix with `hashFiles('**/...')`. - ```yaml - name: Cache Bazel - uses: actions/cache@v2 + uses: actions/cache@v3 with: path: | - ~/.cache/bazelisk - ~/.cache/bazel - key: ${{ runner.os }}-bazel + ~/.cache/bazel # Linux + /private/var/tmp/_bazel_runner/ # macOS + # TODO Add Windows if you know where it is, based on https://bazel.build/remote/output-directories + key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }} + restore-keys: | + ${{ runner.os }}-bazel- +- run: bazelisk test //... ``` + +[`bazelisk`](https://github.com/bazelbuild/bazelisk) does not have be to separately downloaded and installed because it's already included in GitHub's `ubuntu-latest` base image. From cb865c1889904202309ea60044103510aa7e59fa Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 13 Mar 2023 11:02:55 +0530 Subject: [PATCH 5/9] Fixed readme with new segment timeout values (#1133) --- README.md | 2 +- tips-and-workarounds.md | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 171cee3..b844bc4 100644 --- a/README.md +++ b/README.md @@ -27,7 +27,7 @@ See ["Caching dependencies to speed up workflows"](https://docs.github.com/en/ac * Fixed cache not working with github workspace directory or current directory. * Fixed the download stuck problem by introducing a timeout of 1 hour for cache downloads. * Fix zstd not working for windows on gnu tar in issues. -* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 60 minutes. +* Allowing users to provide a custom timeout as input for aborting download of a cache segment using an environment variable `SEGMENT_DOWNLOAD_TIMEOUT_MINS`. Default is 10 minutes. * New actions are available for granular control over caches - [restore](restore/action.yml) and [save](save/action.yml). * Support cross-os caching as an opt-in feature. See [Cross OS caching](./tips-and-workarounds.md#cross-os-cache) for more info. * Added option to fail job on cache miss. See [Exit workflow on cache miss](./restore/README.md#exit-workflow-on-cache-miss) for more info. diff --git a/tips-and-workarounds.md b/tips-and-workarounds.md index a76560b..5addf67 100644 --- a/tips-and-workarounds.md +++ b/tips-and-workarounds.md @@ -1,10 +1,15 @@ +# Tips and workarounds + ## Cache segment restore timeout + A cache gets downloaded in multiple segments of fixed sizes (`1GB` for a `32-bit` runner and `2GB` for a `64-bit` runner). Sometimes, a segment download gets stuck which causes the workflow job to be stuck forever and fail. Version `v3.0.8` of `actions/cache` introduces a segment download timeout. The segment download timeout will allow the segment download to get aborted and hence allow the job to proceed with a cache miss. -Default value of this timeout is 60 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. +Default value of this timeout is 10 minutes and can be customized by specifying an [environment variable](https://docs.github.com/en/actions/learn-github-actions/environment-variables) named `SEGMENT_DOWNLOAD_TIMEOUT_MINS` with timeout value in minutes. ## Update a cache + A cache today is immutable and cannot be updated. But some use cases require the cache to be saved even though there was a "hit" during restore. To do so, use a `key` which is unique for every run and use `restore-keys` to restore the nearest cache. For example: + ```yaml - name: update cache on every commit uses: actions/cache@v3 @@ -13,23 +18,28 @@ A cache today is immutable and cannot be updated. But some use cases require the key: primes-${{ runner.os }}-${{ github.run_id }} # Can use time based key as well restore-keys: | primes-${{ runner.os }} - ``` + ``` + Please note that this will create a new cache on every run and hence will consume the cache [quota](./README.md#cache-limits). ## Use cache across feature branches + Reusing cache across feature branches is not allowed today to provide cache [isolation](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache). However if both feature branches are from the default branch, a good way to achieve this is to ensure that the default branch has a cache. This cache will then be consumable by both feature branches. ## Cross OS cache + From `v3.2.3` cache is cross-os compatible when `enableCrossOsArchive` input is passed as true. This means that a cache created on `ubuntu-latest` or `mac-latest` can be used by `windows-latest` and vice versa, provided the workflow which runs on `windows-latest` have input `enableCrossOsArchive` as true. This is useful to cache dependencies which are independent of the runner platform. This will help reduce the consumption of the cache quota and help build for multiple platforms from the same cache. Things to keep in mind while using this feature: + - Only cache those files which are compatible across OSs. - Caching symlinks might cause issues while restoration as they work differently on different OSs. -- Only cache files from within your github workspace directory. +- Only cache files from within your github workspace directory. - Avoid using directory pointers such as `${{ github.workspace }}` or `~` (home) which eventually evaluate to an absolute path and will not match across OSs. ## Force deletion of caches overriding default cache eviction policy + Caches have [branch scope restriction](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#restrictions-for-accessing-a-cache) in place. This means that if caches for a specific branch are using a lot of storage quota, it may result into more frequently used caches from `default` branch getting thrashed. For example, if there are many pull requests happening on a repo and are creating caches, these cannot be used in default branch scope but will still occupy a lot of space till they get cleaned up by [eviction policy](https://docs.github.com/en/actions/using-workflows/caching-dependencies-to-speed-up-workflows#usage-limits-and-eviction-policy). But sometime we want to clean them up on a faster cadence so as to ensure default branch is not thrashing. In order to achieve this, [gh-actions-cache cli](https://github.com/actions/gh-actions-cache/) can be used to delete caches for specific branches. -This workflow uses `gh-actions-cache` to delete all the caches created by a branch. +This workflow uses `gh-actions-cache` to delete all the caches created by a branch.
Example @@ -74,4 +84,5 @@ jobs: env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} ``` +
From 57014a2baae92efb4c2ce19e2d1d2b47cca10081 Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 13 Mar 2023 12:02:23 +0530 Subject: [PATCH 6/9] Readme fixes (#1134) * Update README.md * Update README.md --- README.md | 2 +- restore/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b844bc4..6cb3df7 100644 --- a/README.md +++ b/README.md @@ -58,7 +58,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir #### 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/tips-and-workarounds.md#cache-segment-restore-timeout) +* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout) ### Outputs diff --git a/restore/README.md b/restore/README.md index 6571aef..f125af7 100644 --- a/restore/README.md +++ b/restore/README.md @@ -23,7 +23,7 @@ The restore action restores a cache. It works similarly to the `cache` action ex ### 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/tips-and-workarounds.md#cache-segment-restore-timeout) +* `SEGMENT_DOWNLOAD_TIMEOUT_MINS` - Segment download timeout (in minutes, default `10`) to abort download of the segment if not completed in the defined number of minutes. [Read more](https://github.com/actions/cache/blob/main/tips-and-workarounds.md#cache-segment-restore-timeout) ## Use cases From 4b8460cbff54c080fe0d466350af7753cbef5894 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Mon, 13 Mar 2023 10:52:18 +0100 Subject: [PATCH 7/9] Create separate Linux/macOS examples for Bazel --- examples.md | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/examples.md b/examples.md index 4136623..4a07f6b 100644 --- a/examples.md +++ b/examples.md @@ -661,18 +661,32 @@ steps: ## * - Bazel +[`bazelisk`](https://github.com/bazelbuild/bazelisk) does not have be to separately downloaded and installed because it's already included in GitHub's `ubuntu-latest` base image. + +### Linux + ```yaml - name: Cache Bazel uses: actions/cache@v3 with: path: | - ~/.cache/bazel # Linux - /private/var/tmp/_bazel_runner/ # macOS - # TODO Add Windows if you know where it is, based on https://bazel.build/remote/output-directories + ~/.cache/bazel key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }} restore-keys: | ${{ runner.os }}-bazel- - run: bazelisk test //... ``` -[`bazelisk`](https://github.com/bazelbuild/bazelisk) does not have be to separately downloaded and installed because it's already included in GitHub's `ubuntu-latest` base image. +### macOS + +```yaml +- name: Cache Bazel + uses: actions/cache@v3 + with: + path: | + /private/var/tmp/_bazel_runner/ + key: ${{ runner.os }}-bazel-${{ hashFiles('.bazelversion', '.bazelrc', 'WORKSPACE', 'WORKSPACE.bazel', 'MODULE.bazel') }} + restore-keys: | + ${{ runner.os }}-bazel- +- run: bazelisk test //... +``` From 84995e0d91a927aa8da027221d329f84446b8c9b Mon Sep 17 00:00:00 2001 From: Sankalp Kotewar <98868223+kotewar@users.noreply.github.com> Date: Mon, 13 Mar 2023 16:43:13 +0530 Subject: [PATCH 8/9] Updated description of the lookup-only input for main action (#1130) * Updated description of the lookup-only input for main action * Update README.md Co-authored-by: Bishal Prasad * Update README.md --------- Co-authored-by: Bishal Prasad --- README.md | 2 +- restore/README.md | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6cb3df7..f71eb50 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ If you are using a `self-hosted` Windows runner, `GNU tar` and `zstd` are requir * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `enableCrossOsArchive` - An optional boolean when enabled, allows Windows runners to save or restore caches that can be restored or saved respectively on other platforms. Default: `false` * `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` -* `lookup-only` - Skip downloading cache. Only check if cache entry exists. Default: `false` +* `lookup-only` - If true, only checks if cache entry exists and skips download. Does not change save cache behavior. Default: `false` #### Environment Variables diff --git a/restore/README.md b/restore/README.md index f125af7..a7203e9 100644 --- a/restore/README.md +++ b/restore/README.md @@ -10,7 +10,7 @@ The restore action restores a cache. It works similarly to the `cache` action ex * `path` - A list of files, directories, and wildcard patterns to restore. See [`@actions/glob`](https://github.com/actions/toolkit/tree/main/packages/glob) for supported patterns. * `restore-keys` - An ordered list of prefix-matched keys to use for restoring stale cache if no cache hit occurred for key. * `fail-on-cache-miss` - Fail the workflow if cache entry is not found. Default: `false` -* `lookup-only` - Check if a cache entry exists for the given input(s) (key, restore-keys) without downloading the cache. Default: `false` +* `lookup-only` - If true, only checks if cache entry exists and skips download. Default: `false` ### Outputs From 6f1f1e10f3bad9846e298e7670d605f5674ddd17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vorburger=20=E2=9B=91=EF=B8=8F?= Date: Mon, 13 Mar 2023 14:26:31 +0100 Subject: [PATCH 9/9] Clarify that macos-latest image has bazelisk --- examples.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples.md b/examples.md index 4a07f6b..1bcde91 100644 --- a/examples.md +++ b/examples.md @@ -661,7 +661,7 @@ steps: ## * - Bazel -[`bazelisk`](https://github.com/bazelbuild/bazelisk) does not have be to separately downloaded and installed because it's already included in GitHub's `ubuntu-latest` base image. +[`bazelisk`](https://github.com/bazelbuild/bazelisk) does not have be to separately downloaded and installed because it's already included in GitHub's `ubuntu-latest` and `macos-latest` base images. ### Linux