Compare commits
No commits in common. "main" and "v4.0.1" have entirely different histories.
|
|
@ -162,6 +162,9 @@ 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:
|
||||
|
|
@ -180,22 +183,7 @@ jobs:
|
|||
- name: Setup node from node version file
|
||||
uses: ./
|
||||
with:
|
||||
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'
|
||||
node-version-file: '__tests__/data/package.json'
|
||||
- name: Verify node
|
||||
run: __tests__/verify-node.sh 16
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
{
|
||||
"volta": {
|
||||
"extends": "./package-volta.json"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,8 +0,0 @@
|
|||
{
|
||||
"engines": {
|
||||
"node": "^14.0.0"
|
||||
},
|
||||
"volta": {
|
||||
"node": "16.0.0"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,5 +1,8 @@
|
|||
{
|
||||
"engines": {
|
||||
"node": "^14.0.0"
|
||||
},
|
||||
"volta": {
|
||||
"node": "16.0.0"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,9 +24,11 @@ describe('main tests', () => {
|
|||
let startGroupSpy: jest.SpyInstance;
|
||||
let endGroupSpy: jest.SpyInstance;
|
||||
|
||||
let existsSpy: jest.SpyInstance;
|
||||
|
||||
let getExecOutputSpy: jest.SpyInstance;
|
||||
|
||||
let getNodeVersionFromFileSpy: jest.SpyInstance;
|
||||
let parseNodeVersionSpy: jest.SpyInstance;
|
||||
let cnSpy: jest.SpyInstance;
|
||||
let findSpy: jest.SpyInstance;
|
||||
let isCacheActionAvailable: jest.SpyInstance;
|
||||
|
|
@ -39,7 +41,6 @@ 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');
|
||||
|
|
@ -61,10 +62,12 @@ 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');
|
||||
|
|
@ -82,7 +85,7 @@ describe('main tests', () => {
|
|||
jest.restoreAllMocks();
|
||||
}, 100000);
|
||||
|
||||
describe('getNodeVersionFromFile', () => {
|
||||
describe('parseNodeVersionFile', () => {
|
||||
each`
|
||||
contents | expected
|
||||
${'12'} | ${'12'}
|
||||
|
|
@ -97,27 +100,10 @@ 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}) => {
|
||||
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);
|
||||
expect(util.parseNodeVersionFile(contents)).toBe(expected);
|
||||
});
|
||||
});
|
||||
|
||||
|
|
@ -156,17 +142,10 @@ describe('main tests', () => {
|
|||
|
||||
describe('node-version-file flag', () => {
|
||||
beforeEach(() => {
|
||||
delete inputs['node-version'];
|
||||
inputs['node-version-file'] = '.nvmrc';
|
||||
|
||||
getNodeVersionFromFileSpy = jest.spyOn(util, 'getNodeVersionFromFile');
|
||||
parseNodeVersionSpy = jest.spyOn(util, 'parseNodeVersionFile');
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
getNodeVersionFromFileSpy.mockRestore();
|
||||
});
|
||||
|
||||
it('does not read node-version-file if node-version is provided', async () => {
|
||||
it('not used if node-version is provided', async () => {
|
||||
// Arrange
|
||||
inputs['node-version'] = '12';
|
||||
|
||||
|
|
@ -174,54 +153,107 @@ describe('main tests', () => {
|
|||
await main.run();
|
||||
|
||||
// Assert
|
||||
expect(inputs['node-version']).toBeDefined();
|
||||
expect(inputs['node-version-file']).toBeDefined();
|
||||
expect(getNodeVersionFromFileSpy).not.toHaveBeenCalled();
|
||||
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(warningSpy).toHaveBeenCalledWith(
|
||||
'Both node-version and node-version-file inputs are specified, only node-version will be used'
|
||||
);
|
||||
});
|
||||
|
||||
it('does not read node-version-file if node-version-file is not provided', async () => {
|
||||
// Arrange
|
||||
delete inputs['node-version-file'];
|
||||
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;
|
||||
|
||||
// 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']
|
||||
inSpy.mockImplementation(name => inputs[name]);
|
||||
existsSpy.mockImplementationOnce(
|
||||
input => input === path.join(__dirname, 'data', versionFile)
|
||||
);
|
||||
|
||||
// Act
|
||||
await main.run();
|
||||
|
||||
// Assert
|
||||
expect(getNodeVersionFromFileSpy).toHaveBeenCalled();
|
||||
expect(existsSpy).toHaveBeenCalled();
|
||||
expect(existsSpy).toHaveReturnedWith(false);
|
||||
expect(parseNodeVersionSpy).not.toHaveBeenCalled();
|
||||
expect(cnSpy).toHaveBeenCalledWith(
|
||||
`::error::The specified node version file at: ${versionFilePath} does not exist${osm.EOL}`
|
||||
);
|
||||
|
|
|
|||
|
|
@ -83329,60 +83329,49 @@ 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.getNodeVersionFromFile = void 0;
|
||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
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');
|
||||
function parseNodeVersionFile(contents) {
|
||||
var _a, _b, _c;
|
||||
let nodeVersion;
|
||||
// Try parsing the file as an NPM `package.json` file.
|
||||
try {
|
||||
const manifest = JSON.parse(contents);
|
||||
// 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
|
||||
// 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
|
||||
// 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.
|
||||
return null;
|
||||
if (!nodeVersion) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (_f) {
|
||||
catch (_d) {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
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();
|
||||
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;
|
||||
}
|
||||
exports.getNodeVersionFromFile = getNodeVersionFromFile;
|
||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||
function printEnvDetailsAndSetOutput() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.startGroup('Environment details');
|
||||
|
|
|
|||
|
|
@ -93373,7 +93373,6 @@ const core = __importStar(__nccwpck_require__(2186));
|
|||
const tc = __importStar(__nccwpck_require__(7784));
|
||||
const path_1 = __importDefault(__nccwpck_require__(1017));
|
||||
const base_distribution_1 = __importDefault(__nccwpck_require__(7));
|
||||
const tc_e = __importStar(__nccwpck_require__(3383));
|
||||
class OfficialBuilds extends base_distribution_1.default {
|
||||
constructor(nodeInfo) {
|
||||
super(nodeInfo);
|
||||
|
|
@ -93492,7 +93491,7 @@ class OfficialBuilds extends base_distribution_1.default {
|
|||
}
|
||||
getManifest() {
|
||||
core.debug('Getting manifest from actions/node-versions@main');
|
||||
return tc_e.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
|
||||
return tc.getManifestFromRepo('actions', 'node-versions', this.nodeInfo.auth, 'main');
|
||||
}
|
||||
resolveLtsAliasFromManifest(versionSpec, stable, manifest) {
|
||||
var _a;
|
||||
|
|
@ -93651,6 +93650,7 @@ 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,7 +93725,10 @@ function resolveVersionInput() {
|
|||
}
|
||||
if (versionFileInput) {
|
||||
const versionFilePath = path.join(process.env.GITHUB_WORKSPACE, versionFileInput);
|
||||
const parsedVersion = (0, util_1.getNodeVersionFromFile)(versionFilePath);
|
||||
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'));
|
||||
if (parsedVersion) {
|
||||
version = parsedVersion;
|
||||
}
|
||||
|
|
@ -93738,64 +93741,6 @@ function resolveVersionInput() {
|
|||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3383:
|
||||
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||
return new (P || (P = Promise))(function (resolve, reject) {
|
||||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||
});
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.getManifestFromRepo = void 0;
|
||||
const httpm = __importStar(__nccwpck_require__(6255));
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
function getManifestFromRepo(owner, repo, auth, branch = 'master') {
|
||||
var _a;
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const manifestUrl = `https://git.qtoa.cn/${owner}/${repo}/raw/branch/${branch}/versions-manifest.json`;
|
||||
const http = new httpm.HttpClient('tool-cache');
|
||||
const headers = {};
|
||||
const response = yield http.getJson(manifestUrl, headers);
|
||||
const result = (_a = response.result) !== null && _a !== void 0 ? _a : [];
|
||||
core.info(`versions-manifest.json:\n${result}`);
|
||||
return result;
|
||||
});
|
||||
}
|
||||
exports.getManifestFromRepo = getManifestFromRepo;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2629:
|
||||
|
|
@ -93835,60 +93780,49 @@ 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.getNodeVersionFromFile = void 0;
|
||||
exports.unique = exports.printEnvDetailsAndSetOutput = exports.parseNodeVersionFile = void 0;
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
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');
|
||||
function parseNodeVersionFile(contents) {
|
||||
var _a, _b, _c;
|
||||
let nodeVersion;
|
||||
// Try parsing the file as an NPM `package.json` file.
|
||||
try {
|
||||
const manifest = JSON.parse(contents);
|
||||
// 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
|
||||
// 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
|
||||
// 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.
|
||||
return null;
|
||||
if (!nodeVersion) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (_f) {
|
||||
catch (_d) {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
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();
|
||||
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;
|
||||
}
|
||||
exports.getNodeVersionFromFile = getNodeVersionFromFile;
|
||||
exports.parseNodeVersionFile = parseNodeVersionFile;
|
||||
function printEnvDetailsAndSetOutput() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
core.startGroup('Environment details');
|
||||
|
|
|
|||
|
|
@ -84,8 +84,6 @@ 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).
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ import path from 'path';
|
|||
|
||||
import BaseDistribution from '../base-distribution';
|
||||
import {NodeInputs, INodeVersion, INodeVersionInfo} from '../base-models';
|
||||
import * as tc_e from '../../manifest-util';
|
||||
|
||||
interface INodeRelease extends tc.IToolRelease {
|
||||
lts?: string;
|
||||
|
|
@ -179,7 +178,7 @@ export default class OfficialBuilds extends BaseDistribution {
|
|||
|
||||
private getManifest(): Promise<tc.IToolRelease[]> {
|
||||
core.debug('Getting manifest from actions/node-versions@main');
|
||||
return tc_e.getManifestFromRepo(
|
||||
return tc.getManifestFromRepo(
|
||||
'actions',
|
||||
'node-versions',
|
||||
this.nodeInfo.auth,
|
||||
|
|
|
|||
13
src/main.ts
13
src/main.ts
|
|
@ -1,5 +1,6 @@
|
|||
import * as core from '@actions/core';
|
||||
|
||||
import fs from 'fs';
|
||||
import os from 'os';
|
||||
|
||||
import * as auth from './authutil';
|
||||
|
|
@ -7,7 +8,7 @@ import * as path from 'path';
|
|||
import {restoreCache} from './cache-restore';
|
||||
import {isCacheFeatureAvailable} from './cache-utils';
|
||||
import {getNodejsDistribution} from './distributions/installer-factory';
|
||||
import {getNodeVersionFromFile, printEnvDetailsAndSetOutput} from './util';
|
||||
import {parseNodeVersionFile, printEnvDetailsAndSetOutput} from './util';
|
||||
import {State} from './constants';
|
||||
|
||||
export async function run() {
|
||||
|
|
@ -98,7 +99,15 @@ function resolveVersionInput(): string {
|
|||
versionFileInput
|
||||
);
|
||||
|
||||
const parsedVersion = getNodeVersionFromFile(versionFilePath);
|
||||
if (!fs.existsSync(versionFilePath)) {
|
||||
throw new Error(
|
||||
`The specified node version file at: ${versionFilePath} does not exist`
|
||||
);
|
||||
}
|
||||
|
||||
const parsedVersion = parseNodeVersionFile(
|
||||
fs.readFileSync(versionFilePath, 'utf8')
|
||||
);
|
||||
|
||||
if (parsedVersion) {
|
||||
version = parsedVersion;
|
||||
|
|
|
|||
|
|
@ -1,17 +0,0 @@
|
|||
import * as httpm from '@actions/http-client'
|
||||
import * as tc from '@actions/tool-cache';
|
||||
import * as core from '@actions/core';
|
||||
export async function getManifestFromRepo(
|
||||
owner: string,
|
||||
repo: string,
|
||||
auth?: string,
|
||||
branch = 'master'
|
||||
): Promise<tc.IToolRelease[]> {
|
||||
const manifestUrl = `https://git.qtoa.cn/${owner}/${repo}/raw/branch/${branch}/versions-manifest.json`
|
||||
const http: httpm.HttpClient = new httpm.HttpClient('tool-cache')
|
||||
const headers: any = {}
|
||||
const response = await http.getJson<tc.IToolRelease[]>(manifestUrl, headers)
|
||||
const result = response.result ?? []
|
||||
core.info(`versions-manifest.json:\n${result}`)
|
||||
return result;
|
||||
}
|
||||
59
src/util.ts
59
src/util.ts
|
|
@ -1,62 +1,45 @@
|
|||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
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');
|
||||
export function parseNodeVersionFile(contents: string): string | null {
|
||||
let nodeVersion: string | undefined;
|
||||
|
||||
// Try parsing the file as an NPM `package.json` file.
|
||||
try {
|
||||
const manifest = JSON.parse(contents);
|
||||
|
||||
// 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;
|
||||
}
|
||||
// JSON can parse numbers, but that's handled later
|
||||
if (typeof manifest === 'object') {
|
||||
nodeVersion = manifest.volta?.node;
|
||||
if (!nodeVersion) nodeVersion = manifest.engines?.node;
|
||||
|
||||
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
|
||||
// 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.
|
||||
return null;
|
||||
if (!nodeVersion) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
core.info('Node version file is not JSON file');
|
||||
}
|
||||
|
||||
const found = contents.match(/^(?:node(js)?\s+)?v?(?<version>[^\s]+)$/m);
|
||||
return found?.groups?.version ?? contents.trim();
|
||||
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;
|
||||
}
|
||||
|
||||
export async function printEnvDetailsAndSetOutput() {
|
||||
|
|
|
|||
Loading…
Reference in New Issue