@@ -20,12 +20,16 @@ export function getAvailableVersions(_platform, engine) {
2020}
2121
2222export async function install ( platform , engine , version ) {
23- const url = rubyInstallerVersions [ version ] [ os . arch ( ) ]
23+ let url = rubyInstallerVersions [ version ] [ os . arch ( ) ]
24+ if ( version === 'mswin' ) {
25+ url = await getLatestMswinURL ( url )
26+ }
2427
25- if ( ! url . endsWith ( '.7z' ) ) {
26- throw new Error ( `URL should end in .7z: ${ url } ` )
28+ const ext = path . posix . extname ( url )
29+ if ( ext !== '.7z' && ext !== '.zip' ) {
30+ throw new Error ( `URL should end in .7z or .zip: ${ url } ` )
2731 }
28- const base = path . posix . basename ( url , '.7z' )
32+ const base = path . posix . basename ( url , ext )
2933
3034 let rubyPrefix , inToolCache
3135 if ( common . shouldUseToolCache ( engine , version ) ) {
@@ -43,6 +47,10 @@ export async function install(platform, engine, version) {
4347 await downloadAndExtract ( engine , version , url , base , rubyPrefix ) ;
4448 }
4549
50+ if ( version === 'mswin' ) {
51+ exportEnv ( { SSL_CERT_FILE : findGitCertFile ( ) } )
52+ }
53+
4654 const paths = [ `${ rubyPrefix } \\bin` ]
4755 const windowsToolchain = core . getInput ( 'windows-toolchain' )
4856 if ( windowsToolchain === 'none' ) {
@@ -77,6 +85,33 @@ export async function install(platform, engine, version) {
7785 return rubyPrefix
7886}
7987
88+ // mswin master builds are published daily under dated names, so pick the latest one from the index
89+ async function getLatestMswinURL ( indexURL ) {
90+ // Retry like tc.downloadTool does for the archive, so a transient failure of the index does not fail the job
91+ let response
92+ for ( let attempt = 1 ; attempt <= 3 ; attempt ++ ) {
93+ try {
94+ response = await fetch ( indexURL , { signal : AbortSignal . timeout ( 30000 ) } )
95+ if ( response . ok ) break
96+ } catch ( error ) {
97+ if ( attempt === 3 ) throw error
98+ }
99+ if ( attempt < 3 ) await new Promise ( resolve => setTimeout ( resolve , 5000 ) )
100+ }
101+ if ( ! response . ok ) {
102+ throw new Error ( `Failed to fetch ${ indexURL } : ${ response . status } ${ response . statusText } ` )
103+ }
104+
105+ const platform = `${ os . arch ( ) } -mswin64_140`
106+ const builds = ( await response . json ( ) ) . builds . filter ( build => build . channel === 'dev' && build . platform === platform )
107+ if ( builds . length === 0 ) {
108+ throw new Error ( `No mswin build for ${ platform } in ${ indexURL } ` )
109+ }
110+
111+ // The index is sorted by name, and the date in the name can differ from the date it was published
112+ return builds . reduce ( ( latest , build ) => build . published_at > latest . published_at ? build : latest ) . url
113+ }
114+
80115async function downloadAndExtract ( engine , version , url , base , rubyPrefix ) {
81116 const downloadPath = await common . measure ( 'Downloading Ruby' , async ( ) => {
82117 console . log ( url )
@@ -148,15 +183,22 @@ async function installMSYS2(url, rubyPrefix = process.env.RUNNER_TEMP) {
148183 return [ `${ msys2Path } \\${ msys2Type } \\bin` , `${ msys2Path } \\usr\\bin` ]
149184}
150185
151- async function installMSYS1 ( url ) {
186+ // DevKit and mswin Rubies have no usable CA certificates on runners, so they use the bundle of Git for Windows
187+ function findGitCertFile ( ) {
152188 const certFile = [
153189 'C:\\Program Files\\Git\\ucrt64\\etc\\ssl\\cert.pem' ,
154190 'C:\\Program Files\\Git\\mingw64\\etc\\ssl\\cert.pem' ,
155191 'C:\\Program Files\\Git\\mingw64\\ssl\\cert.pem' ,
192+ 'C:\\Program Files\\Git\\clangarm64\\etc\\ssl\\cert.pem' ,
156193 ] . find ( file => fs . existsSync ( file ) )
157194 if ( certFile === undefined ) {
158195 throw new Error ( "Cannot find Git's cert file" )
159196 }
197+ return certFile
198+ }
199+
200+ async function installMSYS1 ( url ) {
201+ const certFile = findGitCertFile ( )
160202
161203 const downloadPath = await common . measure ( 'Downloading msys1 build tools' , async ( ) => {
162204 console . log ( url )
0 commit comments