@@ -18,6 +18,7 @@ export default class OfficialBuilds extends BaseDistribution {
18
18
let manifest : tc . IToolRelease [ ] | undefined ;
19
19
let nodeJsVersions : INodeVersion [ ] | undefined ;
20
20
const osArch = this . translateArchToDistUrl ( this . nodeInfo . arch ) ;
21
+
21
22
if ( this . isLtsAlias ( this . nodeInfo . versionSpec ) ) {
22
23
core . info ( 'Attempt to resolve LTS alias from manifest...' ) ;
23
24
@@ -61,72 +62,103 @@ export default class OfficialBuilds extends BaseDistribution {
61
62
62
63
if ( toolPath ) {
63
64
core . info ( `Found in cache @ ${ toolPath } ` ) ;
64
- } else {
65
- let downloadPath = '' ;
66
- try {
67
- core . info ( `Attempting to download ${ this . nodeInfo . versionSpec } ...` ) ;
68
-
69
- const versionInfo = await this . getInfoFromManifest (
70
- this . nodeInfo . versionSpec ,
71
- this . nodeInfo . stable ,
72
- osArch ,
73
- manifest
65
+ this . addToolPath ( toolPath ) ;
66
+ return ;
67
+ }
68
+
69
+ let downloadPath = '' ;
70
+ try {
71
+ core . info ( `Attempting to download ${ this . nodeInfo . versionSpec } ...` ) ;
72
+
73
+ const versionInfo = await this . getInfoFromManifest (
74
+ this . nodeInfo . versionSpec ,
75
+ this . nodeInfo . stable ,
76
+ osArch ,
77
+ manifest
78
+ ) ;
79
+
80
+ if ( versionInfo ) {
81
+ core . info (
82
+ `Acquiring ${ versionInfo . resolvedVersion } - ${ versionInfo . arch } from ${ versionInfo . downloadUrl } `
83
+ ) ;
84
+ downloadPath = await tc . downloadTool (
85
+ versionInfo . downloadUrl ,
86
+ undefined ,
87
+ this . nodeInfo . auth
74
88
) ;
75
- if ( versionInfo ) {
76
- core . info (
77
- `Acquiring ${ versionInfo . resolvedVersion } - ${ versionInfo . arch } from ${ versionInfo . downloadUrl } `
78
- ) ;
79
- downloadPath = await tc . downloadTool (
80
- versionInfo . downloadUrl ,
81
- undefined ,
82
- this . nodeInfo . auth
83
- ) ;
84
-
85
- if ( downloadPath ) {
86
- toolPath = await this . extractArchive ( downloadPath , versionInfo ) ;
87
- }
88
- } else {
89
- core . info (
90
- 'Not found in manifest. Falling back to download directly from Node'
91
- ) ;
92
- }
93
- } catch ( err ) {
94
- // Rate limit?
95
- if (
96
- err instanceof tc . HTTPError &&
97
- ( err . httpStatusCode === 403 || err . httpStatusCode === 429 )
98
- ) {
99
- core . info (
100
- `Received HTTP status code ${ err . httpStatusCode } . This usually indicates the rate limit has been exceeded`
101
- ) ;
102
- } else {
103
- core . info ( ( err as Error ) . message ) ;
104
- }
105
- core . debug ( ( err as Error ) . stack ?? 'empty stack' ) ;
106
- core . info ( 'Falling back to download directly from Node' ) ;
107
- }
108
89
109
- if ( ! toolPath ) {
110
- const nodeJsVersions = await this . getNodeJsVersions ( ) ;
111
- const versions = this . filterVersions ( nodeJsVersions ) ;
112
- const evaluatedVersion = this . evaluateVersions ( versions ) ;
113
- if ( ! evaluatedVersion ) {
114
- throw new Error (
115
- `Unable to find Node version '${ this . nodeInfo . versionSpec } ' for platform ${ this . osPlat } and architecture ${ this . nodeInfo . arch } .`
116
- ) ;
90
+ if ( downloadPath ) {
91
+ toolPath = await this . extractArchive ( downloadPath , versionInfo ) ;
117
92
}
118
- const toolName = this . getNodejsDistInfo ( evaluatedVersion ) ;
119
- toolPath = await this . downloadNodejs ( toolName ) ;
93
+ } else {
94
+ core . info (
95
+ 'Not found in manifest. Falling back to download directly from Node'
96
+ ) ;
97
+ }
98
+ } catch ( err ) {
99
+ // Rate limit?
100
+ if (
101
+ err instanceof tc . HTTPError &&
102
+ ( err . httpStatusCode === 403 || err . httpStatusCode === 429 )
103
+ ) {
104
+ core . info (
105
+ `Received HTTP status code ${ err . httpStatusCode } . This usually indicates the rate limit has been exceeded`
106
+ ) ;
107
+ } else {
108
+ core . info ( ( err as Error ) . message ) ;
120
109
}
110
+ core . debug ( ( err as Error ) . stack ?? 'empty stack' ) ;
111
+ core . info ( 'Falling back to download directly from Node' ) ;
112
+ }
113
+
114
+ if ( ! toolPath ) {
115
+ toolPath = await this . downloadDirectlyFromNode ( ) ;
116
+ }
117
+
118
+ if ( this . osPlat != 'win32' ) {
119
+ toolPath = path . join ( toolPath , 'bin' ) ;
121
120
}
122
121
122
+ core . addPath ( toolPath ) ;
123
+ }
124
+
125
+ protected addToolPath ( toolPath : string ) {
123
126
if ( this . osPlat != 'win32' ) {
124
127
toolPath = path . join ( toolPath , 'bin' ) ;
125
128
}
126
129
127
130
core . addPath ( toolPath ) ;
128
131
}
129
132
133
+ protected async downloadDirectlyFromNode ( ) {
134
+ const nodeJsVersions = await this . getNodeJsVersions ( ) ;
135
+ const versions = this . filterVersions ( nodeJsVersions ) ;
136
+ const evaluatedVersion = this . evaluateVersions ( versions ) ;
137
+
138
+ if ( ! evaluatedVersion ) {
139
+ throw new Error (
140
+ `Unable to find Node version '${ this . nodeInfo . versionSpec } ' for platform ${ this . osPlat } and architecture ${ this . nodeInfo . arch } .`
141
+ ) ;
142
+ }
143
+
144
+ const toolName = this . getNodejsDistInfo ( evaluatedVersion ) ;
145
+
146
+ try {
147
+ const toolPath = await this . downloadNodejs ( toolName ) ;
148
+ return toolPath ;
149
+ } catch ( error ) {
150
+ if ( error instanceof tc . HTTPError && error . httpStatusCode === 404 ) {
151
+ core . warning (
152
+ `Node version ${ this . nodeInfo . versionSpec } for platform ${ this . osPlat } and architecture ${ this . nodeInfo . arch } was found but failed to download. ` +
153
+ 'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
154
+ 'To resolve this issue you may either fall back to the older version or try again later.'
155
+ ) ;
156
+ }
157
+
158
+ throw error ;
159
+ }
160
+ }
161
+
130
162
protected evaluateVersions ( versions : string [ ] ) : string {
131
163
let version = '' ;
132
164
0 commit comments