1
0
mirror of https://github.com/actions/setup-node.git synced 2025-12-17 22:38:59 +08:00

Compare commits

...

16 Commits

Author SHA1 Message Date
aparnajyothi-y
3235b87634 add publish immutable actions (#1281) 2025-04-17 08:56:37 -05:00
gowridurgad
dbe1369d7b v3 - upgrade @actions/cache (#1270)
* actions/cache upgarde

* macos-latest to macos-13

* fix check failures

---------

Co-authored-by: “gowridurgad” <“hgowridurgad@github.com>
2025-04-11 16:22:17 -05:00
Dmitry Shibanov
1a4442cacd Update toolkit cache and core (#875) 2023-10-23 12:20:07 +02:00
Nikolai Laevskii
6e9e44895f Merge pull request #872 from akv-platform/add-notice-about-binaries-not-being-updated
Add notice about binaries not being updated yet
2023-10-19 17:20:27 +02:00
Nikolai Laevskii
e52912ef25 Update tests 2023-10-19 17:12:39 +02:00
Nikolai Laevskii
ac16ae42d7 Update message to use waning instead of info 2023-10-19 16:59:10 +02:00
Nikolai Laevskii
5a8d9111e3 Update build 2023-10-19 14:31:08 +02:00
Nikolai Laevskii
9e956a555c Add notice about binaries not being updated yet 2023-10-19 13:43:56 +02:00
dependabot[bot]
7da2a7eb0c Bump @babel/traverse from 7.15.4 to 7.23.2 (#870) 2023-10-19 10:40:59 +02:00
Nikolai Laevskii
2a017f350d Merge pull request #859 from actions/update-temp-directory-creation
Update temp directory creation
2023-10-09 07:12:35 +02:00
Dmitry Shibanov
72c43c2d8f Update semver (#861) 2023-09-27 12:57:35 +02:00
Nikolai Laevskii
d3ace34546 Update build 2023-09-25 16:37:45 +02:00
Nikolai Laevskii
acbf0586b1 Fix typo 2023-09-25 15:58:01 +02:00
Nikolai Laevskii
f1744b62b7 Update license 2023-09-25 15:58:01 +02:00
Nikolai Laevskii
2651591c72 Update temporary directory creation 2023-09-25 15:58:01 +02:00
Dmitry Shibanov
5e21ff4d9b Remove filter for cached paths (#831) 2023-08-15 15:53:46 +02:00
27 changed files with 64283 additions and 6503 deletions

View File

@@ -18,7 +18,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [12, 14, 16] node-version: [12, 14, 16]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -41,7 +41,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [12, 14, 16] node-version: [12, 14, 16]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -74,7 +74,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [14, 16] node-version: [14, 16]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -98,20 +98,20 @@ jobs:
run: __tests__/verify-node.sh "${{ matrix.node-version }}" run: __tests__/verify-node.sh "${{ matrix.node-version }}"
shell: bash shell: bash
node-yarn2-depencies-caching: node-yarn3-depencies-caching:
name: Test yarn 2 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) name: Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }})
runs-on: ${{ matrix.os }} runs-on: ${{ matrix.os }}
env: env:
YARN_ENABLE_IMMUTABLE_INSTALLS: false YARN_ENABLE_IMMUTABLE_INSTALLS: false
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [12, 14, 16] node-version: [12, 14, 16]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Update yarn - name: Update yarn
run: yarn set version berry run: yarn set version 3.6.4
- name: Yarn version - name: Yarn version
run: yarn --version run: yarn --version
- name: Generate simple .yarnrc.yml - name: Generate simple .yarnrc.yml

View File

@@ -0,0 +1,20 @@
name: 'Publish Immutable Action Version'
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
packages: write
steps:
- name: Checking out
uses: actions/checkout@v4
- name: Publish
id: publish
uses: actions/publish-immutable-action@v0.0.4

View File

@@ -17,7 +17,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [10, 12, 14] node-version: [10, 12, 14]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -34,7 +34,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1] node-version: [lts/dubnium, lts/erbium, lts/fermium, lts/*, lts/-1]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -43,7 +43,7 @@ jobs:
with: with:
node-version: ${{ matrix.node-version }} node-version: ${{ matrix.node-version }}
check-latest: true check-latest: true
- if: runner.os != 'Windows' - if: runner.os != 'Windows' && runner.os != 'macos'
name: Verify node and npm name: Verify node and npm
run: | run: |
. "$NVM_DIR/nvm.sh" . "$NVM_DIR/nvm.sh"
@@ -56,7 +56,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: node-version:
[ [
'20-v8-canary', '20-v8-canary',
@@ -81,7 +81,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: node-version:
[16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly] [16.0.0-nightly20210420a0261d231c, 17-nightly, 18.0.0-nightly]
steps: steps:
@@ -102,7 +102,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [16.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0] node-version: [16.0.0-rc.1, 18.0.0-rc.2, 19.0.0-rc.0]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -122,7 +122,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [10.15, 12.16.0, 14.2.0, 16.3.0] node-version: [10.15, 12.16.0, 14.2.0, 16.3.0]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -139,7 +139,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [10, 12, 14] node-version: [10, 12, 14]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -157,7 +157,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version-file: node-version-file:
[.nvmrc, .tool-versions, .tool-versions-node, package.json] [.nvmrc, .tool-versions, .tool-versions-node, package.json]
steps: steps:
@@ -177,7 +177,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Setup node from node version file - name: Setup node from node version file
@@ -192,7 +192,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [11, 13] node-version: [11, 13]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
@@ -209,7 +209,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
# test old versions which didn't have npm and layout different # test old versions which didn't have npm and layout different
@@ -239,7 +239,7 @@ jobs:
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-13]
node-version: [current, latest, node] node-version: [current, latest, node]
steps: steps:
- name: Get node version - name: Get node version

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/@fastify/busboy.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/@protobuf-ts/plugin.dep.yml generated Normal file

Binary file not shown.

BIN
.licenses/npm/@protobuf-ts/protoc.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/@protobuf-ts/runtime.dep.yml generated Normal file

Binary file not shown.

Binary file not shown.

BIN
.licenses/npm/typescript.dep.yml generated Normal file

Binary file not shown.

BIN
.licenses/npm/uuid-9.0.0.dep.yml generated Normal file

Binary file not shown.

View File

@@ -357,6 +357,41 @@ describe('setup-node', () => {
expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`); expect(cnSpy).toHaveBeenCalledWith(`::error::${errMsg}${osm.EOL}`);
}); });
it('reports when download failed but version exists', async () => {
os.platform = 'linux';
os.arch = 'x64';
// a version which is not in the manifest but is in node dist
const versionSpec = '11.15.0';
inputs['node-version'] = versionSpec;
inputs['always-auth'] = false;
inputs['token'] = 'faketoken';
// ... but not in the local cache
findSpy.mockImplementation(() => '');
dlSpy.mockImplementationOnce(async () => {
throw new tc.HTTPError(404);
});
await main.run();
expect(getManifestSpy).toHaveBeenCalled();
expect(logSpy).toHaveBeenCalledWith(
`Attempting to download ${versionSpec}...`
);
expect(logSpy).toHaveBeenCalledWith(
'Not found in manifest. Falling back to download directly from Node'
);
expect(dlSpy).toHaveBeenCalled();
expect(warningSpy).toHaveBeenCalledWith(
`Node version ${versionSpec} for platform ${os.platform} and architecture ${os.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'To resolve this issue you may either fall back to the older version or try again later.'
);
});
it('acquires specified architecture of node', async () => { it('acquires specified architecture of node', async () => {
for (const {arch, version, osSpec} of [ for (const {arch, version, osSpec} of [
{arch: 'x86', version: '12.16.2', osSpec: 'win32'}, {arch: 'x86', version: '12.16.2', osSpec: 'win32'},

30772
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

33963
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

5787
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -25,7 +25,7 @@
"author": "GitHub", "author": "GitHub",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/cache": "^3.0.4", "@actions/cache": "^4.0.3",
"@actions/core": "^1.10.0", "@actions/core": "^1.10.0",
"@actions/exec": "^1.1.0", "@actions/exec": "^1.1.0",
"@actions/github": "^1.1.0", "@actions/github": "^1.1.0",
@@ -33,24 +33,26 @@
"@actions/http-client": "^1.0.11", "@actions/http-client": "^1.0.11",
"@actions/io": "^1.0.2", "@actions/io": "^1.0.2",
"@actions/tool-cache": "^1.5.4", "@actions/tool-cache": "^1.5.4",
"semver": "^6.3.1" "semver": "^6.3.1",
"uuid": "^9.0.0"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.2", "@types/jest": "^29.5.6",
"@types/node": "^16.11.25", "@types/node": "^16.11.25",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@types/uuid": "^9.0.3",
"@typescript-eslint/eslint-plugin": "^5.54.0", "@typescript-eslint/eslint-plugin": "^5.54.0",
"@typescript-eslint/parser": "^5.54.0", "@typescript-eslint/parser": "^5.54.0",
"@vercel/ncc": "^0.33.4", "@vercel/ncc": "^0.38.0",
"eslint": "^8.35.0", "eslint": "^8.35.0",
"eslint-config-prettier": "^8.6.0", "eslint-config-prettier": "^8.6.0",
"eslint-plugin-jest": "^27.2.1", "eslint-plugin-jest": "^27.2.1",
"eslint-plugin-node": "^11.1.0", "eslint-plugin-node": "^11.1.0",
"jest": "^27.2.5", "jest": "^29.7.0",
"jest-circus": "^27.2.5", "jest-circus": "^29.7.0",
"jest-each": "^27.2.5", "jest-each": "^29.7.0",
"prettier": "^2.8.4", "prettier": "^2.8.4",
"ts-jest": "^27.0.5", "ts-jest": "^29.1.1",
"typescript": "^4.2.3" "typescript": "^4.2.3"
} }
} }

View File

@@ -1,8 +1,6 @@
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as cache from '@actions/cache'; import * as cache from '@actions/cache';
import fs from 'fs';
import {State} from './constants'; import {State} from './constants';
import {getPackageManagerInfo} from './cache-utils'; import {getPackageManagerInfo} from './cache-utils';
@@ -19,17 +17,16 @@ export async function run() {
const cacheLock = core.getState(State.CachePackageManager); const cacheLock = core.getState(State.CachePackageManager);
await cachePackages(cacheLock); await cachePackages(cacheLock);
} catch (error) { } catch (error) {
core.setFailed(error.message); core.setFailed((error as Error).message);
} }
} }
const cachePackages = async (packageManager: string) => { const cachePackages = async (packageManager: string) => {
const state = core.getState(State.CacheMatchedKey); const state = core.getState(State.CacheMatchedKey);
const primaryKey = core.getState(State.CachePrimaryKey); const primaryKey = core.getState(State.CachePrimaryKey);
let cachePaths = JSON.parse( const cachePaths = JSON.parse(
core.getState(State.CachePaths) || '[]' core.getState(State.CachePaths) || '[]'
) as string[]; ) as string[];
cachePaths = cachePaths.filter(fs.existsSync);
const packageManagerInfo = await getPackageManagerInfo(packageManager); const packageManagerInfo = await getPackageManagerInfo(packageManager);
if (!packageManagerInfo) { if (!packageManagerInfo) {

View File

@@ -1,3 +1,4 @@
import {v4 as uuidv4} from 'uuid';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import * as hc from '@actions/http-client'; import * as hc from '@actions/http-client';
import * as core from '@actions/core'; import * as core from '@actions/core';
@@ -166,9 +167,8 @@ export default abstract class BaseDistribution {
const initialUrl = this.getDistributionUrl(); const initialUrl = this.getDistributionUrl();
const osArch: string = this.translateArchToDistUrl(arch); const osArch: string = this.translateArchToDistUrl(arch);
// Create temporary folder to download in to // Create temporary folder to download to
const tempDownloadFolder: string = const tempDownloadFolder = `temp_${uuidv4()}`;
'temp_' + Math.floor(Math.random() * 2000000000);
const tempDirectory = process.env['RUNNER_TEMP'] || ''; const tempDirectory = process.env['RUNNER_TEMP'] || '';
assert.ok(tempDirectory, 'Expected RUNNER_TEMP to be defined'); assert.ok(tempDirectory, 'Expected RUNNER_TEMP to be defined');
const tempDir: string = path.join(tempDirectory, tempDownloadFolder); const tempDir: string = path.join(tempDirectory, tempDownloadFolder);

View File

@@ -18,6 +18,7 @@ export default class OfficialBuilds extends BaseDistribution {
let manifest: tc.IToolRelease[] | undefined; let manifest: tc.IToolRelease[] | undefined;
let nodeJsVersions: INodeVersion[] | undefined; let nodeJsVersions: INodeVersion[] | undefined;
const osArch = this.translateArchToDistUrl(this.nodeInfo.arch); const osArch = this.translateArchToDistUrl(this.nodeInfo.arch);
if (this.isLtsAlias(this.nodeInfo.versionSpec)) { if (this.isLtsAlias(this.nodeInfo.versionSpec)) {
core.info('Attempt to resolve LTS alias from manifest...'); core.info('Attempt to resolve LTS alias from manifest...');
@@ -61,63 +62,57 @@ export default class OfficialBuilds extends BaseDistribution {
if (toolPath) { if (toolPath) {
core.info(`Found in cache @ ${toolPath}`); core.info(`Found in cache @ ${toolPath}`);
} else { this.addToolPath(toolPath);
let downloadPath = ''; return;
try { }
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
const versionInfo = await this.getInfoFromManifest( let downloadPath = '';
this.nodeInfo.versionSpec, try {
this.nodeInfo.stable, core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
osArch,
manifest const versionInfo = await this.getInfoFromManifest(
this.nodeInfo.versionSpec,
this.nodeInfo.stable,
osArch,
manifest
);
if (versionInfo) {
core.info(
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
);
downloadPath = await tc.downloadTool(
versionInfo.downloadUrl,
undefined,
this.nodeInfo.auth
); );
if (versionInfo) {
core.info(
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
);
downloadPath = await tc.downloadTool(
versionInfo.downloadUrl,
undefined,
this.nodeInfo.auth
);
if (downloadPath) { if (downloadPath) {
toolPath = await this.extractArchive(downloadPath, versionInfo); toolPath = await this.extractArchive(downloadPath, versionInfo);
}
} else {
core.info(
'Not found in manifest. Falling back to download directly from Node'
);
} }
} catch (err) { } else {
// Rate limit? core.info(
if ( 'Not found in manifest. Falling back to download directly from Node'
err instanceof tc.HTTPError && );
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info(err.message);
}
core.debug(err.stack);
core.info('Falling back to download directly from Node');
} }
} catch (err) {
// Rate limit?
if (
err instanceof tc.HTTPError &&
(err.httpStatusCode === 403 || err.httpStatusCode === 429)
) {
core.info(
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
);
} else {
core.info((err as Error).message);
}
core.debug((err as Error).stack ?? 'empty stack');
core.info('Falling back to download directly from Node');
}
if (!toolPath) { if (!toolPath) {
const nodeJsVersions = await this.getNodeJsVersions(); toolPath = await this.downloadDirectlyFromNode();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion);
toolPath = await this.downloadNodejs(toolName);
}
} }
if (this.osPlat != 'win32') { if (this.osPlat != 'win32') {
@@ -127,6 +122,43 @@ export default class OfficialBuilds extends BaseDistribution {
core.addPath(toolPath); core.addPath(toolPath);
} }
protected addToolPath(toolPath: string) {
if (this.osPlat != 'win32') {
toolPath = path.join(toolPath, 'bin');
}
core.addPath(toolPath);
}
protected async downloadDirectlyFromNode() {
const nodeJsVersions = await this.getNodeJsVersions();
const versions = this.filterVersions(nodeJsVersions);
const evaluatedVersion = this.evaluateVersions(versions);
if (!evaluatedVersion) {
throw new Error(
`Unable to find Node version '${this.nodeInfo.versionSpec}' for platform ${this.osPlat} and architecture ${this.nodeInfo.arch}.`
);
}
const toolName = this.getNodejsDistInfo(evaluatedVersion);
try {
const toolPath = await this.downloadNodejs(toolName);
return toolPath;
} catch (error) {
if (error instanceof tc.HTTPError && error.httpStatusCode === 404) {
core.warning(
`Node version ${this.nodeInfo.versionSpec} for platform ${this.osPlat} and architecture ${this.nodeInfo.arch} was found but failed to download. ` +
'This usually happens when downloadable binaries are not fully updated at https://nodejs.org/. ' +
'To resolve this issue you may either fall back to the older version or try again later.'
);
}
throw error;
}
}
protected evaluateVersions(versions: string[]): string { protected evaluateVersions(versions: string[]): string {
let version = ''; let version = '';
@@ -214,7 +246,7 @@ export default class OfficialBuilds extends BaseDistribution {
return info?.resolvedVersion; return info?.resolvedVersion;
} catch (err) { } catch (err) {
core.info('Unable to resolve version from manifest...'); core.info('Unable to resolve version from manifest...');
core.debug(err.message); core.debug((err as Error).message);
} }
} }

View File

@@ -75,7 +75,7 @@ export async function run() {
`##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}` `##[add-matcher]${path.join(matchersPath, 'eslint-compact.json')}`
); );
} catch (err) { } catch (err) {
core.setFailed(err.message); core.setFailed((err as Error).message);
} }
} }