1
0
mirror of https://github.com/actions/setup-node.git synced 2025-12-18 06:48:57 +08:00

Compare commits

...

25 Commits

Author SHA1 Message Date
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
Dmitry Shibanov
bea5baf987 change getinput to getstate for cache (#816) 2023-08-10 16:32:24 +02:00
dependabot[bot]
d82f92a0eb Bump word-wrap from 1.2.3 to 1.2.4 (#815)
Bumps [word-wrap](https://github.com/jonschlinkert/word-wrap) from 1.2.3 to 1.2.4.
- [Release notes](https://github.com/jonschlinkert/word-wrap/releases)
- [Commits](https://github.com/jonschlinkert/word-wrap/compare/1.2.3...1.2.4)

---
updated-dependencies:
- dependency-name: word-wrap
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2023-08-04 09:56:30 +02:00
Vytis Valentinavičius
ca2d4e0cdd feat: handling the case where "node" is used for tool-versions file. (#812) 2023-07-18 13:01:34 +02:00
Dmitry Shibanov
c7a93deeac resolve SymbolicLink (#809) 2023-07-13 14:06:23 +02:00
Dmitry Shibanov
34050076a5 Add check for existing paths (#803) 2023-07-13 14:03:41 +02:00
Jeff Wen
f8aa08ed8e Update check-dist workflow name (#710) 2023-07-12 19:35:39 +02:00
Louis Lam
e2d34eacc8 Fix armv7 cache issue (#794) 2023-07-12 16:09:57 +02:00
dependabot[bot]
ef9c88b169 Bump semver from 6.1.2 to 6.3.1 (#807) 2023-07-12 13:17:54 +02:00
dependabot[bot]
ea800d4ebc Bump tough-cookie and @azure/ms-rest-js (#802) 2023-07-12 12:47:57 +02:00
Dmitry Shibanov
cb95c398f6 Update toolkit cache to fix zstd (#804) 2023-07-12 12:13:18 +02:00
Olle Jonsson
69b2dd252e Refer to semver package name in README.md (#808) 2023-07-11 10:03:08 +02:00
34 changed files with 51590 additions and 5121 deletions

View File

@@ -1,4 +1,4 @@
name: Check dist/ name: Check dist
on: on:
push: push:

View File

@@ -98,8 +98,8 @@ 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
@@ -111,7 +111,7 @@ jobs:
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
@@ -173,7 +173,7 @@ jobs:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: prepare sub-projects - name: prepare sub-projects
run: __tests__/prepare-yarn-subprojects.sh run: __tests__/prepare-yarn-subprojects.sh keepcache keepcache
# expect # expect
# - no errors # - no errors

View File

@@ -158,7 +158,8 @@ jobs:
fail-fast: false fail-fast: false
matrix: matrix:
os: [ubuntu-latest, windows-latest, macos-latest] os: [ubuntu-latest, windows-latest, macos-latest]
node-version-file: [.nvmrc, .tool-versions, package.json] node-version-file:
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
steps: steps:
- uses: actions/checkout@v3 - uses: actions/checkout@v3
- name: Remove volta from package.json - name: Remove volta from package.json

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

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

Binary file not shown.

View File

@@ -99,7 +99,7 @@ For information regarding locally cached versions of Node.js on GitHub hosted ru
### Supported version syntax ### Supported version syntax
The `node-version` input supports the Semantic Versioning Specification, for more detailed examples please refer to the [documentation](https://github.com/npm/node-semver). The `node-version` input supports the Semantic Versioning Specification, for more detailed examples please refer to [the semver package documentation](https://github.com/npm/node-semver).
Examples: Examples:

View File

@@ -92,6 +92,9 @@ describe('run', () => {
it('Package manager is not valid, skip caching', async () => { it('Package manager is not valid, skip caching', async () => {
inputs['cache'] = 'yarn3'; inputs['cache'] = 'yarn3';
getStateSpy.mockImplementation(key =>
key === State.CachePackageManager ? inputs['cache'] : ''
);
await run(); await run();
@@ -108,7 +111,9 @@ describe('run', () => {
it('should not save cache for yarn1', async () => { it('should not save cache for yarn1', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation(key => getStateSpy.mockImplementation(key =>
key === State.CachePrimaryKey || key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePaths : key === State.CachePaths
? '["/foo/bar"]' ? '["/foo/bar"]'
@@ -117,8 +122,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
@@ -130,7 +135,9 @@ describe('run', () => {
it('should not save cache for yarn2', async () => { it('should not save cache for yarn2', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation(key => getStateSpy.mockImplementation(key =>
key === State.CachePrimaryKey || key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePaths : key === State.CachePaths
? '["/foo/bar"]' ? '["/foo/bar"]'
@@ -139,8 +146,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).toHaveBeenCalledWith( expect(infoSpy).toHaveBeenCalledWith(
@@ -152,7 +159,9 @@ describe('run', () => {
it('should not save cache for npm', async () => { it('should not save cache for npm', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation(key => getStateSpy.mockImplementation(key =>
key === State.CachePrimaryKey || key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePaths : key === State.CachePaths
? '["/foo/bar"]' ? '["/foo/bar"]'
@@ -162,8 +171,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(setFailedSpy).not.toHaveBeenCalled(); expect(setFailedSpy).not.toHaveBeenCalled();
@@ -172,7 +181,9 @@ describe('run', () => {
it('should not save cache for pnpm', async () => { it('should not save cache for pnpm', async () => {
inputs['cache'] = 'pnpm'; inputs['cache'] = 'pnpm';
getStateSpy.mockImplementation(key => getStateSpy.mockImplementation(key =>
key === State.CachePrimaryKey || key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CachePrimaryKey || key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePaths : key === State.CachePaths
? '["/foo/bar"]' ? '["/foo/bar"]'
@@ -181,8 +192,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(setFailedSpy).not.toHaveBeenCalled(); expect(setFailedSpy).not.toHaveBeenCalled();
@@ -193,7 +204,9 @@ describe('run', () => {
it('saves cache from yarn 1', async () => { it('saves cache from yarn 1', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? npmFileHash ? npmFileHash
@@ -204,8 +217,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
@@ -221,7 +234,9 @@ describe('run', () => {
it('saves cache from yarn 2', async () => { it('saves cache from yarn 2', async () => {
inputs['cache'] = 'yarn'; inputs['cache'] = 'yarn';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? yarnFileHash ? yarnFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? npmFileHash ? npmFileHash
@@ -232,8 +247,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
@@ -249,7 +264,9 @@ describe('run', () => {
it('saves cache from npm', async () => { it('saves cache from npm', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? npmFileHash ? npmFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? yarnFileHash ? yarnFileHash
@@ -260,8 +277,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
@@ -277,7 +294,9 @@ describe('run', () => {
it('saves cache from pnpm', async () => { it('saves cache from pnpm', async () => {
inputs['cache'] = 'pnpm'; inputs['cache'] = 'pnpm';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? pnpmFileHash ? pnpmFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? npmFileHash ? npmFileHash
@@ -288,8 +307,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
@@ -305,7 +324,9 @@ describe('run', () => {
it('save with -1 cacheId , should not fail workflow', async () => { it('save with -1 cacheId , should not fail workflow', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? npmFileHash ? npmFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? yarnFileHash ? yarnFileHash
@@ -319,8 +340,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(
@@ -336,7 +357,9 @@ describe('run', () => {
it('saves with error from toolkit, should fail workflow', async () => { it('saves with error from toolkit, should fail workflow', async () => {
inputs['cache'] = 'npm'; inputs['cache'] = 'npm';
getStateSpy.mockImplementation((key: string) => getStateSpy.mockImplementation((key: string) =>
key === State.CacheMatchedKey key === State.CachePackageManager
? inputs['cache']
: key === State.CacheMatchedKey
? npmFileHash ? npmFileHash
: key === State.CachePrimaryKey : key === State.CachePrimaryKey
? yarnFileHash ? yarnFileHash
@@ -350,8 +373,8 @@ describe('run', () => {
await run(); await run();
expect(getInputSpy).toHaveBeenCalled(); expect(getInputSpy).not.toHaveBeenCalled();
expect(getStateSpy).toHaveBeenCalledTimes(3); expect(getStateSpy).toHaveBeenCalledTimes(4);
expect(getCommandOutputSpy).toHaveBeenCalledTimes(0); expect(getCommandOutputSpy).toHaveBeenCalledTimes(0);
expect(debugSpy).toHaveBeenCalledTimes(0); expect(debugSpy).toHaveBeenCalledTimes(0);
expect(infoSpy).not.toHaveBeenCalledWith( expect(infoSpy).not.toHaveBeenCalledWith(

View File

@@ -23,8 +23,10 @@ describe('cache-utils', () => {
let isFeatureAvailable: jest.SpyInstance; let isFeatureAvailable: jest.SpyInstance;
let info: jest.SpyInstance; let info: jest.SpyInstance;
let warningSpy: jest.SpyInstance; let warningSpy: jest.SpyInstance;
let fsRealPathSyncSpy: jest.SpyInstance;
beforeEach(() => { beforeEach(() => {
console.log('::stop-commands::stoptoken');
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data'); process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
debugSpy = jest.spyOn(core, 'debug'); debugSpy = jest.spyOn(core, 'debug');
debugSpy.mockImplementation(msg => {}); debugSpy.mockImplementation(msg => {});
@@ -35,7 +37,23 @@ describe('cache-utils', () => {
isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable'); isFeatureAvailable = jest.spyOn(cache, 'isFeatureAvailable');
getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput'); getCommandOutputSpy = jest.spyOn(utils, 'getCommandOutput');
fsRealPathSyncSpy = jest.spyOn(fs, 'realpathSync');
fsRealPathSyncSpy.mockImplementation(dirName => {
return dirName;
}); });
});
afterEach(() => {
jest.resetAllMocks();
jest.clearAllMocks();
//jest.restoreAllMocks();
});
afterAll(async () => {
console.log('::stoptoken::');
jest.restoreAllMocks();
}, 100000);
describe('getPackageManagerInfo', () => { describe('getPackageManagerInfo', () => {
it.each<[string, PackageManagerInfo | null]>([ it.each<[string, PackageManagerInfo | null]>([

View File

@@ -0,0 +1 @@
node 14.0.0

View File

@@ -95,6 +95,8 @@ describe('setup-node', () => {
res = <INodeVersion[]>nodeTestDistRc; res = <INodeVersion[]>nodeTestDistRc;
} else if (url.includes('/nightly')) { } else if (url.includes('/nightly')) {
res = <INodeVersion[]>nodeTestDistNightly; res = <INodeVersion[]>nodeTestDistNightly;
} else if (url.includes('/v8-canary')) {
res = <INodeVersion[]>nodeV8CanaryTestDist;
} else { } else {
res = <INodeVersion[]>nodeTestDist; res = <INodeVersion[]>nodeTestDist;
} }

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'},

24594
dist/cache-save/index.js vendored

File diff suppressed because one or more lines are too long

25618
dist/setup/index.js vendored

File diff suppressed because one or more lines are too long

5684
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -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.1.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,5 +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 {State} from './constants'; import {State} from './constants';
import {getPackageManagerInfo} from './cache-utils'; import {getPackageManagerInfo} from './cache-utils';
@@ -13,17 +14,19 @@ process.on('uncaughtException', e => {
export async function run() { export async function run() {
try { try {
const cacheLock = core.getInput('cache'); 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);
const cachePaths = JSON.parse(core.getState(State.CachePaths) || '[]'); const cachePaths = JSON.parse(
core.getState(State.CachePaths) || '[]'
) as string[];
const packageManagerInfo = await getPackageManagerInfo(packageManager); const packageManagerInfo = await getPackageManagerInfo(packageManager);
if (!packageManagerInfo) { if (!packageManagerInfo) {
@@ -31,7 +34,7 @@ const cachePackages = async (packageManager: string) => {
return; return;
} }
if (cachePaths.length === 0) { if (!cachePaths.length) {
// TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?) // TODO: core.getInput has a bug - it can return undefined despite its definition (tests only?)
// export declare function getInput(name: string, options?: InputOptions): string; // export declare function getInput(name: string, options?: InputOptions): string;
const cacheDependencyPath = core.getInput('cache-dependency-path') || ''; const cacheDependencyPath = core.getInput('cache-dependency-path') || '';

View File

@@ -144,6 +144,7 @@ const getProjectDirectoriesFromCacheDependencyPath = async (
const existingDirectories: string[] = cacheDependenciesPaths const existingDirectories: string[] = cacheDependenciesPaths
.map(path.dirname) .map(path.dirname)
.filter(unique()) .filter(unique())
.map(dirName => fs.realpathSync(dirName))
.filter(directory => fs.lstatSync(directory).isDirectory()); .filter(directory => fs.lstatSync(directory).isDirectory());
if (!existingDirectories.length) if (!existingDirectories.length)

View File

@@ -5,6 +5,7 @@ export enum LockType {
} }
export enum State { export enum State {
CachePackageManager = 'SETUP_NODE_CACHE_PACKAGE_MANAGER',
CachePrimaryKey = 'CACHE_KEY', CachePrimaryKey = 'CACHE_KEY',
CacheMatchedKey = 'CACHE_RESULT', CacheMatchedKey = 'CACHE_RESULT',
CachePaths = 'CACHE_PATHS' CachePaths = 'CACHE_PATHS'

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';
@@ -88,7 +89,11 @@ export default abstract class BaseDistribution {
} }
protected findVersionInHostedToolCacheDirectory() { protected findVersionInHostedToolCacheDirectory() {
return tc.find('node', this.nodeInfo.versionSpec, this.nodeInfo.arch); return tc.find(
'node',
this.nodeInfo.versionSpec,
this.translateArchToDistUrl(this.nodeInfo.arch)
);
} }
protected async getNodeJsVersions(): Promise<INodeVersion[]> { protected async getNodeJsVersions(): Promise<INodeVersion[]> {
@@ -162,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,7 +62,10 @@ 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);
return;
}
let downloadPath = ''; let downloadPath = '';
try { try {
core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`); core.info(`Attempting to download ${this.nodeInfo.versionSpec}...`);
@@ -72,6 +76,7 @@ export default class OfficialBuilds extends BaseDistribution {
osArch, osArch,
manifest manifest
); );
if (versionInfo) { if (versionInfo) {
core.info( core.info(
`Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}` `Acquiring ${versionInfo.resolvedVersion} - ${versionInfo.arch} from ${versionInfo.downloadUrl}`
@@ -100,24 +105,14 @@ export default class OfficialBuilds extends BaseDistribution {
`Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded` `Received HTTP status code ${err.httpStatusCode}. This usually indicates the rate limit has been exceeded`
); );
} else { } else {
core.info(err.message); core.info((err as Error).message);
} }
core.debug(err.stack); core.debug((err as Error).stack ?? 'empty stack');
core.info('Falling back to download directly from Node'); 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

@@ -9,6 +9,7 @@ import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils'; import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory'; import {getNodejsDistribution} from './distributions/installer-factory';
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util'; import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
import {State} from './constants';
export async function run() { export async function run() {
try { try {
@@ -60,6 +61,7 @@ export async function run() {
} }
if (cache && isCacheFeatureAvailable()) { if (cache && isCacheFeatureAvailable()) {
core.saveState(State.CachePackageManager, cache);
const cacheDependencyPath = core.getInput('cache-dependency-path'); const cacheDependencyPath = core.getInput('cache-dependency-path');
await restoreCache(cache, cacheDependencyPath); await restoreCache(cache, cacheDependencyPath);
} }
@@ -73,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);
} }
} }

View File

@@ -13,7 +13,7 @@ export function parseNodeVersionFile(contents: string): string {
} }
if (!nodeVersion) { if (!nodeVersion) {
const found = contents.match(/^(?:nodejs\s+)?v?(?<version>[^\s]+)$/m); const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = found?.groups?.version; nodeVersion = found?.groups?.version;
} }