Add support for volta.extends (#921)
Some checks failed
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 10s
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 11s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 10s
e2e-cache / Test yarn subprojects (14) (push) Failing after 10s
e2e-cache / Test yarn subprojects (16) (push) Failing after 10s
e2e-cache / Test yarn subprojects all locally managed (14) (push) Failing after 12s
e2e-cache / Test yarn subprojects some locally managed (14) (push) Failing after 11s
e2e-cache / Test yarn subprojects some locally managed (16) (push) Failing after 10s
proxy / test-proxy (push) Failing after 33s
e2e-cache / Test yarn subprojects managed by git (12) (push) Failing after 5m22s
versions / local-cache (14, ubuntu-latest) (push) Failing after 5m52s
versions / v8-canary-syntax (20-v8-canary, ubuntu-latest) (push) Successful in 32s
Basic validation / Basic validation (push) Failing after 14m58s
Check dist / Check dist/ (push) Failing after 15m0s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 15m4s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 15m6s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 15m7s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, ubuntu-latest) (push) Failing after 15m8s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 15m10s
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 13m51s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, ubuntu-latest) (push) Failing after 13m34s
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, ubuntu-latest) (push) Failing after 13m5s
e2e-cache / Test yarn subprojects (12) (push) Failing after 13m0s
e2e-cache / Test yarn subprojects all locally managed (12) (push) Failing after 12m19s
e2e-cache / Test yarn subprojects all locally managed (16) (push) Failing after 12m7s
e2e-cache / Test yarn subprojects some locally managed (12) (push) Failing after 12m9s
versions / manifest (10.15, ubuntu-latest) (push) Successful in 44s
versions / lts-syntax (lts/fermium, ubuntu-latest) (push) Failing after 5m16s
Licensed / Licensed (push) Failing after 14m33s
proxy / test-bypass-proxy (push) Failing after 14m28s
versions / local-cache (10, ubuntu-latest) (push) Failing after 13m57s
e2e-cache / Test yarn subprojects managed by git (16) (push) Failing after 19m37s
versions / local-cache (12, ubuntu-latest) (push) Failing after 18m40s
versions / lts-syntax (lts/-1, ubuntu-latest) (push) Failing after 17m19s
versions / check-latest (12, ubuntu-latest) (push) Successful in 5m37s
versions / version-file (.tool-versions-node, ubuntu-latest) (push) Successful in 28s
e2e-cache / Test yarn subprojects managed by git (14) (push) Failing after 24m43s
versions / lts-syntax (lts/*, ubuntu-latest) (push) Failing after 22m20s
versions / lts-syntax (lts/dubnium, ubuntu-latest) (push) Failing after 21m47s
versions / lts-syntax (lts/erbium, ubuntu-latest) (push) Failing after 18m23s
versions / v8-canary-syntax (20.0.0-v8-canary, ubuntu-latest) (push) Failing after 14m36s
versions / nightly-syntax (16.0.0-nightly20210420a0261d231c, ubuntu-latest) (push) Failing after 13m37s
versions / nightly-syntax (18.0.0-nightly, ubuntu-latest) (push) Failing after 13m9s
versions / rc-syntax (16.0.0-rc.1, ubuntu-latest) (push) Failing after 12m21s
versions / rc-syntax (18.0.0-rc.2, ubuntu-latest) (push) Failing after 12m3s
versions / rc-syntax (19.0.0-rc.0, ubuntu-latest) (push) Failing after 12m0s
versions / manifest (12.16.0, ubuntu-latest) (push) Failing after 11m16s
versions / nightly-syntax (17-nightly, ubuntu-latest) (push) Failing after 22m50s
versions / manifest (14.2.0, ubuntu-latest) (push) Failing after 19m51s
versions / manifest (16.3.0, ubuntu-latest) (push) Failing after 19m23s
versions / check-latest (10, ubuntu-latest) (push) Failing after 19m25s
versions / check-latest (14, ubuntu-latest) (push) Failing after 19m8s
versions / version-file (.nvmrc, ubuntu-latest) (push) Failing after 18m49s
versions / version-file (package.json, ubuntu-latest) (push) Failing after 12m5s
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, ubuntu-latest) (push) Failing after 28m41s
versions / version-file (.tool-versions, ubuntu-latest) (push) Failing after 17m46s
versions / version-file-volta (ubuntu-latest) (push) Failing after 16m45s
versions / version-file-volta-extends (ubuntu-latest) (push) Failing after 15m33s
versions / node-dist (11, ubuntu-latest) (push) Failing after 15m34s
versions / node-dist (13, ubuntu-latest) (push) Failing after 15m24s
versions / old-versions (ubuntu-latest) (push) Failing after 14m56s
versions / node-latest-aliases (current, ubuntu-latest) (push) Failing after 14m55s
versions / node-latest-aliases (latest, ubuntu-latest) (push) Failing after 13m51s
versions / node-latest-aliases (node, ubuntu-latest) (push) Failing after 13m54s
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test npm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test pnpm (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 1 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (12, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (14, windows-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, macos-latest) (push) Has been cancelled
e2e-cache / Test yarn 3 (Node ${{ matrix.node-version}}, ${{ matrix.os }}) (16, windows-latest) (push) Has been cancelled
versions / local-cache (10, macos-latest) (push) Has been cancelled
versions / local-cache (10, windows-latest) (push) Has been cancelled
versions / local-cache (12, macos-latest) (push) Has been cancelled
versions / local-cache (12, windows-latest) (push) Has been cancelled
versions / local-cache (14, macos-latest) (push) Has been cancelled
versions / local-cache (14, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/*, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/-1, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/-1, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/dubnium, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/erbium, windows-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, macos-latest) (push) Has been cancelled
versions / lts-syntax (lts/fermium, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20-v8-canary, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary, windows-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, macos-latest) (push) Has been cancelled
versions / v8-canary-syntax (20.0.0-v8-canary20221101e50e45c9f8, windows-latest) (push) Has been cancelled
versions / nightly-syntax (16.0.0-nightly20210420a0261d231c, macos-latest) (push) Has been cancelled
versions / nightly-syntax (16.0.0-nightly20210420a0261d231c, windows-latest) (push) Has been cancelled
versions / nightly-syntax (17-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (17-nightly, windows-latest) (push) Has been cancelled
versions / nightly-syntax (18.0.0-nightly, macos-latest) (push) Has been cancelled
versions / nightly-syntax (18.0.0-nightly, windows-latest) (push) Has been cancelled
versions / rc-syntax (16.0.0-rc.1, macos-latest) (push) Has been cancelled
versions / rc-syntax (16.0.0-rc.1, windows-latest) (push) Has been cancelled
versions / rc-syntax (18.0.0-rc.2, macos-latest) (push) Has been cancelled
versions / rc-syntax (18.0.0-rc.2, windows-latest) (push) Has been cancelled
versions / rc-syntax (19.0.0-rc.0, macos-latest) (push) Has been cancelled
versions / rc-syntax (19.0.0-rc.0, windows-latest) (push) Has been cancelled
versions / manifest (10.15, macos-latest) (push) Has been cancelled
versions / manifest (10.15, windows-latest) (push) Has been cancelled
versions / manifest (12.16.0, macos-latest) (push) Has been cancelled
versions / manifest (12.16.0, windows-latest) (push) Has been cancelled
versions / manifest (14.2.0, macos-latest) (push) Has been cancelled
versions / manifest (14.2.0, windows-latest) (push) Has been cancelled
versions / manifest (16.3.0, macos-latest) (push) Has been cancelled
versions / manifest (16.3.0, windows-latest) (push) Has been cancelled
versions / check-latest (10, macos-latest) (push) Has been cancelled
versions / check-latest (10, windows-latest) (push) Has been cancelled
versions / check-latest (12, macos-latest) (push) Has been cancelled
versions / check-latest (12, windows-latest) (push) Has been cancelled
versions / check-latest (14, macos-latest) (push) Has been cancelled
versions / check-latest (14, windows-latest) (push) Has been cancelled
versions / version-file (.nvmrc, macos-latest) (push) Has been cancelled
versions / version-file (.nvmrc, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions, windows-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, macos-latest) (push) Has been cancelled
versions / version-file (.tool-versions-node, windows-latest) (push) Has been cancelled
versions / version-file (package.json, macos-latest) (push) Has been cancelled
versions / version-file (package.json, windows-latest) (push) Has been cancelled
versions / version-file-volta (macos-latest) (push) Has been cancelled
versions / version-file-volta (windows-latest) (push) Has been cancelled
versions / version-file-volta-extends (macos-latest) (push) Has been cancelled
versions / version-file-volta-extends (windows-latest) (push) Has been cancelled
versions / node-dist (11, macos-latest) (push) Has been cancelled
versions / node-dist (11, windows-latest) (push) Has been cancelled
versions / node-dist (13, macos-latest) (push) Has been cancelled
versions / node-dist (13, windows-latest) (push) Has been cancelled
versions / old-versions (macos-latest) (push) Has been cancelled
versions / old-versions (windows-latest) (push) Has been cancelled
versions / arch (push) Has been cancelled
versions / node-latest-aliases (current, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (current, windows-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (latest, windows-latest) (push) Has been cancelled
versions / node-latest-aliases (node, macos-latest) (push) Has been cancelled
versions / node-latest-aliases (node, windows-latest) (push) Has been cancelled
Update configuration files / Update configuration files (push) Failing after 14m0s
CodeQL analysis / CodeQL analysis (push) Failing after 14m1s

* Add support for `volta.extends`

* Code review
This commit is contained in:
Manta Anantachai S 2023-12-29 16:31:21 +07:00 committed by GitHub
parent b39b52d121
commit d86ebcd40b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 211 additions and 193 deletions

View File

@ -162,9 +162,6 @@ jobs:
[.nvmrc, .tool-versions, .tool-versions-node, package.json]
steps:
- uses: actions/checkout@v4
- name: Remove volta from package.json
shell: bash
run: cat <<< "$(jq 'del(.volta)' ./__tests__/data/package.json)" > ./__tests__/data/package.json
- name: Setup node from node version file
uses: ./
with:
@ -183,7 +180,22 @@ jobs:
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/package.json'
node-version-file: '__tests__/data/package-volta.json'
- name: Verify node
run: __tests__/verify-node.sh 16
version-file-volta-extends:
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Setup node from node version file
uses: ./
with:
node-version-file: '__tests__/data/package-volta-extends.json'
- name: Verify node
run: __tests__/verify-node.sh 16

View File

@ -0,0 +1,5 @@
{
"volta": {
"extends": "./package-volta.json"
}
}

View File

@ -0,0 +1,8 @@
{
"engines": {
"node": "^14.0.0"
},
"volta": {
"node": "16.0.0"
}
}

View File

@ -1,8 +1,5 @@
{
"engines": {
"node": "^14.0.0"
},
"volta": {
"node": "16.0.0"
}
}

View File

@ -24,11 +24,9 @@ describe('main tests', () => {
let startGroupSpy: jest.SpyInstance;
let endGroupSpy: jest.SpyInstance;
let existsSpy: jest.SpyInstance;
let getExecOutputSpy: jest.SpyInstance;
let parseNodeVersionSpy: jest.SpyInstance;
let getNodeVersionFromFileSpy: jest.SpyInstance;
let cnSpy: jest.SpyInstance;
let findSpy: jest.SpyInstance;
let isCacheActionAvailable: jest.SpyInstance;
@ -41,6 +39,7 @@ describe('main tests', () => {
// node
os = {};
console.log('::stop-commands::stoptoken');
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
process.env['GITHUB_OUTPUT'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out
infoSpy = jest.spyOn(core, 'info');
@ -62,12 +61,10 @@ describe('main tests', () => {
isCacheActionAvailable = jest.spyOn(cache, 'isFeatureAvailable');
existsSpy = jest.spyOn(fs, 'existsSync');
cnSpy = jest.spyOn(process.stdout, 'write');
cnSpy.mockImplementation(line => {
// uncomment to debug
// process.stderr.write('write:' + line + '\n');
process.stderr.write('write:' + line + '\n');
});
setupNodeJsSpy = jest.spyOn(OfficialBuilds.prototype, 'setupNodeJs');
@ -85,7 +82,7 @@ describe('main tests', () => {
jest.restoreAllMocks();
}, 100000);
describe('parseNodeVersionFile', () => {
describe('getNodeVersionFromFile', () => {
each`
contents | expected
${'12'} | ${'12'}
@ -100,10 +97,27 @@ describe('main tests', () => {
${'unknown format'} | ${'unknown format'}
${' 14.1.0 '} | ${'14.1.0'}
${'{"volta": {"node": ">=14.0.0 <=17.0.0"}}'}| ${'>=14.0.0 <=17.0.0'}
${'{"volta": {"extends": "./package.json"}}'}| ${'18.0.0'}
${'{"engines": {"node": "17.0.0"}}'} | ${'17.0.0'}
${'{}'} | ${null}
`.it('parses "$contents"', ({contents, expected}) => {
expect(util.parseNodeVersionFile(contents)).toBe(expected);
const existsSpy = jest.spyOn(fs, 'existsSync');
existsSpy.mockImplementation(() => true);
const readFileSpy = jest.spyOn(fs, 'readFileSync');
readFileSpy.mockImplementation(filePath => {
if (
typeof filePath === 'string' &&
path.basename(filePath) === 'package.json'
) {
// Special case for volta.extends
return '{"volta": {"node": "18.0.0"}}';
}
return contents;
});
expect(util.getNodeVersionFromFile('file')).toBe(expected);
});
});
@ -142,10 +156,17 @@ describe('main tests', () => {
describe('node-version-file flag', () => {
beforeEach(() => {
parseNodeVersionSpy = jest.spyOn(util, 'parseNodeVersionFile');
delete inputs['node-version'];
inputs['node-version-file'] = '.nvmrc';
getNodeVersionFromFileSpy = jest.spyOn(util, 'getNodeVersionFromFile');
});
it('not used if node-version is provided', async () => {
afterEach(() => {
getNodeVersionFromFileSpy.mockRestore();
});
it('does not read node-version-file if node-version is provided', async () => {
// Arrange
inputs['node-version'] = '12';
@ -153,107 +174,54 @@ describe('main tests', () => {
await main.run();
// Assert
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
}, 10000);
it('not used if node-version-file not provided', async () => {
// Act
await main.run();
// Assert
expect(parseNodeVersionSpy).toHaveBeenCalledTimes(0);
});
it('reads node-version-file if provided', async () => {
// Arrange
const versionSpec = 'v14';
const versionFile = '.nvmrc';
const expectedVersionSpec = '14';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
inputs['node-version-file'] = versionFile;
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalledTimes(1);
expect(existsSpy).toHaveReturnedWith(true);
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
expect(infoSpy).toHaveBeenCalledWith(
`Resolved ${versionFile} as ${expectedVersionSpec}`
);
}, 10000);
it('reads package.json as node-version-file if provided', async () => {
// Arrange
const versionSpec = fs.readFileSync(
path.join(__dirname, 'data/package.json'),
'utf-8'
);
const versionFile = 'package.json';
const expectedVersionSpec = '14';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, 'data');
inputs['node-version-file'] = versionFile;
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalledTimes(1);
expect(existsSpy).toHaveReturnedWith(true);
expect(parseNodeVersionSpy).toHaveBeenCalledWith(versionSpec);
expect(infoSpy).toHaveBeenCalledWith(
`Resolved ${versionFile} as ${expectedVersionSpec}`
);
}, 10000);
it('both node-version-file and node-version are provided', async () => {
inputs['node-version'] = '12';
const versionSpec = 'v14';
const versionFile = '.nvmrc';
const expectedVersionSpec = '14';
process.env['GITHUB_WORKSPACE'] = path.join(__dirname, '..');
inputs['node-version-file'] = versionFile;
parseNodeVersionSpy.mockImplementation(() => expectedVersionSpec);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalledTimes(0);
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
expect(inputs['node-version']).toBeDefined();
expect(inputs['node-version-file']).toBeDefined();
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled();
expect(warningSpy).toHaveBeenCalledWith(
'Both node-version and node-version-file inputs are specified, only node-version will be used'
);
});
it('should throw an error if node-version-file is not found', async () => {
const versionFile = '.nvmrc';
const versionFilePath = path.join(__dirname, '..', versionFile);
inputs['node-version-file'] = versionFile;
it('does not read node-version-file if node-version-file is not provided', async () => {
// Arrange
delete inputs['node-version-file'];
inSpy.mockImplementation(name => inputs[name]);
existsSpy.mockImplementationOnce(
input => input === path.join(__dirname, 'data', versionFile)
// Act
await main.run();
// Assert
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled();
});
it('reads node-version-file', async () => {
// Arrange
const expectedVersionSpec = '14';
getNodeVersionFromFileSpy.mockImplementation(() => expectedVersionSpec);
// Act
await main.run();
// Assert
expect(getNodeVersionFromFileSpy).toHaveBeenCalled();
expect(infoSpy).toHaveBeenCalledWith(
`Resolved ${inputs['node-version-file']} as ${expectedVersionSpec}`
);
}, 10000);
it('should throw an error if node-version-file is not accessible', async () => {
// Arrange
inputs['node-version-file'] = 'non-existing-file';
const versionFilePath = path.join(
__dirname,
'data',
inputs['node-version-file']
);
// Act
await main.run();
// Assert
expect(existsSpy).toHaveBeenCalled();
expect(existsSpy).toHaveReturnedWith(false);
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
expect(getNodeVersionFromFileSpy).toHaveBeenCalled();
expect(cnSpy).toHaveBeenCalledWith(
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
);

View File

@ -83329,49 +83329,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
function getNodeVersionFromFile(versionFilePath) {
var _a, _b, _c, _d, _e;
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
const contents = fs_1.default.readFileSync(versionFilePath, 'utf8');
// Try parsing the file as an NPM `package.json` file.
try {
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
// if contents are an object, we parsed JSON
// Presume package.json file.
if (typeof manifest === 'object' && !!manifest) {
// Support Volta.
// See https://docs.volta.sh/guide/understanding#managing-your-project
if ((_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node) {
return manifest.volta.node;
}
if ((_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node) {
return manifest.engines.node;
}
// Support Volta workspaces.
// See https://docs.volta.sh/advanced/workspaces
if ((_c = manifest.volta) === null || _c === void 0 ? void 0 : _c.extends) {
const extendedFilePath = path_1.default.resolve(path_1.default.dirname(versionFilePath), manifest.volta.extends);
core.info('Resolving node version from ' + extendedFilePath);
return getNodeVersionFromFile(extendedFilePath);
}
// If contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// If node-version file is _not_ JSON, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
return null;
}
}
catch (_d) {
catch (_f) {
core.info('Node version file is not JSON file');
}
if (!nodeVersion) {
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
}
// In the case of an unknown format,
// return as is and evaluate the version separately.
if (!nodeVersion)
nodeVersion = contents.trim();
return nodeVersion;
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
return (_e = (_d = found === null || found === void 0 ? void 0 : found.groups) === null || _d === void 0 ? void 0 : _d.version) !== null && _e !== void 0 ? _e : contents.trim();
}
exports.parseNodeVersionFile = parseNodeVersionFile;
exports.getNodeVersionFromFile = getNodeVersionFromFile;
function printEnvDetailsAndSetOutput() {
return __awaiter(this, void 0, void 0, function* () {
core.startGroup('Environment details');

67
dist/setup/index.js vendored
View File

@ -93650,7 +93650,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.run = void 0;
const core = __importStar(__nccwpck_require__(2186));
const fs_1 = __importDefault(__nccwpck_require__(7147));
const os_1 = __importDefault(__nccwpck_require__(2037));
const auth = __importStar(__nccwpck_require__(7573));
const path = __importStar(__nccwpck_require__(1017));
@ -93725,10 +93724,7 @@ function resolveVersionInput() {
}
if (versionFileInput) {
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
const parsedVersion = (0, util_1.parseNodeVersionFile)(fs_1.default.readFileSync(versionFilePath, 'utf8'));
const parsedVersion = (0, util_1.getNodeVersionFromFile)(versionFilePath);
if (parsedVersion) {
version = parsedVersion;
}
@ -93780,49 +93776,60 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
exports.unique = exports.printEnvDetailsAndSetOutput = exports.getNodeVersionFromFile = void 0;
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
function parseNodeVersionFile(contents) {
var _a, _b, _c;
let nodeVersion;
const fs_1 = __importDefault(__nccwpck_require__(7147));
const path_1 = __importDefault(__nccwpck_require__(1017));
function getNodeVersionFromFile(versionFilePath) {
var _a, _b, _c, _d, _e;
if (!fs_1.default.existsSync(versionFilePath)) {
throw new Error(`The specified node version file at: ${versionFilePath} does not exist`);
}
const contents = fs_1.default.readFileSync(versionFilePath, 'utf8');
// Try parsing the file as an NPM `package.json` file.
try {
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = (_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node;
if (!nodeVersion)
nodeVersion = (_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node;
// if contents are an object, we parsed JSON
// Presume package.json file.
if (typeof manifest === 'object' && !!manifest) {
// Support Volta.
// See https://docs.volta.sh/guide/understanding#managing-your-project
if ((_a = manifest.volta) === null || _a === void 0 ? void 0 : _a.node) {
return manifest.volta.node;
}
if ((_b = manifest.engines) === null || _b === void 0 ? void 0 : _b.node) {
return manifest.engines.node;
}
// Support Volta workspaces.
// See https://docs.volta.sh/advanced/workspaces
if ((_c = manifest.volta) === null || _c === void 0 ? void 0 : _c.extends) {
const extendedFilePath = path_1.default.resolve(path_1.default.dirname(versionFilePath), manifest.volta.extends);
core.info('Resolving node version from ' + extendedFilePath);
return getNodeVersionFromFile(extendedFilePath);
}
// If contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// If node-version file is _not_ JSON, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
return null;
}
}
catch (_d) {
catch (_f) {
core.info('Node version file is not JSON file');
}
if (!nodeVersion) {
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = (_c = found === null || found === void 0 ? void 0 : found.groups) === null || _c === void 0 ? void 0 : _c.version;
}
// In the case of an unknown format,
// return as is and evaluate the version separately.
if (!nodeVersion)
nodeVersion = contents.trim();
return nodeVersion;
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
return (_e = (_d = found === null || found === void 0 ? void 0 : found.groups) === null || _d === void 0 ? void 0 : _d.version) !== null && _e !== void 0 ? _e : contents.trim();
}
exports.parseNodeVersionFile = parseNodeVersionFile;
exports.getNodeVersionFromFile = getNodeVersionFromFile;
function printEnvDetailsAndSetOutput() {
return __awaiter(this, void 0, void 0, function* () {
core.startGroup('Environment details');

View File

@ -84,6 +84,8 @@ When using the `package.json` input, the action will look for `volta.node` first
}
```
Otherwise, when [`volta.extends`](https://docs.volta.sh/advanced/workspaces) is defined, then it will resolve the corresponding file and look for `volta.node` or `engines.node` recursively.
## Architecture
You can use any of the [supported operating systems](https://docs.github.com/en/actions/using-github-hosted-runners/about-github-hosted-runners), and the compatible `architecture` can be selected using `architecture`. Values are `x86`, `x64`, `arm64`, `armv6l`, `armv7l`, `ppc64le`, `s390x` (not all of the architectures are available on all platforms).

View File

@ -1,6 +1,5 @@
import * as core from '@actions/core';
import fs from 'fs';
import os from 'os';
import * as auth from './authutil';
@ -8,7 +7,7 @@ import * as path from 'path';
import {restoreCache} from './cache-restore';
import {isCacheFeatureAvailable} from './cache-utils';
import {getNodejsDistribution} from './distributions/installer-factory';
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
import {State} from './constants';
export async function run() {
@ -99,15 +98,7 @@ function resolveVersionInput(): string {
versionFileInput
);
if (!fs.existsSync(versionFilePath)) {
throw new Error(
`The specified node version file at: ${versionFilePath} does not exist`
);
}
const parsedVersion = parseNodeVersionFile(
fs.readFileSync(versionFilePath, 'utf8')
);
const parsedVersion = getNodeVersionFromFile(versionFilePath);
if (parsedVersion) {
version = parsedVersion;

View File

@ -1,45 +1,62 @@
import * as core from '@actions/core';
import * as exec from '@actions/exec';
export function parseNodeVersionFile(contents: string): string | null {
let nodeVersion: string | undefined;
import fs from 'fs';
import path from 'path';
export function getNodeVersionFromFile(versionFilePath: string): string | null {
if (!fs.existsSync(versionFilePath)) {
throw new Error(
`The specified node version file at: ${versionFilePath} does not exist`
);
}
const contents = fs.readFileSync(versionFilePath, 'utf8');
// Try parsing the file as an NPM `package.json` file.
try {
const manifest = JSON.parse(contents);
// JSON can parse numbers, but that's handled later
if (typeof manifest === 'object') {
nodeVersion = manifest.volta?.node;
if (!nodeVersion) nodeVersion = manifest.engines?.node;
// Presume package.json file.
if (typeof manifest === 'object' && !!manifest) {
// Support Volta.
// See https://docs.volta.sh/guide/understanding#managing-your-project
if (manifest.volta?.node) {
return manifest.volta.node;
}
// if contents are an object, we parsed JSON
if (manifest.engines?.node) {
return manifest.engines.node;
}
// Support Volta workspaces.
// See https://docs.volta.sh/advanced/workspaces
if (manifest.volta?.extends) {
const extendedFilePath = path.resolve(
path.dirname(versionFilePath),
manifest.volta.extends
);
core.info('Resolving node version from ' + extendedFilePath);
return getNodeVersionFromFile(extendedFilePath);
}
// If contents are an object, we parsed JSON
// this can happen if node-version-file is a package.json
// yet contains no volta.node or engines.node
//
// if node-version file is _not_ json, control flow
// If node-version file is _not_ JSON, control flow
// will not have reached these lines.
//
// And because we've reached here, we know the contents
// *are* JSON, so no further string parsing makes sense.
if (!nodeVersion) {
return null;
}
return null;
}
} catch {
core.info('Node version file is not JSON file');
}
if (!nodeVersion) {
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
nodeVersion = found?.groups?.version;
}
// In the case of an unknown format,
// return as is and evaluate the version separately.
if (!nodeVersion) nodeVersion = contents.trim();
return nodeVersion as string;
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
return found?.groups?.version ?? contents.trim();
}
export async function printEnvDetailsAndSetOutput() {