Skip to content

Commit d59bcf2

Browse files
committed
support ghes
1 parent 2ae9264 commit d59bcf2

File tree

3 files changed

+109
-49
lines changed

3 files changed

+109
-49
lines changed

dist/index.js

Lines changed: 47 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4631,6 +4631,7 @@ const core = __importStar(__webpack_require__(470));
46314631
const installer = __importStar(__webpack_require__(749));
46324632
const auth = __importStar(__webpack_require__(202));
46334633
const path = __importStar(__webpack_require__(622));
4634+
const url_1 = __webpack_require__(835);
46344635
function run() {
46354636
return __awaiter(this, void 0, void 0, function* () {
46364637
try {
@@ -4644,7 +4645,7 @@ function run() {
46444645
}
46454646
console.log(`version: ${version}`);
46464647
if (version) {
4647-
let token = core.getInput('token');
4648+
let token = isGhes() ? undefined : core.getInput('token');
46484649
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
46494650
yield installer.getNode(version, stable, token);
46504651
}
@@ -4664,6 +4665,10 @@ function run() {
46644665
});
46654666
}
46664667
exports.run = run;
4668+
function isGhes() {
4669+
const ghUrl = new url_1.URL(process.env['GITHUB_URL'] || 'https://github.com');
4670+
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
4671+
}
46674672
//# sourceMappingURL=main.js.map
46684673

46694674
/***/ }),
@@ -12981,7 +12986,6 @@ function getNode(versionSpec, stable, token) {
1298112986
let osPlat = os.platform();
1298212987
let osArch = translateArchToDistUrl(os.arch());
1298312988
// check cache
12984-
let info = null;
1298512989
let toolPath;
1298612990
toolPath = tc.find('node', versionSpec);
1298712991
// If not found in cache, download
@@ -12990,31 +12994,57 @@ function getNode(versionSpec, stable, token) {
1299012994
}
1299112995
else {
1299212996
console.log(`Attempting to download ${versionSpec}...`);
12993-
let info = yield getInfoFromManifest(versionSpec, stable, token);
12994-
if (!info) {
12995-
console.log('Not found in manifest. Falling back to download directly from Node');
12996-
info = yield getInfoFromDist(versionSpec);
12997-
}
12998-
if (!info) {
12999-
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
13000-
}
13001-
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
1300212997
let downloadPath = '';
12998+
let info = null;
12999+
//
13000+
// Try download from internal distribution (popular versions only)
13001+
//
1300313002
try {
13004-
downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, token);
13003+
info = yield getInfoFromManifest(versionSpec, stable, token);
13004+
if (info) {
13005+
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
13006+
downloadPath = yield tc.downloadTool(info.downloadUrl, undefined, token);
13007+
}
13008+
else {
13009+
console.log('Not found in manifest. Falling back to download directly from Node');
13010+
}
1300513011
}
1300613012
catch (err) {
13007-
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
13008-
yield acquireNodeFromFallbackLocation(info.resolvedVersion);
13009-
return;
13013+
// Rate limited?
13014+
if (err instanceof tc.HTTPError && err.httpStatusCode === 403) {
13015+
console.log('Received HTTP status code 403. This usually indicates the rate limit has been exceeded');
13016+
}
13017+
else {
13018+
console.log(err.message);
13019+
}
13020+
core.debug(err.stack);
13021+
console.log('Falling back to download directly from Node');
13022+
}
13023+
//
13024+
// Download from nodejs.org
13025+
//
13026+
if (!downloadPath) {
13027+
info = yield getInfoFromDist(versionSpec);
13028+
if (!info) {
13029+
throw new Error(`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`);
13030+
}
13031+
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
13032+
try {
13033+
downloadPath = yield tc.downloadTool(info.downloadUrl);
13034+
}
13035+
catch (err) {
13036+
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
13037+
return yield acquireNodeFromFallbackLocation(info.resolvedVersion);
13038+
}
13039+
throw err;
1301013040
}
13011-
throw err;
1301213041
}
1301313042
//
1301413043
// Extract
1301513044
//
1301613045
console.log('Extracting ...');
1301713046
let extPath;
13047+
info = info || {}; // satisfy compiler, never null when reaches here
1301813048
if (osPlat == 'win32') {
1301913049
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
1302013050
extPath = yield tc.extract7z(downloadPath, undefined, _7zPath);
@@ -13055,15 +13085,14 @@ exports.getNode = getNode;
1305513085
function getInfoFromManifest(versionSpec, stable, token) {
1305613086
return __awaiter(this, void 0, void 0, function* () {
1305713087
let info = null;
13058-
const releases = yield tc.getManifestFromRepo('actions', 'node-versions', token);
13088+
const releases = yield tc.getManifestFromRepo('actions', 'node-versions', token || '');
1305913089
console.log(`matching ${versionSpec}...`);
1306013090
const rel = yield tc.findFromManifest(versionSpec, stable, releases);
1306113091
if (rel && rel.files.length > 0) {
1306213092
info = {};
1306313093
info.resolvedVersion = rel.version;
1306413094
info.downloadUrl = rel.files[0].download_url;
1306513095
info.fileName = rel.files[0].filename;
13066-
info.token = token;
1306713096
}
1306813097
return info;
1306913098
});
@@ -13072,7 +13101,6 @@ function getInfoFromDist(versionSpec) {
1307213101
return __awaiter(this, void 0, void 0, function* () {
1307313102
let osPlat = os.platform();
1307413103
let osArch = translateArchToDistUrl(os.arch());
13075-
let info = null;
1307613104
let version;
1307713105
version = yield queryDistForMatch(versionSpec);
1307813106
if (!version) {

src/installer.ts

Lines changed: 55 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import * as io from '@actions/io';
66
import * as tc from '@actions/tool-cache';
77
import * as path from 'path';
88
import * as semver from 'semver';
9-
import {Url} from 'url';
109
import fs = require('fs');
1110

1211
//
@@ -20,21 +19,19 @@ export interface INodeVersion {
2019

2120
interface INodeVersionInfo {
2221
downloadUrl: string;
23-
token: string | null;
2422
resolvedVersion: string;
2523
fileName: string;
2624
}
2725

2826
export async function getNode(
2927
versionSpec: string,
3028
stable: boolean,
31-
token: string
29+
token: string | undefined
3230
) {
3331
let osPlat: string = os.platform();
3432
let osArch: string = translateArchToDistUrl(os.arch());
3533

3634
// check cache
37-
let info: INodeVersionInfo | null = null;
3835
let toolPath: string;
3936
toolPath = tc.find('node', versionSpec);
4037

@@ -43,39 +40,70 @@ export async function getNode(
4340
console.log(`Found in cache @ ${toolPath}`);
4441
} else {
4542
console.log(`Attempting to download ${versionSpec}...`);
46-
let info = await getInfoFromManifest(versionSpec, stable, token);
47-
if (!info) {
48-
console.log(
49-
'Not found in manifest. Falling back to download directly from Node'
50-
);
51-
info = await getInfoFromDist(versionSpec);
52-
}
53-
54-
if (!info) {
55-
throw new Error(
56-
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
57-
);
58-
}
59-
60-
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
61-
6243
let downloadPath = '';
44+
let info: INodeVersionInfo | null = null;
45+
46+
//
47+
// Try download from internal distribution (popular versions only)
48+
//
6349
try {
64-
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, token);
50+
info = await getInfoFromManifest(versionSpec, stable, token);
51+
if (info) {
52+
console.log(
53+
`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`
54+
);
55+
downloadPath = await tc.downloadTool(
56+
info.downloadUrl,
57+
undefined,
58+
token
59+
);
60+
} else {
61+
console.log(
62+
'Not found in manifest. Falling back to download directly from Node'
63+
);
64+
}
6565
} catch (err) {
66-
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
67-
await acquireNodeFromFallbackLocation(info.resolvedVersion);
68-
return;
66+
// Rate limited?
67+
if (err instanceof tc.HTTPError && err.httpStatusCode === 403) {
68+
console.log(
69+
'Received HTTP status code 403. This usually indicates the rate limit has been exceeded'
70+
);
71+
} else {
72+
console.log(err.message);
6973
}
74+
core.debug(err.stack);
75+
console.log('Falling back to download directly from Node');
76+
}
7077

71-
throw err;
78+
//
79+
// Download from nodejs.org
80+
//
81+
if (!downloadPath) {
82+
info = await getInfoFromDist(versionSpec);
83+
if (!info) {
84+
throw new Error(
85+
`Unable to find Node version '${versionSpec}' for platform ${osPlat} and architecture ${osArch}.`
86+
);
87+
}
88+
89+
console.log(`Acquiring ${info.resolvedVersion} from ${info.downloadUrl}`);
90+
try {
91+
downloadPath = await tc.downloadTool(info.downloadUrl);
92+
} catch (err) {
93+
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
94+
return await acquireNodeFromFallbackLocation(info.resolvedVersion);
95+
}
96+
97+
throw err;
98+
}
7299
}
73100

74101
//
75102
// Extract
76103
//
77104
console.log('Extracting ...');
78105
let extPath: string;
106+
info = info || ({} as INodeVersionInfo); // satisfy compiler, never null when reaches here
79107
if (osPlat == 'win32') {
80108
let _7zPath = path.join(__dirname, '..', 'externals', '7zr.exe');
81109
extPath = await tc.extract7z(downloadPath, undefined, _7zPath);
@@ -117,13 +145,13 @@ export async function getNode(
117145
async function getInfoFromManifest(
118146
versionSpec: string,
119147
stable: boolean,
120-
token: string
148+
token: string | undefined
121149
): Promise<INodeVersionInfo | null> {
122150
let info: INodeVersionInfo | null = null;
123151
const releases = await tc.getManifestFromRepo(
124152
'actions',
125153
'node-versions',
126-
token
154+
token || ''
127155
);
128156
console.log(`matching ${versionSpec}...`);
129157
const rel = await tc.findFromManifest(versionSpec, stable, releases);
@@ -133,7 +161,6 @@ async function getInfoFromManifest(
133161
info.resolvedVersion = rel.version;
134162
info.downloadUrl = rel.files[0].download_url;
135163
info.fileName = rel.files[0].filename;
136-
info.token = token;
137164
}
138165

139166
return info;
@@ -145,7 +172,6 @@ async function getInfoFromDist(
145172
let osPlat: string = os.platform();
146173
let osArch: string = translateArchToDistUrl(os.arch());
147174

148-
let info: INodeVersionInfo | null = null;
149175
let version: string;
150176

151177
version = await queryDistForMatch(versionSpec);

src/main.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as core from '@actions/core';
22
import * as installer from './installer';
33
import * as auth from './authutil';
44
import * as path from 'path';
5+
import {URL} from 'url';
56

67
export async function run() {
78
try {
@@ -16,7 +17,7 @@ export async function run() {
1617

1718
console.log(`version: ${version}`);
1819
if (version) {
19-
let token = core.getInput('token');
20+
let token = isGhes() ? undefined : core.getInput('token');
2021
let stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
2122
await installer.getNode(version, stable, token);
2223
}
@@ -39,3 +40,8 @@ export async function run() {
3940
core.setFailed(error.message);
4041
}
4142
}
43+
44+
function isGhes(): boolean {
45+
const ghUrl = new URL(process.env['GITHUB_URL'] || 'https://github.com');
46+
return ghUrl.hostname.toUpperCase() !== 'GITHUB.COM';
47+
}

0 commit comments

Comments
 (0)