@@ -108,7 +108,7 @@ async function installCrystalForLinux({crystal, shards, arch = getArch(), path})
108
108
Core . info ( "Setting up environment for Crystal" ) ;
109
109
Core . addPath ( Path . join ( path , "bin" ) ) ;
110
110
await FS . symlink ( "share/crystal/src" , Path . join ( path , "src" ) ) ;
111
- if ( shards === None ) {
111
+ if ( shards !== Any ) {
112
112
try {
113
113
await FS . unlink ( Path . join ( path , "bin" , "shards" ) ) ;
114
114
} catch ( e ) { }
@@ -124,7 +124,7 @@ async function installCrystalForMac({crystal, shards, arch = "x86_64", path}) {
124
124
Core . info ( "Setting up environment for Crystal" ) ;
125
125
Core . addPath ( Path . join ( path , "embedded" , "bin" ) ) ;
126
126
Core . addPath ( Path . join ( path , "bin" ) ) ;
127
- if ( shards === None ) {
127
+ if ( shards !== Any ) {
128
128
try {
129
129
await FS . unlink ( Path . join ( path , "embedded" , "bin" , "shards" ) ) ;
130
130
} catch ( e ) { }
@@ -162,17 +162,31 @@ async function installBinaryRelease({crystal, suffix, path}) {
162
162
}
163
163
}
164
164
165
- async function maybeInstallShards ( { shards, path} , crystalPromise ) {
165
+ async function maybeInstallShards ( { shards, path, allowCache = true } , crystalPromise ) {
166
166
const allowed = [ Latest , Nightly , NumericVersion , Any , None ] ;
167
+ let cached = false ;
167
168
checkVersion ( shards , allowed ) ;
168
169
if ( ! [ Any , None ] . includes ( shards ) ) {
169
- await installShards ( { shards, path} , crystalPromise ) ;
170
+ cached = await installShards ( { shards, path, allowCache } , crystalPromise ) ;
170
171
}
171
172
if ( shards !== None ) {
172
173
if ( shards === Any ) {
173
174
await crystalPromise ;
174
175
}
175
- const { stdout} = await subprocess ( [ "shards" , "--version" ] ) ;
176
+ let result = null ;
177
+ try {
178
+ result = await subprocess ( [ "shards" , "--version" ] ) ;
179
+ } catch ( error ) {
180
+ if ( ! cached ) {
181
+ throw error ;
182
+ }
183
+ Core . warning ( error ) ;
184
+ Core . info ( "Will try to rebuild" ) ;
185
+ await crystalPromise ;
186
+ await rebuildShards ( { path} ) ;
187
+ result = await subprocess ( [ "shards" , "--version" ] ) ;
188
+ }
189
+ const { stdout} = result ;
176
190
const [ ver ] = stdout . match ( / \d [ ^ ] + / ) ;
177
191
if ( shards === Any && ver ) {
178
192
Core . setOutput ( "shards" , "v" + ver ) ;
@@ -201,12 +215,7 @@ async function installShards({shards, path}, crystalPromise) {
201
215
const fetchSrcTask = downloadSource ( { name : "Shards" , apiBase : GitHubApiBaseShards , ref} ) ;
202
216
await IO . mv ( await fetchSrcTask , path ) ;
203
217
await crystalPromise ;
204
-
205
- Core . info ( "Building Shards" ) ;
206
- const { stdout} = await subprocess ( [ "make" ] , { cwd : path } ) ;
207
- Core . startGroup ( "Finished building Shards" ) ;
208
- Core . info ( stdout ) ;
209
- Core . endGroup ( ) ;
218
+ await rebuildShards ( { path} ) ;
210
219
}
211
220
if ( restored !== cacheKey ) {
212
221
Core . info ( `Saving cache: '${ cacheKey } '` ) ;
@@ -217,9 +226,18 @@ async function installShards({shards, path}, crystalPromise) {
217
226
}
218
227
}
219
228
220
- await crystalPromise ;
221
229
Core . info ( "Setting up environment for Shards" ) ;
222
230
Core . addPath ( Path . join ( path , "bin" ) ) ;
231
+ return ! ! restored ;
232
+ }
233
+
234
+ async function rebuildShards ( { path} ) {
235
+ Core . info ( "Building Shards" ) ;
236
+ await subprocess ( [ "make" , "clean" ] , { cwd : path } ) ;
237
+ const { stdout} = await subprocess ( [ "make" ] , { cwd : path } ) ;
238
+ Core . startGroup ( "Finished building Shards" ) ;
239
+ Core . info ( stdout ) ;
240
+ Core . endGroup ( ) ;
223
241
}
224
242
225
243
const GitHubApiBase = "/repos/crystal-lang/crystal" ;
0 commit comments