From 96f024b3bc1d81975405f50d50b57d4c50a85a08 Mon Sep 17 00:00:00 2001 From: Sergey Dolin Date: Wed, 23 Aug 2023 07:43:30 +0200 Subject: [PATCH] Add advanced use cases to examples section --- examples.md | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) diff --git a/examples.md b/examples.md index 1bcde91..bf1a47b 100644 --- a/examples.md +++ b/examples.md @@ -15,6 +15,8 @@ - [Linux](#linux-1) - [macOS](#macos-1) - [Windows](#windows-2) +- [Go - Advanced](#go---advanced) + - [Do not cache dependencies or intermediate build files](#do-not-cache-dependencies-or-intermediate-build-files) - [Haskell - Cabal](#haskell---cabal) - [Haskell - Stack](#haskell---stack) - [Java - Gradle](#java---gradle) @@ -40,6 +42,9 @@ - [Swift - Swift Package Manager](#swift---swift-package-manager) - [Swift - Mint](#swift---mint) - [* - Bazel](#---bazel) +- [Common use cases](#common-use-cases) + - [Restore-only caches](#restore-only-caches) + - [Automatically detect cached paths](#automatically-detect-cached-paths) ## C# - NuGet @@ -221,6 +226,10 @@ steps: ${{ runner.os }}-go- ``` +### Do not cache dependencies or intermediate build files +```yaml +``` + ## Haskell - Cabal We cache the elements of the Cabal store separately, as the entirety of `~/.cabal` can grow very large for projects with many dependencies. @@ -690,3 +699,37 @@ steps: ${{ runner.os }}-bazel- - run: bazelisk test //... ``` +## Common use cases + +### Restore-only caches +If there are several builds on the same repo it might make sense to create a cache in one build and use it in the +others. The action [actions/cache/restore](https://github.com/actions/cache/blob/main/restore/README.md#only-restore-cache) +should be used in this case. + +### Automatically detect cached paths +[Defining outputs for jobs](https://docs.github.com/en/actions/using-jobs/defining-outputs-for-jobs) can be used to +automatically detect paths to cache and use them to configure `actions/cache` action. + +```yaml +- uses: actions/setup-go@v4 + with: + go-version: "1.20.x" + cache: false + +- name: Get Go cached paths + id: find-cached-paths + run: | + echo "cache=$(go env GOCACHE)" >> $GITHUB_OUTPUT + echo "modcache=$(go env GOMODCACHE)" >> $GITHUB_OUTPUT + +- name: Set up cache + uses: actions/cache@v3 + needs: find-cached-paths + with: + path: | + ${{ needs.find-cached-paths.outputs.cache }} + ${{ needs.find-cached-paths.outputs.modcache }} + key: setup-go-${{ runner.os }}-go-${{ hashFiles('go.sum go.mod') }} + restore-keys: | + setup-go-${{ runner.os }}-go- +``` \ No newline at end of file