@@ -3,41 +3,32 @@ const fs = require("fs");
3
3
const core = require ( "@actions/core" ) ;
4
4
const tc = require ( "@actions/tool-cache" ) ;
5
5
6
- let getCrDownloadUrl = ( version ) => {
7
- return `https://github.com/calcit-lang/calcit/releases/download/${ version } /cr` ;
8
- } ;
9
-
10
- let getCapsDownloadUrl = ( version ) => {
11
- return `https://github.com/calcit-lang/calcit/releases/download/${ version } /caps` ;
12
- } ;
13
-
14
6
const version = core . getInput ( "version" ) ;
7
+ const skipCache = core . getInput ( "skipCache" ) ;
15
8
16
- async function setup ( ) {
9
+ const binFolder = `/home/runner/bin/` ;
10
+
11
+ async function setup ( bin ) {
17
12
try {
18
13
// Get version of tool to be installed
19
14
20
- const pathToCr = await tc . downloadTool (
21
- getCrDownloadUrl ( version ) ,
22
- "/home/runner/bin/cr"
23
- ) ;
24
- const pathToCaps = await tc . downloadTool (
25
- getCapsDownloadUrl ( version ) ,
26
- "/home/runner/bin/caps"
27
- ) ;
28
-
29
- // TODO cache
30
- // https://github.com/actions/toolkit/tree/main/packages/tool-cache#cache
31
-
32
- // Expose the tool by adding it to the PATH
33
- fs . chmodSync ( pathToCr , 0o755 ) ;
34
- core . addPath ( path . dirname ( pathToCr ) ) ;
35
-
36
- console . log ( `add to path: ${ pathToCr } ` ) ;
37
-
38
- fs . chmodSync ( pathToCaps , 0o755 ) ;
39
- core . addPath ( path . dirname ( pathToCaps ) ) ;
40
- console . log ( `add to path: ${ pathToCaps } ` ) ;
15
+ let url = `https://github.com/calcit-lang/calcit/releases/download/${ version } /${ bin } ` ;
16
+
17
+ let prevCr = tc . find ( bin , version ) ;
18
+ let binPath = `${ binFolder } ${ bin } ` ;
19
+
20
+ if ( prevCr && ! skipCache ) {
21
+ fs . copyFileSync ( prevCr , binPath ) ;
22
+ console . log ( `use cached: ${ prevCr } ` ) ;
23
+ } else {
24
+ const pathToCr = await tc . downloadTool ( url , binPath ) ;
25
+ console . log ( `downloaded to: ${ pathToCr } ` ) ;
26
+ const cachedPath = await tc . cacheFile ( pathToCr , bin , bin , version ) ;
27
+ console . log ( `cached to: ${ cachedPath } ` ) ;
28
+ }
29
+ fs . chmodSync ( binPath , 0o755 ) ;
30
+ core . addPath ( binFolder ) ;
31
+ console . log ( `add binary to path: ${ binPath } ` ) ;
41
32
} catch ( e ) {
42
33
core . setFailed ( e ) ;
43
34
}
@@ -47,5 +38,6 @@ module.exports = setup;
47
38
48
39
if ( require . main === module ) {
49
40
console . log ( `Setting up Calcit ${ version } ` ) ;
50
- setup ( ) ;
41
+ setup ( "cr" ) ;
42
+ setup ( "caps" ) ;
51
43
}
0 commit comments