github.com/jfrog/frogbot@v1.1.1-0.20231221090046-821a26f50338/action/node_modules/@actions/tool-cache/README.md (about) 1 # `@actions/tool-cache` 2 3 > Functions necessary for downloading and caching tools. 4 5 ## Usage 6 7 #### Download 8 9 You can use this to download tools (or other files) from a download URL: 10 11 ```js 12 const tc = require('@actions/tool-cache'); 13 14 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz'); 15 ``` 16 17 #### Extract 18 19 These can then be extracted in platform specific ways: 20 21 ```js 22 const tc = require('@actions/tool-cache'); 23 24 if (process.platform === 'win32') { 25 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.zip'); 26 const node12ExtractedFolder = await tc.extractZip(node12Path, 'path/to/extract/to'); 27 28 // Or alternately 29 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-win-x64.7z'); 30 const node12ExtractedFolder = await tc.extract7z(node12Path, 'path/to/extract/to'); 31 } 32 else if (process.platform === 'darwin') { 33 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0.pkg'); 34 const node12ExtractedFolder = await tc.extractXar(node12Path, 'path/to/extract/to'); 35 } 36 else { 37 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz'); 38 const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to'); 39 } 40 ``` 41 42 #### Cache 43 44 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. 45 46 You'll often want to add it to the path as part of this step: 47 48 ```js 49 const tc = require('@actions/tool-cache'); 50 const core = require('@actions/core'); 51 52 const node12Path = await tc.downloadTool('https://nodejs.org/dist/v12.7.0/node-v12.7.0-linux-x64.tar.gz'); 53 const node12ExtractedFolder = await tc.extractTar(node12Path, 'path/to/extract/to'); 54 55 const cachedPath = await tc.cacheDir(node12ExtractedFolder, 'node', '12.7.0'); 56 core.addPath(cachedPath); 57 ``` 58 59 You can also cache files for reuse. 60 61 ```js 62 const tc = require('@actions/tool-cache'); 63 64 const cachedPath = await tc.cacheFile('path/to/exe', 'destFileName.exe', 'myExeName', '1.1.0'); 65 ``` 66 67 #### Find 68 69 Finally, you can find directories and files you've previously cached: 70 71 ```js 72 const tc = require('@actions/tool-cache'); 73 const core = require('@actions/core'); 74 75 const nodeDirectory = tc.find('node', '12.x', 'x64'); 76 core.addPath(nodeDirectory); 77 ``` 78 79 You can even find all cached versions of a tool: 80 81 ```js 82 const tc = require('@actions/tool-cache'); 83 84 const allNodeVersions = tc.findAllVersions('node'); 85 console.log(`Versions of node available: ${allNodeVersions}`); 86 ```