Skip to content

Commit 62c15e1

Browse files
authored
fix: send GitHub token instead of mirror-token to GitHub endpoints (#1669)
1 parent 387287a commit 62c15e1

3 files changed

Lines changed: 67 additions & 12 deletions

File tree

‎__tests__/official-installer.test.ts‎

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,69 @@ describe('setup-node', () => {
479479
expect(addPathSpy).toHaveBeenCalledWith(expPath);
480480
});
481481

482+
it('sends GitHub token to GitHub manifest and release downloads when mirror and mirror-token are set', async () => {
483+
os.platform = 'linux';
484+
os.arch = 'x64';
485+
486+
const versionSpec = '12.16.2';
487+
inputs['node-version'] = versionSpec;
488+
inputs['token'] = 'github-secret-token';
489+
inputs['mirror'] = 'https://my_mirror_url';
490+
inputs['mirror-token'] = 'mirror-secret-token';
491+
492+
findSpy.mockImplementation(() => '');
493+
dlSpy.mockImplementation(async () => '/some/temp/path');
494+
const toolPath = path.normalize('/cache/node/12.16.2/x64');
495+
exSpy.mockImplementation(async () => '/some/other/temp/path');
496+
cacheSpy.mockImplementation(async () => toolPath);
497+
498+
await main.run();
499+
500+
expect(getManifestSpy).toHaveBeenCalledWith(
501+
'actions',
502+
'node-versions',
503+
'token github-secret-token',
504+
'main'
505+
);
506+
expect(dlSpy).toHaveBeenCalledWith(
507+
'https://github.com/actions/node-versions/releases/download/12.16.2-20200507.95/node-12.16.2-linux-x64.tar.gz',
508+
undefined,
509+
'token github-secret-token'
510+
);
511+
});
512+
513+
it('sends GitHub token to manifest and mirror-token to mirror when falling back to mirror', async () => {
514+
os.platform = 'linux';
515+
os.arch = 'x64';
516+
517+
const versionSpec = '11.15.0';
518+
const mirror = 'https://my_mirror_url';
519+
inputs['node-version'] = versionSpec;
520+
inputs['token'] = 'github-secret-token';
521+
inputs['mirror'] = mirror;
522+
inputs['mirror-token'] = 'mirror-secret-token';
523+
524+
findSpy.mockImplementation(() => '');
525+
dlSpy.mockImplementation(async () => '/some/temp/path');
526+
const toolPath = path.normalize('/cache/node/11.15.0/x64');
527+
exSpy.mockImplementation(async () => '/some/other/temp/path');
528+
cacheSpy.mockImplementation(async () => toolPath);
529+
530+
await main.run();
531+
532+
expect(getManifestSpy).toHaveBeenCalledWith(
533+
'actions',
534+
'node-versions',
535+
'token github-secret-token',
536+
'main'
537+
);
538+
expect(dlSpy).toHaveBeenCalledWith(
539+
`${mirror}/dist/v11.15.0/node-v11.15.0-linux-x64.tar.gz`,
540+
undefined,
541+
'mirror-secret-token'
542+
);
543+
});
544+
482545
it('falls back to a version from node dist', async () => {
483546
os.platform = 'linux';
484547
os.arch = 'x64';

‎dist/setup/index.js‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -99051,9 +99051,7 @@ class OfficialBuilds extends BaseDistribution {
9905199051
const versionInfo = await this.getInfoFromManifest(this.nodeInfo.versionSpec, this.nodeInfo.stable, osArch, manifest);
9905299052
if (versionInfo) {
9905399053
core_info(`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`);
99054-
downloadPath = await downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.mirror && this.nodeInfo.mirrorToken
99055-
? this.nodeInfo.mirrorToken
99056-
: this.nodeInfo.auth);
99054+
downloadPath = await downloadTool(versionInfo.downloadUrl, undefined, this.nodeInfo.auth);
9905799055
if (downloadPath) {
9905899056
toolPath = await this.extractArchive(downloadPath, versionInfo, false);
9905999057
}
@@ -99174,9 +99172,7 @@ class OfficialBuilds extends BaseDistribution {
9917499172
core_debug('Getting manifest from actions/node-versions@main');
9917599173
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
9917699174
try {
99177-
const manifest = await getManifestFromRepo('actions', 'node-versions', this.nodeInfo.mirror && this.nodeInfo.mirrorToken
99178-
? this.nodeInfo.mirrorToken
99179-
: this.nodeInfo.auth, 'main');
99175+
const manifest = await getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
9918099176
if (isValidManifest(manifest)) {
9918199177
return manifest;
9918299178
}

‎src/distributions/official_builds/official_builds.ts‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ export default class OfficialBuilds extends BaseDistribution {
106106
downloadPath = await tc.downloadTool(
107107
versionInfo.downloadUrl,
108108
undefined,
109-
this.nodeInfo.mirror && this.nodeInfo.mirrorToken
110-
? this.nodeInfo.mirrorToken
111-
: this.nodeInfo.auth
109+
this.nodeInfo.auth
112110
);
113111

114112
if (downloadPath) {
@@ -287,9 +285,7 @@ export default class OfficialBuilds extends BaseDistribution {
287285
const manifest = await tc.getManifestFromRepo(
288286
'actions',
289287
'node-versions',
290-
this.nodeInfo.mirror && this.nodeInfo.mirrorToken
291-
? this.nodeInfo.mirrorToken
292-
: this.nodeInfo.auth,
288+
this.nodeInfo.auth,
293289
'main'
294290
);
295291
if (isValidManifest(manifest)) {

0 commit comments

Comments
 (0)