@@ -3,11 +3,45 @@ const tc = require('@actions/tool-cache');
3
3
const exec = require ( '@actions/exec' ) ;
4
4
const cache = require ( '@actions/cache' ) ;
5
5
6
+ const { platform } = require ( 'node:process' ) ;
7
+ const { arch } = require ( 'node:process' ) ;
8
+
9
+ function direnvBinaryURL ( version , platform , arch ) {
10
+ const baseurl = `https://github.com/direnv/direnv/releases/download/v${ version } /direnv`
11
+
12
+ // supported arch: x64, arm64
13
+ // supported platform: linux, darwin
14
+ const supportedArch = [ 'x64' , 'arm64' ] ;
15
+ const supportedPlatform = [ 'linux' , 'darwin' ] ;
16
+
17
+ if ( ! supportedArch . includes ( arch ) ) {
18
+ throw new Error ( `unsupported arch: ${ arch } ` ) ;
19
+ }
20
+
21
+ if ( ! supportedPlatform . includes ( platform ) ) {
22
+ throw new Error ( `unsupported platform: ${ platform } ` ) ;
23
+ }
24
+
25
+ const archPlatform = `${ platform } -${ arch } ` ;
26
+
27
+ switch ( archPlatform ) {
28
+ case 'linux-x64' :
29
+ return `${ baseurl } .linux-amd64` ;
30
+ case 'linux-arm64' :
31
+ return `${ baseurl } .linux-arm64` ;
32
+ case 'darwin-x64' :
33
+ return `${ baseurl } .darwin-amd64` ;
34
+ case 'darwin-arm64' :
35
+ return `${ baseurl } .darwin-arm64` ;
36
+ default :
37
+ throw new Error ( `unsupported platform: ${ archPlatform } ` ) ;
38
+ }
39
+ }
6
40
7
41
// internal functions
8
42
async function installTools ( ) {
9
43
const direnvVersion = core . getInput ( 'direnvVersion' ) ;
10
- core . info ( `installing direnv-${ direnvVersion } ... ` ) ;
44
+ core . info ( `installing direnv-${ direnvVersion } on ${ platform } - ${ arch } ` ) ;
11
45
12
46
// test direnv in cache
13
47
const foundToolCache = tc . find ( 'direnv' , direnvVersion ) ;
@@ -16,7 +50,7 @@ async function installTools() {
16
50
core . addPath ( foundToolCache ) ;
17
51
} else {
18
52
const workspace = process . env [ 'GITHUB_WORKSPACE' ] ;
19
- const key = `hatsunemiku3939-direnv-action-toolcache-${ direnvVersion } ` ;
53
+ const key = `hatsunemiku3939-direnv-action-toolcache-${ direnvVersion } - ${ platform } - ${ arch } ` ;
20
54
const paths = [ `${ workspace } /.direnv-action` ] ;
21
55
const restoreKeys = [ key ] ;
22
56
@@ -36,8 +70,9 @@ async function installTools() {
36
70
// clear
37
71
await exec . exec ( 'rm' , [ `-rf` , `${ workspace } /.direnv-action` ] ) ;
38
72
} else {
39
- core . info ( 'direnv not found in cache, installing...' ) ;
40
- const installPath = await tc . downloadTool ( `https://github.com/direnv/direnv/releases/download/v${ direnvVersion } /direnv.linux-amd64` ) ;
73
+ const dlUrl = direnvBinaryURL ( direnvVersion , platform , arch ) ;
74
+ core . info ( `direnv not found in cache, installing ${ dlUrl } ...` ) ;
75
+ const installPath = await tc . downloadTool ( dlUrl ) ;
41
76
42
77
// set permissions
43
78
core . info ( `direnv installed ${ installPath } , setting permissions...` ) ;
0 commit comments