1
1
const Core = require ( "@actions/core" ) ;
2
2
const ToolCache = require ( "@actions/tool-cache" ) ;
3
+ const IO = require ( "@actions/io" ) ;
3
4
const Octokit = require ( "@octokit/request" ) ;
4
5
const fetch = require ( "node-fetch" ) ;
5
6
const Path = require ( "path" ) ;
@@ -31,8 +32,7 @@ async function run() {
31
32
}
32
33
await maybeInstallShards ( params , func ( params ) ) ;
33
34
34
- Core . info ( "[command]crystal --version" ) ;
35
- const { stdout} = await execFile ( "crystal" , [ "--version" ] ) ;
35
+ const { stdout} = await subprocess ( [ "crystal" , "--version" ] ) ;
36
36
Core . info ( stdout ) ;
37
37
} catch ( error ) {
38
38
Core . setFailed ( error ) ;
@@ -76,6 +76,12 @@ function checkVersion(version, allowed) {
76
76
throw `Version "${ version } " is invalid` ;
77
77
}
78
78
79
+ async function subprocess ( command , options ) {
80
+ Core . info ( "[command]" + command . join ( " " ) ) ;
81
+ const [ file , ...args ] = command ;
82
+ return execFile ( file , args , options ) ;
83
+ }
84
+
79
85
async function installCrystalForLinux ( {
80
86
crystal,
81
87
shards,
@@ -86,7 +92,7 @@ async function installCrystalForLinux({
86
92
const suffixes = { "x86_64" : "linux-x86_64" , "x86" : "linux-i686" } ;
87
93
checkArch ( arch , Object . keys ( suffixes ) ) ;
88
94
89
- const p = installAptPackages (
95
+ const depsTask = installAptPackages (
90
96
"libevent-dev libgmp-dev libpcre3-dev libssl-dev libxml2-dev libyaml-dev" . split ( " " ) ,
91
97
) ;
92
98
const path = await installBinaryRelease ( { crystal, shards, suffix : suffixes [ arch ] , destination} ) ;
@@ -98,7 +104,7 @@ async function installCrystalForLinux({
98
104
await FS . unlink ( Path . join ( path , "bin" , "shards" ) ) ;
99
105
} catch ( e ) { }
100
106
}
101
- await p ;
107
+ await depsTask ;
102
108
}
103
109
104
110
async function installCrystalForMac ( {
@@ -131,11 +137,13 @@ async function installCrystalForMac({
131
137
132
138
async function installAptPackages ( packages ) {
133
139
Core . info ( "Installing package dependencies" ) ;
134
- const args = [
135
- "-n" , " apt-get", "install" , "-qy" , "--no-install-recommends" , "--no-upgrade" , "--" ,
140
+ const command = [
141
+ "apt-get" , "install" , "-qy" , "--no-install-recommends" , "--no-upgrade" , "--" ,
136
142
] . concat ( packages ) ;
137
- Core . info ( "[command]sudo " + args . join ( " " ) ) ;
138
- const { stdout} = await execFile ( "sudo" , args ) ;
143
+ if ( await IO . which ( "sudo" ) ) {
144
+ command . unshift ( "sudo" , "-n" ) ;
145
+ }
146
+ const { stdout} = await subprocess ( command ) ;
139
147
Core . startGroup ( "Finished installing package dependencies" ) ;
140
148
Core . info ( stdout ) ;
141
149
Core . endGroup ( ) ;
@@ -169,8 +177,7 @@ async function maybeInstallShards({shards, destination}, crystalPromise) {
169
177
await crystalPromise ;
170
178
}
171
179
if ( shards !== None ) {
172
- Core . info ( "[command]shards --version" ) ;
173
- const { stdout} = await execFile ( "shards" , [ "--version" ] ) ;
180
+ const { stdout} = await subprocess ( [ "shards" , "--version" ] ) ;
174
181
Core . info ( stdout ) ;
175
182
}
176
183
}
@@ -186,8 +193,7 @@ async function installShards({shards, destination}, crystalPromise) {
186
193
await crystalPromise ;
187
194
188
195
Core . info ( "Building Shards" ) ;
189
- Core . info ( "[command]make" ) ;
190
- const { stdout} = await execFile ( "make" , { cwd : path } ) ;
196
+ const { stdout} = await subprocess ( [ "make" ] , { cwd : path } ) ;
191
197
Core . startGroup ( "Finished building Shards" ) ;
192
198
Core . info ( stdout ) ;
193
199
Core . endGroup ( ) ;
0 commit comments