11const os = require ( 'os' )
22const path = require ( 'path' )
3- const core = require ( '@actions/core' )
43const exec = require ( '@actions/exec' )
54const io = require ( '@actions/io' )
65const tc = require ( '@actions/tool-cache' )
@@ -17,24 +16,33 @@ export function getAvailableVersions(platform, engine) {
1716}
1817
1918export async function install ( platform , engine , version ) {
20- return await downloadAndExtract ( platform , engine , version )
21- }
22-
23- async function downloadAndExtract ( platform , engine , version ) {
24- let rubyPrefix
25- if ( common . shouldExtractInToolCache ( engine , version ) ) {
26- rubyPrefix = common . getToolCacheRubyPrefix ( platform , version )
19+ let rubyPrefix , inToolCache
20+ if ( common . shouldUseToolCache ( engine , version ) ) {
21+ inToolCache = tc . find ( 'Ruby' , version )
22+ if ( inToolCache ) {
23+ rubyPrefix = inToolCache
24+ } else {
25+ rubyPrefix = common . getToolCacheRubyPrefix ( platform , version )
26+ }
2727 } else if ( windows ) {
2828 rubyPrefix = path . join ( `${ common . drive } :` , `${ engine } -${ version } ` )
2929 } else {
3030 rubyPrefix = path . join ( os . homedir ( ) , '.rubies' , `${ engine } -${ version } ` )
3131 }
3232
33- const parentDir = path . dirname ( rubyPrefix )
34-
3533 // Set the PATH now, so the MSYS2 'tar' is in Path on Windows
3634 common . setupPath ( [ path . join ( rubyPrefix , 'bin' ) ] )
3735
36+ if ( ! inToolCache ) {
37+ await downloadAndExtract ( platform , engine , version , rubyPrefix ) ;
38+ }
39+
40+ return rubyPrefix
41+ }
42+
43+ async function downloadAndExtract ( platform , engine , version , rubyPrefix ) {
44+ const parentDir = path . dirname ( rubyPrefix )
45+
3846 await io . rmRF ( rubyPrefix )
3947 await io . mkdirP ( parentDir )
4048
@@ -47,13 +55,11 @@ async function downloadAndExtract(platform, engine, version) {
4755 await common . measure ( 'Extracting Ruby' , async ( ) => {
4856 if ( windows ) {
4957 // Windows 2016 doesn't have system tar, use MSYS2's, it needs unix style paths
50- await exec . exec ( 'tar' , [ '-xz' , '-C' , common . win2nix ( parentDir ) , '-f' , common . win2nix ( downloadPath ) ] )
58+ await exec . exec ( 'tar' , [ '-xz' , '-C' , common . win2nix ( parentDir ) , '-f' , common . win2nix ( downloadPath ) ] )
5159 } else {
52- await exec . exec ( 'tar' , [ '-xz' , '-C' , parentDir , '-f' , downloadPath ] )
60+ await exec . exec ( 'tar' , [ '-xz' , '-C' , parentDir , '-f' , downloadPath ] )
5361 }
5462 } )
55-
56- return rubyPrefix
5763}
5864
5965function getDownloadURL ( platform , engine , version ) {
0 commit comments