@@ -32,6 +32,7 @@ if (!tempDirectory) {
32
32
//
33
33
interface INodeVersion {
34
34
version : string ;
35
+ date : string ;
35
36
files : string [ ] ;
36
37
}
37
38
@@ -81,7 +82,7 @@ export async function getNode(versionSpec: string, mirror: string) {
81
82
core . addPath ( toolPath ) ;
82
83
}
83
84
84
- async function queryLatestMatch (
85
+ export async function queryLatestMatch (
85
86
versionSpec : string ,
86
87
mirror : string
87
88
) : Promise < string > {
@@ -101,15 +102,15 @@ async function queryLatestMatch(
101
102
throw new Error ( `Unexpected OS '${ osPlat } '` ) ;
102
103
}
103
104
104
- let versions : string [ ] = [ ] ;
105
+ let versions : INodeVersion [ ] = [ ] ;
105
106
let dataUrl = `${ mirror } /index.json` ;
106
107
let rest : restm . RestClient = new restm . RestClient ( 'setup-node' ) ;
107
108
let nodeVersions : INodeVersion [ ] =
108
109
( await rest . get < INodeVersion [ ] > ( dataUrl ) ) . result || [ ] ;
109
110
nodeVersions . forEach ( ( nodeVersion : INodeVersion ) => {
110
111
// ensure this version supports your os and platform
111
112
if ( nodeVersion . files . indexOf ( dataFileName ) >= 0 ) {
112
- versions . push ( nodeVersion . version ) ;
113
+ versions . push ( nodeVersion ) ;
113
114
}
114
115
} ) ;
115
116
@@ -119,18 +120,32 @@ async function queryLatestMatch(
119
120
}
120
121
121
122
// TODO - should we just export this from @actions/tool-cache? Lifted directly from there
122
- function evaluateVersions ( versions : string [ ] , versionSpec : string ) : string {
123
+ function evaluateVersions (
124
+ versions : INodeVersion [ ] ,
125
+ versionSpec : string
126
+ ) : string {
123
127
let version = '' ;
124
128
core . debug ( `evaluating ${ versions . length } versions` ) ;
125
129
versions = versions . sort ( ( a , b ) => {
126
- if ( semver . gt ( a , b ) ) {
130
+ const versionA : semver . SemVer | null = semver . coerce ( a . version ) ;
131
+ const versionB : semver . SemVer | null = semver . coerce ( b . version ) ;
132
+ // If versions are equal, compare date instead
133
+ if ( versionA === versionB || versionA === null || versionB === null ) {
134
+ if ( new Date ( a . date ) > new Date ( b . date ) ) {
135
+ return 1 ;
136
+ }
137
+ return - 1 ;
138
+ }
139
+ if ( semver . gt ( versionA , versionB ) ) {
127
140
return 1 ;
128
141
}
129
142
return - 1 ;
130
143
} ) ;
131
144
for ( let i = versions . length - 1 ; i >= 0 ; i -- ) {
132
- const potential : string = versions [ i ] ;
133
- const satisfied : boolean = semver . satisfies ( potential , versionSpec ) ;
145
+ const potential : string = versions [ i ] . version ;
146
+ const semverPotential : semver . SemVer | null = semver . coerce ( potential ) ;
147
+ if ( semverPotential === null ) continue ;
148
+ const satisfied : boolean = semver . satisfies ( semverPotential , versionSpec ) ;
134
149
if ( satisfied ) {
135
150
version = potential ;
136
151
break ;
0 commit comments