Skip to content

Commit aac36eb

Browse files
committed
Use @actions/cache to accelerate the Action
This opt-out feature uses the cache, so that the files are cached the first time a given artifact from a given buildId is downloaded. Subsequent attempts to download the same artifact with the same buildId should become much quicker as a consequence. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent f21a50c commit aac36eb

File tree

4 files changed

+27
-2
lines changed

4 files changed

+27
-2
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ Please note that only the `build-installers` and the `full` flavors are availabl
6666

6767
By default, this Action prints a line whenever 250 items were extracted (this does not work for the `full` flavor, where this Action is silent by default). It can be overridden by setting the input parameter `verbose`; setting it to a number will show updates whenever that many items were extracted. Setting it to `false` will suppress progress updates. Setting it to `true` will print every extracted file (this also works for the `full` flavor).
6868

69+
### Caching
70+
71+
To accelerate this Action, artifacts are cached once downloaded. This can be turned off by setting the input parameter `cache` to `false`.
72+
6973
## Developing _this_ Action
7074

7175
> First, you'll need to have a reasonably modern version of `node` handy, such as Node 12.

__tests__/main.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@ if (process.env.RUN_NETWORK_TESTS !== 'true') {
5050
INPUT_FLAVOR: 'minimal',
5151
INPUT_ARCHITECTURE: 'x86_64',
5252
INPUT_PATH: outputDirectory,
53-
INPUT_VERBOSE: '250'
53+
INPUT_VERBOSE: '250',
54+
INPUT_CACHE: 'true'
5455
}
5556
})
5657
).toEqual(0)

action.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@ inputs:
1818
required: false
1919
description: 'Whether to log files as they are extracted'
2020
default: '250'
21+
cache:
22+
required: false
23+
description: 'Use @actions/cache to accelerate this Action'
24+
default: 'true'
2125
runs:
2226
using: 'node12'
2327
main: 'dist/index.js'

main.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import * as core from '@actions/core'
22
import process from 'process'
33
import {get} from './src/downloader'
4+
import {restoreCache, saveCache} from '@actions/cache'
45

56
async function run(): Promise<void> {
67
try {
@@ -14,15 +15,30 @@ async function run(): Promise<void> {
1415
const architecture = core.getInput('architecture')
1516
const verbose = core.getInput('verbose')
1617

17-
const {artifactName, download} = await get(flavor, architecture)
18+
const {artifactName, download, id} = await get(flavor, architecture)
1819
const outputDirectory = core.getInput('path') || `C:/${artifactName}`
20+
let useCache = core.getInput('cache') === 'true'
21+
22+
try {
23+
if (useCache && (await restoreCache([outputDirectory], id))) {
24+
core.info(`Cached ${id} was successfully restored`)
25+
return
26+
}
27+
} catch (e) {
28+
core.warning(`Cannot use @actions/cache (${e})`)
29+
useCache = false
30+
}
1931

2032
core.info(`Downloading ${artifactName}`)
2133
await download(
2234
outputDirectory,
2335
verbose.match(/^\d+$/) ? parseInt(verbose) : verbose === 'true'
2436
)
2537

38+
if (useCache && !(await saveCache([outputDirectory], id))) {
39+
core.warning(`Failed to cache ${id}`)
40+
}
41+
2642
// Set up PATH so that Git for Windows' SDK's `bash.exe` is found
2743
core.addPath(`${outputDirectory}/usr/bin`)
2844
core.exportVariable(

0 commit comments

Comments
 (0)