Skip to content

Commit 340069d

Browse files
authored
refactor: update action parameters and docs
2 parents cc72f1c + c50cff9 commit 340069d

8 files changed

Lines changed: 30 additions & 106 deletions

File tree

README.md

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@
55
[![e2e-cache](https://github.com/actions/setup-node/actions/workflows/e2e-cache.yml/badge.svg?branch=main)](https://github.com/actions/setup-node/actions/workflows/e2e-cache.yml)
66
[![proxy](https://github.com/actions/setup-node/actions/workflows/proxy.yml/badge.svg)](https://github.com/actions/setup-node/actions/workflows/proxy.yml)
77

8+
> **Fork of [actions/setup-node](https://github.com/actions/setup-node)** — Node.js binaries are downloaded from the [npmmirror](https://npmmirror.com/) instead of the official Node.js dist, which significantly improves download speed in some self-hosted network environments.
9+
810
This action provides the following functionality for GitHub Actions users:
911

10-
- Optionally downloading and caching distribution of the requested Node.js version, and adding it to the PATH
12+
- Optionally downloading and caching distribution of the requested Node.js version **via cnpm mirror**, and adding it to the PATH
1113
- Optionally caching npm/yarn/pnpm dependencies
1214
- Registering problem matchers for error output
1315
- Configuring authentication for GPR or npm
@@ -94,20 +96,6 @@ See [action.yml](action.yml)
9496
# Default: ''
9597
scope: ''
9698

97-
# Optional mirror to download binaries from.
98-
# Artifacts need to match the official Node.js
99-
# Example:
100-
# V8 Canary Build: <mirror_url>/download/v8-canary
101-
# RC Build: <mirror_url>/download/rc
102-
# Official: Build <mirror_url>/dist
103-
# Nightly build: <mirror_url>/download/nightly
104-
# Default: ''
105-
mirror: ''
106-
107-
# Optional mirror token.
108-
# The token will be used as a bearer token in the Authorization header
109-
# Default: ''
110-
mirror-token: ''
11199
```
112100
<!-- end usage -->
113101

@@ -125,7 +113,7 @@ steps:
125113
126114
The `node-version` input is optional. If not supplied, the node version from PATH will be used. However, it is recommended to always specify Node.js version and not rely on the system one.
127115

128-
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to downloading directly from [npm Mirror Node dist](https://cdn.npmmirror.com/binaries/node/).
116+
The action will first check the local cache for a semver match. If unable to find a specific version in the cache, the action will attempt to download a version of Node.js. It will pull LTS versions from [node-versions releases](https://github.com/actions/node-versions/releases) and on miss or failure will fall back to downloading directly from the [cnpm mirror](https://cdn.npmmirror.com/binaries/node/).
129117

130118
For information regarding locally cached versions of Node.js on GitHub hosted runners, check out [GitHub Actions Runner Images](https://github.com/actions/runner-images).
131119

@@ -143,7 +131,7 @@ Examples:
143131
**Note:** Like the other values, `*` will get the latest [locally-cached Node.js version](https://github.com/actions/runner-images/blob/main/images/ubuntu/Ubuntu2204-Readme.md#nodejs), or the latest version from [actions/node-versions](https://github.com/actions/node-versions/blob/main/versions-manifest.json), depending on the [`check-latest`](docs/advanced-usage.md#check-latest-version) input.
144132

145133
`current`/`latest`/`node` always resolve to the latest [dist version](https://nodejs.org/dist/index.json).
146-
That version is then downloaded from actions/node-versions if possible, or directly from https://cdn.npmmirror.com/binaries/node if not.
134+
That version is then downloaded from actions/node-versions if possible, or directly from the [cnpm mirror](https://cdn.npmmirror.com/binaries/node/) if not.
147135
Since it will not be cached always, there is possibility of hitting rate limit when downloading from dist
148136

149137
### Checking in lockfiles
@@ -249,7 +237,6 @@ If the runner is not able to access github.com, any Nodejs versions requested du
249237
- [Publishing to npmjs and GPR with npm](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-npm)
250238
- [Publishing to npmjs and GPR with yarn](docs/advanced-usage.md#publish-to-npmjs-and-gpr-with-yarn)
251239
- [Using private packages](docs/advanced-usage.md#use-private-packages)
252-
- [Using private mirror](docs/advanced-usage.md#use-private-mirror)
253240

254241
## Recommended permissions
255242

action.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,6 @@ inputs:
2525
default: true
2626
cache-dependency-path:
2727
description: 'Used to specify the path to a dependency file: package-lock.json, yarn.lock, etc. Supports wildcards or a list of file names for caching multiple dependencies.'
28-
mirror:
29-
description: 'Used to specify an alternative mirror to download Node.js binaries from'
30-
mirror-token:
31-
description: 'The token used as Authorization header when fetching from the mirror'
3228
# TODO: add input to control forcing to pull from cloud or dist.
3329
# escape valve for someone having issues or needing the absolute latest which isn't cached yet
3430
outputs:

dist/setup/index.js

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -112561,13 +112561,9 @@ class BaseDistribution {
112561112561
return tc.find('node', this.nodeInfo.versionSpec, this.translateArchToDistUrl(this.nodeInfo.arch));
112562112562
}
112563112563
async getNodeJsVersions() {
112564-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
112564+
const initialUrl = this.getDistributionUrl();
112565112565
const dataUrl = `${initialUrl}/index.json`;
112566-
const headers = {};
112567-
if (this.nodeInfo.mirrorToken) {
112568-
headers['Authorization'] = this.nodeInfo.mirrorToken;
112569-
}
112570-
const response = await this.httpClient.getJson(dataUrl, headers);
112566+
const response = await this.httpClient.getJson(dataUrl);
112571112567
return response.result || [];
112572112568
}
112573112569
getNodejsDistInfo(version) {
@@ -112581,7 +112577,7 @@ class BaseDistribution {
112581112577
? `${fileName}.zip`
112582112578
: `${fileName}.7z`
112583112579
: `${fileName}.tar.gz`;
112584-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
112580+
const initialUrl = this.getDistributionUrl();
112585112581
const url = `${initialUrl}/v${version}/${urlFileName}`;
112586112582
return {
112587112583
downloadUrl: url,
@@ -112594,7 +112590,7 @@ class BaseDistribution {
112594112590
let downloadPath = '';
112595112591
core.info(`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`);
112596112592
try {
112597-
downloadPath = await tc.downloadTool(info.downloadUrl, undefined, this.nodeInfo.mirrorToken);
112593+
downloadPath = await tc.downloadTool(info.downloadUrl);
112598112594
}
112599112595
catch (err) {
112600112596
if (err instanceof tc.HTTPError &&
@@ -112615,7 +112611,7 @@ class BaseDistribution {
112615112611
return { range: valid, options };
112616112612
}
112617112613
async acquireWindowsNodeFromFallbackLocation(version, arch = os_1.default.arch()) {
112618-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
112614+
const initialUrl = this.getDistributionUrl();
112619112615
const osArch = this.translateArchToDistUrl(arch);
112620112616
// Create temporary folder to download to
112621112617
const tempDownloadFolder = `temp_${crypto.randomUUID()}`;
@@ -112629,18 +112625,18 @@ class BaseDistribution {
112629112625
exeUrl = `${initialUrl}/v${version}/win-${osArch}/node.exe`;
112630112626
libUrl = `${initialUrl}/v${version}/win-${osArch}/node.lib`;
112631112627
core.info(`Downloading only node binary from ${exeUrl}`);
112632-
const exePath = await tc.downloadTool(exeUrl, undefined, this.nodeInfo.mirrorToken);
112628+
const exePath = await tc.downloadTool(exeUrl);
112633112629
await io.cp(exePath, path.join(tempDir, 'node.exe'));
112634-
const libPath = await tc.downloadTool(libUrl, undefined, this.nodeInfo.mirrorToken);
112630+
const libPath = await tc.downloadTool(libUrl);
112635112631
await io.cp(libPath, path.join(tempDir, 'node.lib'));
112636112632
}
112637112633
catch (err) {
112638112634
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
112639112635
exeUrl = `${initialUrl}/v${version}/node.exe`;
112640112636
libUrl = `${initialUrl}/v${version}/node.lib`;
112641-
const exePath = await tc.downloadTool(exeUrl, undefined, this.nodeInfo.mirrorToken);
112637+
const exePath = await tc.downloadTool(exeUrl);
112642112638
await io.cp(exePath, path.join(tempDir, 'node.exe'));
112643-
const libPath = await tc.downloadTool(libUrl, undefined, this.nodeInfo.mirrorToken);
112639+
const libPath = await tc.downloadTool(libUrl);
112644112640
await io.cp(libPath, path.join(tempDir, 'node.lib'));
112645112641
}
112646112642
else {
@@ -112926,15 +112922,15 @@ class OfficialBuilds extends base_distribution_1.default {
112926112922
version = super.evaluateVersions(versions);
112927112923
return version;
112928112924
}
112929-
getDistributionUrl(mirror) {
112925+
getDistributionUrl() {
112930112926
return constants_1.DEFAULT_NODE_MIRROR;
112931112927
}
112932112928
getFallbackDisplayUrl() {
112933112929
return constants_1.DEFAULT_NODE_MIRROR;
112934112930
}
112935112931
getManifest() {
112936112932
core.debug('Getting manifest from actions/node-versions@main');
112937-
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.mirror ? this.nodeInfo.mirrorToken : this.nodeInfo.auth, 'main');
112933+
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
112938112934
}
112939112935
resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
112940112936
const alias = versionSpec.split('lts/')[1]?.toLowerCase();
@@ -113074,18 +113070,14 @@ async function run() {
113074113070
if (version) {
113075113071
const token = core.getInput('token');
113076113072
const auth = !token ? undefined : `token ${token}`;
113077-
const mirror = core.getInput('mirror');
113078-
const mirrorToken = core.getInput('mirror-token');
113079113073
const stable = (core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
113080113074
const checkLatest = (core.getInput('check-latest') || 'false').toUpperCase() === 'TRUE';
113081113075
const nodejsInfo = {
113082113076
versionSpec: version,
113083113077
checkLatest,
113084113078
auth,
113085113079
stable,
113086-
arch,
113087-
mirror,
113088-
mirrorToken
113080+
arch
113089113081
};
113090113082
const nodeDistribution = (0, installer_factory_1.getNodejsDistribution)(nodejsInfo);
113091113083
await nodeDistribution.setupNodeJs();

docs/advanced-usage.md

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -474,18 +474,3 @@ steps:
474474
To access private GitHub Packages within the same organization, go to "Manage Actions access" in Package settings and set the repositories you want to access.
475475

476476
Please refer to the [Ensuring workflow access to your package - Configuring a package's access control and visibility](https://docs.github.com/en/packages/learn-github-packages/configuring-a-packages-access-control-and-visibility#ensuring-workflow-access-to-your-package) for more details.
477-
478-
## Use private mirror
479-
480-
It is possible to use a private mirror hosting Node.js binaries. This mirror must be a full mirror of the official Node.js distribution.
481-
The mirror URL can be set using the `mirror` input.
482-
It is possible to specify a token to authenticate with the mirror using the `mirror-token` input.
483-
The token will be passed in the `Authorization` header.
484-
485-
```yaml
486-
- uses: actions/setup-node@v6
487-
with:
488-
node-version: '24.x'
489-
mirror: 'https://nodejs.org/dist'
490-
mirror-token: 'your-mirror-token'
491-
```

src/distributions/base-distribution.ts

Lines changed: 10 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import os from 'os';
1111
import fs from 'fs';
1212

1313
import {NodeInputs, INodeVersion, INodeVersionInfo} from './base-models';
14-
import {DEFAULT_NODE_MIRROR} from '../constants';
1514

1615
export default abstract class BaseDistribution {
1716
protected httpClient: hc.HttpClient;
@@ -24,7 +23,7 @@ export default abstract class BaseDistribution {
2423
});
2524
}
2625

27-
protected abstract getDistributionUrl(mirror: string): string;
26+
protected abstract getDistributionUrl(): string;
2827

2928
public async setupNodeJs() {
3029
let nodeJsVersions: INodeVersion[] | undefined;
@@ -97,19 +96,10 @@ export default abstract class BaseDistribution {
9796
}
9897

9998
protected async getNodeJsVersions(): Promise<INodeVersion[]> {
100-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
99+
const initialUrl = this.getDistributionUrl();
101100
const dataUrl = `${initialUrl}/index.json`;
102101

103-
const headers = {};
104-
105-
if (this.nodeInfo.mirrorToken) {
106-
headers['Authorization'] = this.nodeInfo.mirrorToken;
107-
}
108-
109-
const response = await this.httpClient.getJson<INodeVersion[]>(
110-
dataUrl,
111-
headers
112-
);
102+
const response = await this.httpClient.getJson<INodeVersion[]>(dataUrl);
113103
return response.result || [];
114104
}
115105

@@ -126,7 +116,7 @@ export default abstract class BaseDistribution {
126116
? `${fileName}.zip`
127117
: `${fileName}.7z`
128118
: `${fileName}.tar.gz`;
129-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
119+
const initialUrl = this.getDistributionUrl();
130120
const url = `${initialUrl}/v${version}/${urlFileName}`;
131121

132122
return <INodeVersionInfo>{
@@ -143,11 +133,7 @@ export default abstract class BaseDistribution {
143133
`Acquiring ${info.resolvedVersion} - ${info.arch} from ${info.downloadUrl}`
144134
);
145135
try {
146-
downloadPath = await tc.downloadTool(
147-
info.downloadUrl,
148-
undefined,
149-
this.nodeInfo.mirrorToken
150-
);
136+
downloadPath = await tc.downloadTool(info.downloadUrl);
151137
} catch (err) {
152138
if (
153139
err instanceof tc.HTTPError &&
@@ -181,7 +167,7 @@ export default abstract class BaseDistribution {
181167
version: string,
182168
arch: string = os.arch()
183169
): Promise<string> {
184-
const initialUrl = this.getDistributionUrl(this.nodeInfo.mirror);
170+
const initialUrl = this.getDistributionUrl();
185171
const osArch: string = this.translateArchToDistUrl(arch);
186172

187173
// Create temporary folder to download to
@@ -198,34 +184,18 @@ export default abstract class BaseDistribution {
198184

199185
core.info(`Downloading only node binary from ${exeUrl}`);
200186

201-
const exePath = await tc.downloadTool(
202-
exeUrl,
203-
undefined,
204-
this.nodeInfo.mirrorToken
205-
);
187+
const exePath = await tc.downloadTool(exeUrl);
206188
await io.cp(exePath, path.join(tempDir, 'node.exe'));
207-
const libPath = await tc.downloadTool(
208-
libUrl,
209-
undefined,
210-
this.nodeInfo.mirrorToken
211-
);
189+
const libPath = await tc.downloadTool(libUrl);
212190
await io.cp(libPath, path.join(tempDir, 'node.lib'));
213191
} catch (err) {
214192
if (err instanceof tc.HTTPError && err.httpStatusCode == 404) {
215193
exeUrl = `${initialUrl}/v${version}/node.exe`;
216194
libUrl = `${initialUrl}/v${version}/node.lib`;
217195

218-
const exePath = await tc.downloadTool(
219-
exeUrl,
220-
undefined,
221-
this.nodeInfo.mirrorToken
222-
);
196+
const exePath = await tc.downloadTool(exeUrl);
223197
await io.cp(exePath, path.join(tempDir, 'node.exe'));
224-
const libPath = await tc.downloadTool(
225-
libUrl,
226-
undefined,
227-
this.nodeInfo.mirrorToken
228-
);
198+
const libPath = await tc.downloadTool(libUrl);
229199
await io.cp(libPath, path.join(tempDir, 'node.lib'));
230200
} else {
231201
throw err;

src/distributions/base-models.ts

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ export interface NodeInputs {
44
auth?: string;
55
checkLatest: boolean;
66
stable: boolean;
7-
mirror: string;
8-
mirrorToken: string;
97
}
108

119
export interface INodeVersionInfo {

src/distributions/official_builds/official_builds.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ export default class OfficialBuilds extends BaseDistribution {
166166
return version;
167167
}
168168

169-
protected getDistributionUrl(mirror: string): string {
169+
protected getDistributionUrl(): string {
170170
return DEFAULT_NODE_MIRROR;
171171
}
172172

@@ -179,7 +179,7 @@ export default class OfficialBuilds extends BaseDistribution {
179179
return tc.getManifestFromRepo(
180180
'actions',
181181
'node-versions',
182-
this.nodeInfo.mirror ? this.nodeInfo.mirrorToken : this.nodeInfo.auth,
182+
this.nodeInfo.auth,
183183
'main'
184184
);
185185
}

src/main.ts

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,6 @@ export async function run() {
4040
if (version) {
4141
const token = core.getInput('token');
4242
const auth = !token ? undefined : `token ${token}`;
43-
const mirror = core.getInput('mirror');
44-
const mirrorToken = core.getInput('mirror-token');
4543
const stable =
4644
(core.getInput('stable') || 'true').toUpperCase() === 'TRUE';
4745
const checkLatest =
@@ -51,9 +49,7 @@ export async function run() {
5149
checkLatest,
5250
auth,
5351
stable,
54-
arch,
55-
mirror,
56-
mirrorToken
52+
arch
5753
};
5854
const nodeDistribution = getNodejsDistribution(nodejsInfo);
5955
await nodeDistribution.setupNodeJs();

0 commit comments

Comments
 (0)