mirror of
				https://github.com/actions/cache.git
				synced 2025-11-04 03:34:00 +00:00 
			
		
		
		
	add R Markdown - knitr cache example & show default booleans
This commit is contained in:
		
							parent
							
								
									14bc367517
								
							
						
					
					
						commit
						e5e58a06aa
					
				@ -31,8 +31,8 @@ If you are using this inside a container, a POSIX-compliant `tar` needs to be in
 | 
				
			|||||||
* `key` - An explicit key for restoring and saving the cache
 | 
					* `key` - An explicit key for restoring and saving the cache
 | 
				
			||||||
* `restore-keys` - An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note
 | 
					* `restore-keys` - An ordered list of keys to use for restoring stale cache if no cache hit occurred for key. Note
 | 
				
			||||||
`cache-hit` returns false in this case.
 | 
					`cache-hit` returns false in this case.
 | 
				
			||||||
* `reeval` - A boolean. Whether to reevaluate the `key` argument in the action's post run script when saving cache. Set to `true` if you would like your cache key set after your job's steps are complete.
 | 
					* `reeval` - A boolean. Default set to `false`. Whether to reevaluate the `key` argument in the action's post run script when saving cache. Set to `true` if you would like your cache key set after your job's steps are complete.
 | 
				
			||||||
* `only-restore` - A boolean. Whether to only perform cache restoration and not the save post run script.
 | 
					* `only-restore` - A boolean. Default set to `false`. Whether to only perform cache restoration and not the save post run script.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
### Outputs
 | 
					### Outputs
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										118
									
								
								examples.md
									
									
									
									
									
								
							
							
						
						
									
										118
									
								
								examples.md
									
									
									
									
									
								
							@ -1,42 +1,44 @@
 | 
				
			|||||||
# Examples
 | 
					# Examples
 | 
				
			||||||
 | 
					
 | 
				
			||||||
- [C# - NuGet](#c---nuget)
 | 
					- [Examples](#examples)
 | 
				
			||||||
- [D - DUB](#d---dub)
 | 
					  - [C# - NuGet](#c---nuget)
 | 
				
			||||||
  - [POSIX](#posix)
 | 
					  - [D - DUB](#d---dub)
 | 
				
			||||||
  - [Windows](#windows)
 | 
					    - [POSIX](#posix)
 | 
				
			||||||
- [Deno](#deno)
 | 
					    - [Windows](#windows)
 | 
				
			||||||
  - [Linux](#linux)
 | 
					  - [Deno](#deno)
 | 
				
			||||||
  - [macOS](#macos)
 | 
					    - [Linux](#linux)
 | 
				
			||||||
  - [Windows](#windows-1)
 | 
					    - [macOS](#macos)
 | 
				
			||||||
- [Elixir - Mix](#elixir---mix)
 | 
					    - [Windows](#windows-1)
 | 
				
			||||||
- [Erlang - Rebar3](#erlang--rebar3)
 | 
					  - [Elixir - Mix](#elixir---mix)
 | 
				
			||||||
- [Go - Modules](#go---modules)
 | 
					  - [Erlang - Rebar3](#erlang---rebar3)
 | 
				
			||||||
  - [Linux](#linux-1)
 | 
					  - [Go - Modules](#go---modules)
 | 
				
			||||||
  - [macOS](#macos-1)
 | 
					    - [Linux](#linux-1)
 | 
				
			||||||
  - [Windows](#windows-2)
 | 
					    - [macOS](#macos-1)
 | 
				
			||||||
- [Haskell - Cabal](#haskell---cabal)
 | 
					    - [Windows](#windows-2)
 | 
				
			||||||
- [Haskell - Stack](#haskell---stack)
 | 
					  - [Haskell - Cabal](#haskell---cabal)
 | 
				
			||||||
- [Java - Gradle](#java---gradle)
 | 
					  - [Haskell - Stack](#haskell---stack)
 | 
				
			||||||
- [Java - Maven](#java---maven)
 | 
					  - [Java - Gradle](#java---gradle)
 | 
				
			||||||
- [Node - npm](#node---npm)
 | 
					  - [Java - Maven](#java---maven)
 | 
				
			||||||
- [Node - Lerna](#node---lerna)
 | 
					  - [Node - npm](#node---npm)
 | 
				
			||||||
- [Node - Yarn](#node---yarn)
 | 
					  - [Node - Lerna](#node---lerna)
 | 
				
			||||||
- [Node - Yarn 2](#node---yarn-2)
 | 
					  - [Node - Yarn](#node---yarn)
 | 
				
			||||||
- [OCaml/Reason - esy](#ocamlreason---esy)
 | 
					  - [Node - Yarn 2](#node---yarn-2)
 | 
				
			||||||
- [PHP - Composer](#php---composer)
 | 
					  - [OCaml/Reason - esy](#ocamlreason---esy)
 | 
				
			||||||
- [Python - pip](#python---pip)
 | 
					  - [PHP - Composer](#php---composer)
 | 
				
			||||||
  - [Simple example](#simple-example)
 | 
					  - [Python - pip](#python---pip)
 | 
				
			||||||
  - [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
 | 
					    - [Simple example](#simple-example)
 | 
				
			||||||
  - [Multiple OS's in a workflow with a matrix](#multiple-oss-in-a-workflow-with-a-matrix)
 | 
					    - [Multiple OS's in a workflow](#multiple-oss-in-a-workflow)
 | 
				
			||||||
  - [Using pip to get cache location](#using-pip-to-get-cache-location)
 | 
					    - [Multiple OS's in a workflow with a matrix](#multiple-oss-in-a-workflow-with-a-matrix)
 | 
				
			||||||
- [Python - pipenv](#python---pipenv)
 | 
					    - [Using pip to get cache location](#using-pip-to-get-cache-location)
 | 
				
			||||||
- [R - renv](#r---renv)
 | 
					  - [Python - pipenv](#python---pipenv)
 | 
				
			||||||
- [Ruby - Bundler](#ruby---bundler)
 | 
					  - [R - renv](#r---renv)
 | 
				
			||||||
- [Rust - Cargo](#rust---cargo)
 | 
					  - [R Markdown - knitr cache](#r-markdown---knitr-cache)
 | 
				
			||||||
- [Scala - SBT](#scala---sbt)
 | 
					  - [Ruby - Bundler](#ruby---bundler)
 | 
				
			||||||
- [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
 | 
					  - [Rust - Cargo](#rust---cargo)
 | 
				
			||||||
- [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
 | 
					  - [Scala - SBT](#scala---sbt)
 | 
				
			||||||
- [Swift - Swift Package Manager](#swift---swift-package-manager)
 | 
					  - [Swift, Objective-C - Carthage](#swift-objective-c---carthage)
 | 
				
			||||||
 | 
					  - [Swift, Objective-C - CocoaPods](#swift-objective-c---cocoapods)
 | 
				
			||||||
 | 
					  - [Swift - Swift Package Manager](#swift---swift-package-manager)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## C# - NuGet
 | 
					## C# - NuGet
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -515,6 +517,48 @@ For renv, the cache directory will vary by OS. The `RENV_PATHS_ROOT` environment
 | 
				
			|||||||
    restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-
 | 
					    restore-keys: ${{ steps.get-version.outputs.os-version }}-${{ steps.get-version.outputs.r-version }}-${{inputs.cache-version }}-
 | 
				
			||||||
```
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					## R Markdown - knitr cache
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					For [R Markdown](https://bookdown.org/yihui/rmarkdown-cookbook/cache.html) and [Quarto](https://quarto.org/docs/computations/caching.html#knitr-cache), [knitr](https://yihui.org/knitr/options/#cache) creates a directory of cached code chunk variables & output for chunks where the chunk option `cache=TRUE` is set. The cache directory is typically located in the directory of the input file being rendered. It is named by concating the input `.Rmd` or `.qmd` file name with `_cache` appended.
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					See the composite action implementation [prncevince/r-actions/setup-knitr-cache](https://github.com/prncevince/r-actions/tree/main/setup-knitr-cache) and corresponding [example](https://github.com/prncevince/r-actions/blob/main/.github/workflows/knitr-cache.yaml) [workflows](https://github.com/prncevince/test-workflow-knitr-cache/blob/main/.github/workflows/knitr-cache.yaml).
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Here, we set `reeval` to `true`. This instructs the action to reevalute the cache `key` input variable before saving the cache during the action's post script run when determing if we have met a cache hit. When using knitr caching, we do this because the knitr cache is typically ignored from the Git repo, and invalidation is determined by much more than a diff on the input file. Thus, it makes more sense to evaluate our cache key after knitr code chunk evaluation has completed. For more info on knitr cache invalidation, see [On Cache Invalidation](https://yihui.org/en/2018/06/cache-invalidation/). 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					```yaml
 | 
				
			||||||
 | 
					jobs:
 | 
				
			||||||
 | 
					  setup-knitr-cache:
 | 
				
			||||||
 | 
					    - uses: actions/checkout@v3
 | 
				
			||||||
 | 
					    - uses: r-lib/actions/setup-pandoc@v2
 | 
				
			||||||
 | 
					    - name: Install system dependencies on Linux
 | 
				
			||||||
 | 
					      if: runner.os == 'Linux'
 | 
				
			||||||
 | 
					      run: |
 | 
				
			||||||
 | 
					        sudo apt-get update -y
 | 
				
			||||||
 | 
					        sudo apt-get install -y libcurl4-openssl-dev libharfbuzz-dev libfribidi-dev
 | 
				
			||||||
 | 
					    - uses: r-lib/actions/setup-r@v2
 | 
				
			||||||
 | 
					      with:
 | 
				
			||||||
 | 
					        r-version: latest
 | 
				
			||||||
 | 
					    - name: Get R and OS version
 | 
				
			||||||
 | 
					      id: restore-partials
 | 
				
			||||||
 | 
					      shell: Rscript {0}
 | 
				
			||||||
 | 
					      run: |
 | 
				
			||||||
 | 
					        cat("##[set-output name=os-version;]", sessionInfo()$running, "\n", sep = "")
 | 
				
			||||||
 | 
					        cat("##[set-output name=r-version;]", R.Version()$version.string, sep = "")
 | 
				
			||||||
 | 
					    - name: Install R Markdown
 | 
				
			||||||
 | 
					      shell: Rscript {0}
 | 
				
			||||||
 | 
					      run: install.packages("rmarkdown")
 | 
				
			||||||
 | 
					    - name: Restore knitr cache
 | 
				
			||||||
 | 
					      uses: actions/cache@v3
 | 
				
			||||||
 | 
					      with:
 | 
				
			||||||
 | 
					        reeval: true
 | 
				
			||||||
 | 
					        path: rmd-file-name_cache
 | 
				
			||||||
 | 
					        key: ${{ github.action }}-${{ github.workflow }}-${{ steps.restore-partials.outputs.os-version }}-${{ steps.restore-partials.outputs.r-version }}-${{ hashFiles(format('{0}/**', rmd-file-name_cache)) }}
 | 
				
			||||||
 | 
					        restore-keys: ${{ github.action }}-${{ github.workflow }}-${{ steps.restore-partials.outputs.os-version }}-${{ steps.restore-partials.outputs.r-version }}-
 | 
				
			||||||
 | 
					    - name: Render R Markdown & Build knitr cache
 | 
				
			||||||
 | 
					      shell: Rscript {0}
 | 
				
			||||||
 | 
					      run: rmarkdown::render(input = "rmd-file-name.Rmd")
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
## Ruby - Bundler
 | 
					## Ruby - Bundler
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Caching gems with Bundler correctly is not trivial and just using `actions/cache`
 | 
					Caching gems with Bundler correctly is not trivial and just using `actions/cache`
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user