|
| 1 | +# GitHub.Actions.ToolCache |
| 2 | + |
| 3 | +> Functions necessary for downloading and caching tools. |
| 4 | +
|
| 5 | +This module exposes bindings to the [@actions/tool-cache package](https://github.com/actions/toolkit/tree/main/packages/tool-cache). |
| 6 | + |
| 7 | +## Usage |
| 8 | + |
| 9 | +#### Download |
| 10 | + |
| 11 | +You can use this to download tools (or other files) from a download URL: |
| 12 | + |
| 13 | +```purescript |
| 14 | +
|
| 15 | +node12Path <- ToolCache.downloadTool "https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz" |
| 16 | +``` |
| 17 | + |
| 18 | +#### Extract |
| 19 | + |
| 20 | +These can then be extracted in platform specific ways: |
| 21 | + |
| 22 | +```purescript |
| 23 | +const tc = require('@actions/tool-cache'); |
| 24 | +
|
| 25 | +node12ExtractedFolder <- case platform of |
| 26 | + Just Win32 -> do |
| 27 | + node12Path <- ToolCache.downloadTool' "https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.zip" |
| 28 | + ToolCache.extractZip' node12Path |
| 29 | + Just Darwin -> do |
| 30 | + node12Path <- ToolCache.downloadTool' "https://nodejs.org/dist/v12.7.0/node-v12.7.0.pkg" |
| 31 | + ToolCache.extractXar' node12Path |
| 32 | + _ -> do |
| 33 | + node12Path <- ToolCache.downloadTool' "https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz" |
| 34 | + ToolCache.extractTar node12Path |
| 35 | +``` |
| 36 | + |
| 37 | +#### Cache |
| 38 | + |
| 39 | +Finally, you can cache these directories in our tool-cache. This is useful if you want to switch back and forth between versions of a tool, or save a tool between runs for self-hosted runners. |
| 40 | + |
| 41 | +You'll often want to add it to the path as part of this step: |
| 42 | + |
| 43 | +```purescript |
| 44 | +const tc = require('@actions/tool-cache'); |
| 45 | +const core = require('@actions/core'); |
| 46 | +
|
| 47 | +example = do |
| 48 | + node12Path <- ToolCache.downloadTool' "https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz" |
| 49 | + node12ExtractedFolder <- ToolCache.extractTar node12Path |
| 50 | + cachedPath <- ToolCache.cacheDir' { sourceDir: node12ExtractedFolder, tool: "node", version: "12.7.0" } |
| 51 | + liftEffect $ do |
| 52 | + Core.addPath cachedPath |
| 53 | +``` |
| 54 | + |
| 55 | +You can also cache files for reuse. |
| 56 | + |
| 57 | +```purescript |
| 58 | +ToolTache.cachefile' { sourceFile: "path/to/exe", targetFile: "destFileName.exe", tool: "myExeName", version: "1.1.0"} |
| 59 | +``` |
| 60 | + |
| 61 | +#### Find |
| 62 | + |
| 63 | +Finally, you can find directories and files you've previously cached: |
| 64 | + |
| 65 | +```purescript |
| 66 | +nodeDirectory <- ToolCache.find' { toolName: "node", versionSpec "12.x" } |
| 67 | +liftEffect $ Core.addPath nodeDirectory |
| 68 | +``` |
| 69 | + |
| 70 | +You can even find all cached versions of a tool: |
| 71 | + |
| 72 | +```purescript |
| 73 | +allNodeVersion <- ToolCache.findAllVersions "node" |
| 74 | +``` |
0 commit comments