Revert to NodeJS v12 and Apply ESLint into the project

This commit is contained in:
Thach Nguyen 2022-07-30 21:50:45 +07:00
parent 7a818935c0
commit e069019619
17 changed files with 3489 additions and 3391 deletions

46
.eslintrc.json Normal file
View File

@ -0,0 +1,46 @@
{
"env": {
"es6": true,
"node": true
},
"plugins": ["@typescript-eslint"],
"extends": [
"eslint:recommended", // all
"plugin:@typescript-eslint/all",
"prettier"
],
"overrides": [
{
"files": ["**/*.test.ts"],
"env": {
"jest/globals": true
},
"plugins": ["jest"],
"extends": ["plugin:jest/all"],
"rules": {
"jest/prefer-expect-assertions": "off"
}
}
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 9,
"sourceType": "module",
"project": "./tsconfig.eslint.json"
},
"rules": {
"@typescript-eslint/no-implicit-any-catch": "off",
"@typescript-eslint/no-magic-numbers": [
"error",
{
"ignoreArrayIndexes": true
}
],
"@typescript-eslint/strict-boolean-expressions": [
"error",
{
"allowNullableString": true
}
]
}
}

2
.gitattributes vendored
View File

@ -4,4 +4,4 @@
* text=auto eol=lf * text=auto eol=lf
# Excluded from stats, hidden in diffs # Excluded from stats, hidden in diffs
dist/*.js -diff -merge linguist-generated dist/** -diff -merge linguist-generated

View File

@ -18,8 +18,8 @@ jobs:
Clone this repository and build the project with command Clone this repository and build the project with command
```batch ```batch
docker run --rm -it -v "%PWD%:/usr/src/app" -w /usr/src/app node:16-alpine /bin/sh -c ^ docker run --rm -it -v "%PWD%:/usr/src/app" -w /usr/src/app node:12-alpine /bin/sh -c ^
"npm i --no-bin-links --no-save && npm run lint && npm test && npm run build" "yarn --no-bin-links && yarn lint && yarn test && yarn build"
``` ```
**Note** that `%PWD%` is the project working directory in `Unix` format, such as: `/c/Users/source/repos/setup-maven` **Note** that `%PWD%` is the project working directory in `Unix` format, such as: `/c/Users/source/repos/setup-maven`

View File

@ -1,10 +1,11 @@
import * as installer from '../src/installer'; import * as installer from '../src/installer';
describe('getAvailableVersions', () => { describe('getAvailableVersions', () => {
it('load real available versions', async () => { it('loads real available versions', async () => {
const availableVersions = await installer.getAvailableVersions(); const availableVersions = await installer.getAvailableVersions();
expect(availableVersions).toBeTruthy(); expect(availableVersions).toStrictEqual(
expect(availableVersions).toEqual(expect.arrayContaining(['3.2.5', '3.3.3', '3.8.2'])); expect.arrayContaining(['3.0', '3.2.5', '3.3.3', '3.8.2'])
);
}); });
}); });

17
__tests__/main.test.ts Normal file
View File

@ -0,0 +1,17 @@
import * as core from '@actions/core';
import { run } from '../src/main';
describe('failed to run with invalid inputs', () => {
it.each([
['maven-version', { 'maven-version': ' foo-3!' }] // eslint-disable-line no-inline-comments
])('%s', async (name: string, inputs: Readonly<Record<string, string>>) => {
const spyFailed = jest.spyOn(core, 'setFailed');
jest.spyOn(core, 'getInput').mockImplementation((key: string) => inputs[key]);
await run();
expect(spyFailed).toHaveBeenCalledWith(
expect.stringMatching(new RegExp(`[Ii]nvalid .*'${inputs[name]}'`))
);
});
});

16
__tests__/utils.test.ts Normal file
View File

@ -0,0 +1,16 @@
import * as path from 'path';
import { getVersionFromToolcachePath } from '../src/utils';
describe('getVersionFromToolcachePath', () => {
it.each([
['', ''],
['foo', '.'],
[path.join('foo', '1.0', 'x64'), '1.0'],
[`bar${path.sep}foo${path.sep}`, 'bar']
])('%s -> %s', (toolPath: string, expected: string) => {
const actual = getVersionFromToolcachePath(toolPath);
expect(actual).toBe(expected);
});
});

View File

@ -10,5 +10,5 @@ outputs:
version: version:
description: 'Actual version of Apache Maven that has been installed' description: 'Actual version of Apache Maven that has been installed'
runs: runs:
using: 'node16' using: 'node12'
main: 'dist/index.js' main: 'dist/index.js'

338
dist/index.js generated vendored
View File

@ -14,7 +14,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result; return result;
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const os = __importStar(__nccwpck_require__(37)); const os = __importStar(__nccwpck_require__(87));
const utils_1 = __nccwpck_require__(278); const utils_1 = __nccwpck_require__(278);
/** /**
* Commands * Commands
@ -112,8 +112,8 @@ Object.defineProperty(exports, "__esModule", ({ value: true }));
const command_1 = __nccwpck_require__(351); const command_1 = __nccwpck_require__(351);
const file_command_1 = __nccwpck_require__(717); const file_command_1 = __nccwpck_require__(717);
const utils_1 = __nccwpck_require__(278); const utils_1 = __nccwpck_require__(278);
const os = __importStar(__nccwpck_require__(37)); const os = __importStar(__nccwpck_require__(87));
const path = __importStar(__nccwpck_require__(17)); const path = __importStar(__nccwpck_require__(622));
/** /**
* The code to exit an action * The code to exit an action
*/ */
@ -348,8 +348,8 @@ var __importStar = (this && this.__importStar) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
// We use any as a valid input type // We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */ /* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__nccwpck_require__(147)); const fs = __importStar(__nccwpck_require__(747));
const os = __importStar(__nccwpck_require__(37)); const os = __importStar(__nccwpck_require__(87));
const utils_1 = __nccwpck_require__(278); const utils_1 = __nccwpck_require__(278);
function issueCommand(command, message) { function issueCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`]; const filePath = process.env[`GITHUB_${command}`];
@ -399,6 +399,25 @@ exports.toCommandValue = toCommandValue;
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
@ -408,14 +427,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getExecOutput = exports.exec = void 0;
const string_decoder_1 = __nccwpck_require__(304);
const tr = __importStar(__nccwpck_require__(159)); const tr = __importStar(__nccwpck_require__(159));
/** /**
* Exec a command. * Exec a command.
@ -441,6 +455,51 @@ function exec(commandLine, args, options) {
}); });
} }
exports.exec = exec; exports.exec = exec;
/**
* Exec a command and get the output.
* Output will be streamed to the live console.
* Returns promise with the exit code and collected stdout and stderr
*
* @param commandLine command to execute (can include additional args). Must be correctly escaped.
* @param args optional arguments for tool. Escaping is handled by the lib.
* @param options optional exec options. See ExecOptions
* @returns Promise<ExecOutput> exit code, stdout, and stderr
*/
function getExecOutput(commandLine, args, options) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
let stdout = '';
let stderr = '';
//Using string decoder covers the case where a mult-byte character is split
const stdoutDecoder = new string_decoder_1.StringDecoder('utf8');
const stderrDecoder = new string_decoder_1.StringDecoder('utf8');
const originalStdoutListener = (_a = options === null || options === void 0 ? void 0 : options.listeners) === null || _a === void 0 ? void 0 : _a.stdout;
const originalStdErrListener = (_b = options === null || options === void 0 ? void 0 : options.listeners) === null || _b === void 0 ? void 0 : _b.stderr;
const stdErrListener = (data) => {
stderr += stderrDecoder.write(data);
if (originalStdErrListener) {
originalStdErrListener(data);
}
};
const stdOutListener = (data) => {
stdout += stdoutDecoder.write(data);
if (originalStdoutListener) {
originalStdoutListener(data);
}
};
const listeners = Object.assign(Object.assign({}, options === null || options === void 0 ? void 0 : options.listeners), { stdout: stdOutListener, stderr: stdErrListener });
const exitCode = yield exec(commandLine, args, Object.assign(Object.assign({}, options), { listeners }));
//flush any remaining characters
stdout += stdoutDecoder.end();
stderr += stderrDecoder.end();
return {
exitCode,
stdout,
stderr
};
});
}
exports.getExecOutput = getExecOutput;
//# sourceMappingURL=exec.js.map //# sourceMappingURL=exec.js.map
/***/ }), /***/ }),
@ -450,6 +509,25 @@ exports.exec = exec;
"use strict"; "use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (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.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) { return new (P || (P = Promise))(function (resolve, reject) {
@ -459,20 +537,15 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
step((generator = generator.apply(thisArg, _arguments || [])).next()); step((generator = generator.apply(thisArg, _arguments || [])).next());
}); });
}; };
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const os = __importStar(__nccwpck_require__(37)); exports.argStringToArray = exports.ToolRunner = void 0;
const events = __importStar(__nccwpck_require__(361)); const os = __importStar(__nccwpck_require__(87));
const child = __importStar(__nccwpck_require__(81)); const events = __importStar(__nccwpck_require__(614));
const path = __importStar(__nccwpck_require__(17)); const child = __importStar(__nccwpck_require__(129));
const path = __importStar(__nccwpck_require__(622));
const io = __importStar(__nccwpck_require__(436)); const io = __importStar(__nccwpck_require__(436));
const ioUtil = __importStar(__nccwpck_require__(962)); const ioUtil = __importStar(__nccwpck_require__(962));
const timers_1 = __nccwpck_require__(213);
/* eslint-disable @typescript-eslint/unbound-method */ /* eslint-disable @typescript-eslint/unbound-method */
const IS_WINDOWS = process.platform === 'win32'; const IS_WINDOWS = process.platform === 'win32';
/* /*
@ -542,11 +615,12 @@ class ToolRunner extends events.EventEmitter {
s = s.substring(n + os.EOL.length); s = s.substring(n + os.EOL.length);
n = s.indexOf(os.EOL); n = s.indexOf(os.EOL);
} }
strBuffer = s; return s;
} }
catch (err) { catch (err) {
// streaming lines to console is best effort. Don't fail a build. // streaming lines to console is best effort. Don't fail a build.
this._debug(`error processing line. Failed with error ${err}`); this._debug(`error processing line. Failed with error ${err}`);
return '';
} }
} }
_getSpawnFileName() { _getSpawnFileName() {
@ -828,7 +902,7 @@ class ToolRunner extends events.EventEmitter {
// if the tool is only a file name, then resolve it from the PATH // if the tool is only a file name, then resolve it from the PATH
// otherwise verify it exists (add extension on Windows if necessary) // otherwise verify it exists (add extension on Windows if necessary)
this.toolPath = yield io.which(this.toolPath, true); this.toolPath = yield io.which(this.toolPath, true);
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => __awaiter(this, void 0, void 0, function* () {
this._debug(`exec tool: ${this.toolPath}`); this._debug(`exec tool: ${this.toolPath}`);
this._debug('arguments:'); this._debug('arguments:');
for (const arg of this.args) { for (const arg of this.args) {
@ -842,9 +916,12 @@ class ToolRunner extends events.EventEmitter {
state.on('debug', (message) => { state.on('debug', (message) => {
this._debug(message); this._debug(message);
}); });
if (this.options.cwd && !(yield ioUtil.exists(this.options.cwd))) {
return reject(new Error(`The cwd: ${this.options.cwd} does not exist!`));
}
const fileName = this._getSpawnFileName(); const fileName = this._getSpawnFileName();
const cp = child.spawn(fileName, this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(this.options, fileName)); const cp = child.spawn(fileName, this._getSpawnArgs(optionsNonNull), this._getSpawnOptions(this.options, fileName));
const stdbuffer = ''; let stdbuffer = '';
if (cp.stdout) { if (cp.stdout) {
cp.stdout.on('data', (data) => { cp.stdout.on('data', (data) => {
if (this.options.listeners && this.options.listeners.stdout) { if (this.options.listeners && this.options.listeners.stdout) {
@ -853,14 +930,14 @@ class ToolRunner extends events.EventEmitter {
if (!optionsNonNull.silent && optionsNonNull.outStream) { if (!optionsNonNull.silent && optionsNonNull.outStream) {
optionsNonNull.outStream.write(data); optionsNonNull.outStream.write(data);
} }
this._processLineBuffer(data, stdbuffer, (line) => { stdbuffer = this._processLineBuffer(data, stdbuffer, (line) => {
if (this.options.listeners && this.options.listeners.stdline) { if (this.options.listeners && this.options.listeners.stdline) {
this.options.listeners.stdline(line); this.options.listeners.stdline(line);
} }
}); });
}); });
} }
const errbuffer = ''; let errbuffer = '';
if (cp.stderr) { if (cp.stderr) {
cp.stderr.on('data', (data) => { cp.stderr.on('data', (data) => {
state.processStderr = true; state.processStderr = true;
@ -875,7 +952,7 @@ class ToolRunner extends events.EventEmitter {
: optionsNonNull.outStream; : optionsNonNull.outStream;
s.write(data); s.write(data);
} }
this._processLineBuffer(data, errbuffer, (line) => { errbuffer = this._processLineBuffer(data, errbuffer, (line) => {
if (this.options.listeners && this.options.listeners.errline) { if (this.options.listeners && this.options.listeners.errline) {
this.options.listeners.errline(line); this.options.listeners.errline(line);
} }
@ -922,7 +999,7 @@ class ToolRunner extends events.EventEmitter {
} }
cp.stdin.end(this.options.input); cp.stdin.end(this.options.input);
} }
}); }));
}); });
} }
} }
@ -1008,7 +1085,7 @@ class ExecState extends events.EventEmitter {
this._setResult(); this._setResult();
} }
else if (this.processExited) { else if (this.processExited) {
this.timeout = setTimeout(ExecState.HandleTimeout, this.delay, this); this.timeout = timers_1.setTimeout(ExecState.HandleTimeout, this.delay, this);
} }
} }
_debug(message) { _debug(message) {
@ -1058,8 +1135,8 @@ class ExecState extends events.EventEmitter {
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const http = __nccwpck_require__(685); const http = __nccwpck_require__(605);
const https = __nccwpck_require__(687); const https = __nccwpck_require__(211);
const pm = __nccwpck_require__(443); const pm = __nccwpck_require__(443);
let tunnel; let tunnel;
var HttpCodes; var HttpCodes;
@ -1678,9 +1755,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}; };
var _a; var _a;
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const assert_1 = __nccwpck_require__(491); const assert_1 = __nccwpck_require__(357);
const fs = __nccwpck_require__(147); const fs = __nccwpck_require__(747);
const path = __nccwpck_require__(17); const path = __nccwpck_require__(622);
_a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink; _a = fs.promises, exports.chmod = _a.chmod, exports.copyFile = _a.copyFile, exports.lstat = _a.lstat, exports.mkdir = _a.mkdir, exports.readdir = _a.readdir, exports.readlink = _a.readlink, exports.rename = _a.rename, exports.rmdir = _a.rmdir, exports.stat = _a.stat, exports.symlink = _a.symlink, exports.unlink = _a.unlink;
exports.IS_WINDOWS = process.platform === 'win32'; exports.IS_WINDOWS = process.platform === 'win32';
function exists(fsPath) { function exists(fsPath) {
@ -1879,9 +1956,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const childProcess = __nccwpck_require__(81); const childProcess = __nccwpck_require__(129);
const path = __nccwpck_require__(17); const path = __nccwpck_require__(622);
const util_1 = __nccwpck_require__(837); const util_1 = __nccwpck_require__(669);
const ioUtil = __nccwpck_require__(962); const ioUtil = __nccwpck_require__(962);
const exec = util_1.promisify(childProcess.exec); const exec = util_1.promisify(childProcess.exec);
/** /**
@ -2187,9 +2264,9 @@ const semver = __importStar(__nccwpck_require__(911));
const core_1 = __nccwpck_require__(186); const core_1 = __nccwpck_require__(186);
// needs to be require for core node modules to be mocked // needs to be require for core node modules to be mocked
/* eslint @typescript-eslint/no-require-imports: 0 */ /* eslint @typescript-eslint/no-require-imports: 0 */
const os = __nccwpck_require__(37); const os = __nccwpck_require__(87);
const cp = __nccwpck_require__(81); const cp = __nccwpck_require__(129);
const fs = __nccwpck_require__(147); const fs = __nccwpck_require__(747);
function _findMatch(versionSpec, stable, candidates, archFilter) { function _findMatch(versionSpec, stable, candidates, archFilter) {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const platFilter = os.platform(); const platFilter = os.platform();
@ -2378,17 +2455,17 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const core = __importStar(__nccwpck_require__(186)); const core = __importStar(__nccwpck_require__(186));
const io = __importStar(__nccwpck_require__(436)); const io = __importStar(__nccwpck_require__(436));
const fs = __importStar(__nccwpck_require__(147)); const fs = __importStar(__nccwpck_require__(747));
const mm = __importStar(__nccwpck_require__(473)); const mm = __importStar(__nccwpck_require__(473));
const os = __importStar(__nccwpck_require__(37)); const os = __importStar(__nccwpck_require__(87));
const path = __importStar(__nccwpck_require__(17)); const path = __importStar(__nccwpck_require__(622));
const httpm = __importStar(__nccwpck_require__(925)); const httpm = __importStar(__nccwpck_require__(925));
const semver = __importStar(__nccwpck_require__(911)); const semver = __importStar(__nccwpck_require__(911));
const stream = __importStar(__nccwpck_require__(781)); const stream = __importStar(__nccwpck_require__(413));
const util = __importStar(__nccwpck_require__(837)); const util = __importStar(__nccwpck_require__(669));
const v4_1 = __importDefault(__nccwpck_require__(824)); const v4_1 = __importDefault(__nccwpck_require__(824));
const exec_1 = __nccwpck_require__(514); const exec_1 = __nccwpck_require__(514);
const assert_1 = __nccwpck_require__(491); const assert_1 = __nccwpck_require__(357);
const retry_helper_1 = __nccwpck_require__(279); const retry_helper_1 = __nccwpck_require__(279);
class HTTPError extends Error { class HTTPError extends Error {
constructor(httpStatusCode) { constructor(httpStatusCode) {
@ -4581,13 +4658,13 @@ module.exports = __nccwpck_require__(219);
"use strict"; "use strict";
var net = __nccwpck_require__(808); var net = __nccwpck_require__(631);
var tls = __nccwpck_require__(404); var tls = __nccwpck_require__(16);
var http = __nccwpck_require__(685); var http = __nccwpck_require__(605);
var https = __nccwpck_require__(687); var https = __nccwpck_require__(211);
var events = __nccwpck_require__(361); var events = __nccwpck_require__(614);
var assert = __nccwpck_require__(491); var assert = __nccwpck_require__(357);
var util = __nccwpck_require__(837); var util = __nccwpck_require__(669);
exports.httpOverHttp = httpOverHttp; exports.httpOverHttp = httpOverHttp;
@ -4886,7 +4963,7 @@ module.exports = bytesToUuid;
// Unique ID creation requires a high quality random # generator. In node.js // Unique ID creation requires a high quality random # generator. In node.js
// this is pretty straight-forward - we use the crypto API. // this is pretty straight-forward - we use the crypto API.
var crypto = __nccwpck_require__(113); var crypto = __nccwpck_require__(417);
module.exports = function nodeRNG() { module.exports = function nodeRNG() {
return crypto.randomBytes(16); return crypto.randomBytes(16);
@ -4951,7 +5028,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod); __setModuleDefault(result, mod);
return result; return result;
}; };
@ -4965,45 +5042,27 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.findVersionForDownload = exports.downloadMaven = exports.getAvailableVersions = exports.setupMaven = void 0; exports.setupMaven = exports.findVersionForDownload = exports.downloadMaven = exports.getAvailableVersions = void 0;
const path = __importStar(__nccwpck_require__(17)); const path = __importStar(__nccwpck_require__(622));
const core = __importStar(__nccwpck_require__(186)); const core = __importStar(__nccwpck_require__(186));
const httpm = __importStar(__nccwpck_require__(925));
const tc = __importStar(__nccwpck_require__(784)); const tc = __importStar(__nccwpck_require__(784));
const http_client_1 = __nccwpck_require__(925);
const semver = __importStar(__nccwpck_require__(911)); const semver = __importStar(__nccwpck_require__(911));
const utils_1 = __nccwpck_require__(314); const utils_1 = __nccwpck_require__(314);
function setupMaven(versionSpec, installedVersion) {
return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find('maven', versionSpec);
let resolvedVersion = utils_1.getVersionFromToolcachePath(toolPath);
if (installedVersion) {
if (!toolPath || semver.gte(installedVersion, resolvedVersion)) {
core.info(`Use system Maven version ${installedVersion} instead of the cached one: ${resolvedVersion}`);
return installedVersion;
}
}
else if (!toolPath) {
resolvedVersion = yield findVersionForDownload(versionSpec);
toolPath = yield downloadMaven(resolvedVersion);
}
core.addPath(path.join(toolPath, 'bin'));
return resolvedVersion;
});
}
exports.setupMaven = setupMaven;
const DOWNLOAD_BASE_URL = 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven'; const DOWNLOAD_BASE_URL = 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven';
function getAvailableVersions() { function getAvailableVersions() {
var _a;
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
const resourceUrl = `${DOWNLOAD_BASE_URL}/maven-metadata.xml`; const resourceUrl = `${DOWNLOAD_BASE_URL}/maven-metadata.xml`;
const http = new http_client_1.HttpClient('setup-maven', undefined, { allowRetries: true }); const http = new httpm.HttpClient('setup-maven', undefined, { allowRetries: true });
core.info(`Downloading Maven versions manifest from ${resourceUrl} ...`); core.info(`Downloading Maven versions manifest from ${resourceUrl} ...`);
const response = yield http.get(resourceUrl); const response = yield http.get(resourceUrl);
const body = yield response.readBody(); const body = yield response.readBody();
if (response.message.statusCode !== http_client_1.HttpCodes.OK || !body) { if (response.message.statusCode !== httpm.HttpCodes.OK || !body) {
throw new Error(`Unable to get available versions from ${resourceUrl}`); throw new Error(`Unable to get available versions from ${resourceUrl}`);
} }
const availableVersions = body.match(/(?<=<version>)[^<>]+(?=<\/version>)/g) || []; const availableVersions = (_a = body.match(/(?<=<version>)[^<>]+(?=<\/version>)/g)) !== null && _a !== void 0 ? _a : [];
core.debug(`Available Maven versions: [${availableVersions}]`); core.debug(`Available Maven versions: [${availableVersions.toString()}]`);
return availableVersions; return availableVersions;
}); });
} }
@ -5035,6 +5094,25 @@ function findVersionForDownload(versionSpec) {
}); });
} }
exports.findVersionForDownload = findVersionForDownload; exports.findVersionForDownload = findVersionForDownload;
function setupMaven(versionSpec, installedVersion) {
return __awaiter(this, void 0, void 0, function* () {
let toolPath = tc.find('maven', versionSpec);
let resolvedVersion = utils_1.getVersionFromToolcachePath(toolPath);
if (installedVersion) {
if (!toolPath || semver.gte(installedVersion, resolvedVersion)) {
core.info(`Use system Maven version ${installedVersion} instead of the cached one: ${resolvedVersion}`);
return installedVersion;
}
}
else if (!toolPath) {
resolvedVersion = yield findVersionForDownload(versionSpec);
toolPath = yield downloadMaven(resolvedVersion);
}
core.addPath(path.join(toolPath, 'bin'));
return resolvedVersion;
});
}
exports.setupMaven = setupMaven;
/***/ }), /***/ }),
@ -5059,7 +5137,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod); __setModuleDefault(result, mod);
return result; return result;
}; };
@ -5078,14 +5156,17 @@ const core = __importStar(__nccwpck_require__(186));
const semver = __importStar(__nccwpck_require__(911)); const semver = __importStar(__nccwpck_require__(911));
const utils_1 = __nccwpck_require__(314); const utils_1 = __nccwpck_require__(314);
const installer_1 = __nccwpck_require__(574); const installer_1 = __nccwpck_require__(574);
function resolveVersionInput() {
const versionSpec = core.getInput('maven-version') || '3';
if (!semver.validRange(versionSpec)) {
throw new Error(`Invalid SemVer notation '${versionSpec}' for a Maven version`);
}
return versionSpec;
}
function run() { function run() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const versionSpec = core.getInput('maven-version') || '3'; const versionSpec = resolveVersionInput();
if (!semver.validRange(versionSpec)) {
core.setFailed(`Invalid SemVer notation '${versionSpec}' for a Maven version`);
return;
}
let installedVersion = yield utils_1.getActiveMavenVersion(); let installedVersion = yield utils_1.getActiveMavenVersion();
if (installedVersion && !semver.satisfies(installedVersion, versionSpec)) { if (installedVersion && !semver.satisfies(installedVersion, versionSpec)) {
installedVersion = undefined; installedVersion = undefined;
@ -5093,8 +5174,8 @@ function run() {
installedVersion = yield installer_1.setupMaven(versionSpec, installedVersion); installedVersion = yield installer_1.setupMaven(versionSpec, installedVersion);
core.setOutput('version', installedVersion); core.setOutput('version', installedVersion);
} }
catch (error) { catch (err) {
core.setFailed(error.toString()); core.setFailed(err.message);
} }
}); });
} }
@ -5123,7 +5204,7 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
var __importStar = (this && this.__importStar) || function (mod) { var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod; if (mod && mod.__esModule) return mod;
var result = {}; var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod); __setModuleDefault(result, mod);
return result; return result;
}; };
@ -5137,8 +5218,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
}); });
}; };
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.getExecOutput = exports.getActiveMavenVersion = exports.getVersionFromToolcachePath = void 0; exports.getActiveMavenVersion = exports.getVersionFromToolcachePath = void 0;
const path = __importStar(__nccwpck_require__(17)); const path = __importStar(__nccwpck_require__(622));
const core = __importStar(__nccwpck_require__(186)); const core = __importStar(__nccwpck_require__(186));
const exec = __importStar(__nccwpck_require__(514)); const exec = __importStar(__nccwpck_require__(514));
function getVersionFromToolcachePath(toolPath) { function getVersionFromToolcachePath(toolPath) {
@ -5151,42 +5232,24 @@ exports.getVersionFromToolcachePath = getVersionFromToolcachePath;
function getActiveMavenVersion() { function getActiveMavenVersion() {
return __awaiter(this, void 0, void 0, function* () { return __awaiter(this, void 0, void 0, function* () {
try { try {
const { output } = yield getExecOutput('mvn', ['-v']); const { stdout } = yield exec.getExecOutput('mvn', ['-v'], { silent: true });
const found = output.match(/^[^\d]*(\S+)/); const found = /^[^\d]*(\S+)/.exec(stdout);
const installedVersion = !found ? '' : found[1]; const installedVersion = !found ? '' : found[1];
core.debug(`Retrieved activated Maven version: ${installedVersion}`); core.debug(`Retrieved activated Maven version: ${installedVersion}`);
return installedVersion; return installedVersion;
} }
catch (error) { catch (err) {
core.info(`Failed to get activated Maven version. ${error}`); core.info(`Failed to get activated Maven version. ${err.message}`);
} }
return undefined; return undefined;
}); });
} }
exports.getActiveMavenVersion = getActiveMavenVersion; exports.getActiveMavenVersion = getActiveMavenVersion;
/**
* Exec a command and get the standard output.
*
* @throws {Error} If the exit-code is non-zero.
*/
function getExecOutput(command, args) {
return __awaiter(this, void 0, void 0, function* () {
let output = '';
const exitCode = yield exec.exec(command, args, {
silent: true,
listeners: {
stdout: (data) => (output += data.toString())
}
});
return { exitCode, output };
});
}
exports.getExecOutput = getExecOutput;
/***/ }), /***/ }),
/***/ 491: /***/ 357:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5194,7 +5257,7 @@ module.exports = require("assert");
/***/ }), /***/ }),
/***/ 81: /***/ 129:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5202,7 +5265,7 @@ module.exports = require("child_process");
/***/ }), /***/ }),
/***/ 113: /***/ 417:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5210,7 +5273,7 @@ module.exports = require("crypto");
/***/ }), /***/ }),
/***/ 361: /***/ 614:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5218,7 +5281,7 @@ module.exports = require("events");
/***/ }), /***/ }),
/***/ 147: /***/ 747:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5226,7 +5289,7 @@ module.exports = require("fs");
/***/ }), /***/ }),
/***/ 685: /***/ 605:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5234,7 +5297,7 @@ module.exports = require("http");
/***/ }), /***/ }),
/***/ 687: /***/ 211:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5242,7 +5305,7 @@ module.exports = require("https");
/***/ }), /***/ }),
/***/ 808: /***/ 631:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5250,7 +5313,7 @@ module.exports = require("net");
/***/ }), /***/ }),
/***/ 37: /***/ 87:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5258,7 +5321,7 @@ module.exports = require("os");
/***/ }), /***/ }),
/***/ 17: /***/ 622:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5266,7 +5329,7 @@ module.exports = require("path");
/***/ }), /***/ }),
/***/ 781: /***/ 413:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5274,7 +5337,23 @@ module.exports = require("stream");
/***/ }), /***/ }),
/***/ 404: /***/ 304:
/***/ ((module) => {
"use strict";
module.exports = require("string_decoder");
/***/ }),
/***/ 213:
/***/ ((module) => {
"use strict";
module.exports = require("timers");
/***/ }),
/***/ 16:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5282,7 +5361,7 @@ module.exports = require("tls");
/***/ }), /***/ }),
/***/ 837: /***/ 669:
/***/ ((module) => { /***/ ((module) => {
"use strict"; "use strict";
@ -5337,6 +5416,7 @@ var exports = __webpack_exports__;
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
const main_1 = __nccwpck_require__(399); const main_1 = __nccwpck_require__(399);
// noinspection JSIgnoredPromiseFromCall // noinspection JSIgnoredPromiseFromCall
// eslint-disable-next-line @typescript-eslint/no-floating-promises
main_1.run(); main_1.run();
})(); })();

10
jest.config.json Normal file
View File

@ -0,0 +1,10 @@
{
"clearMocks": true,
"moduleFileExtensions": ["ts", "js"],
"testEnvironment": "node",
"testMatch": ["**/*.test.ts"],
"transform": {
"\\.ts$": "ts-jest"
},
"verbose": true
}

3169
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -5,12 +5,14 @@
"description": "setup maven action", "description": "setup maven action",
"main": "dist/index.js", "main": "dist/index.js",
"scripts": { "scripts": {
"build": "npm run ncc -- build -o dist src/setup-maven.ts", "build": "yarn ncc build -o dist src/setup-maven.ts",
"test": "node node_modules/jest/bin/jest.js", "test": "node node_modules/jest/bin/jest.js",
"format": "npm run prettier -- \"{,!(dist)/**/}?*.*\" --write", "format": "yarn prettier \"{,!(dist)/**/}*.{ts,js*,yml,md}\" --write",
"lint": "npm run prettier -- \"{,!(dist)/**/}?*.*\" --check", "format-check": "yarn prettier \"{,!(dist)/**/}*.{ts,js*,yml,md}\" --check",
"lint": "yarn format-check && yarn eslint \"{,!(dist)/**/}*.{ts,js}\"",
"ncc": "node node_modules/@vercel/ncc/dist/ncc/cli.js", "ncc": "node node_modules/@vercel/ncc/dist/ncc/cli.js",
"prettier": "node node_modules/prettier/bin-prettier.js --ignore-path .gitignore" "prettier": "node node_modules/prettier/bin-prettier.js --ignore-path .gitignore",
"eslint": "node node_modules/eslint/bin/eslint.js --ignore-path .gitignore"
}, },
"keywords": [ "keywords": [
"actions", "actions",
@ -21,21 +23,30 @@
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@actions/core": "^1.2.6", "@actions/core": "^1.2.6",
"@actions/exec": "^1.0.4", "@actions/exec": "^1.0.0",
"@actions/http-client": "^1.0.11", "@actions/http-client": "^1.0.8",
"@actions/tool-cache": "^1.6.1", "@actions/tool-cache": "^1.3.1",
"semver": "^6.1.1" "semver": "^6.1.1"
}, },
"devDependencies": { "devDependencies": {
"@types/jest": "^27.0.2", "@types/jest": "^27.0.2",
"@types/node": "^16.11.25", "@types/node": "^12.0.4",
"@types/semver": "^6.0.0", "@types/semver": "^6.0.0",
"@vercel/ncc": "^0.33.4", "@typescript-eslint/eslint-plugin": "^4.20.0",
"@typescript-eslint/parser": "^4.20.0",
"@vercel/ncc": "^0.31.1",
"eslint": "^7.23.0",
"eslint-config-prettier": ">=8.0.0",
"eslint-plugin-jest": "^24.3.0",
"jest": "^27.2.5", "jest": "^27.2.5",
"jest-circus": "^27.2.5", "prettier": "^1.17.1",
"prettier": "^1.19.1",
"ts-jest": "^27.0.5", "ts-jest": "^27.0.5",
"typescript": "^4.2.3" "typescript": "^3.5.1"
},
"resolutions": {
"**/color-convert/color-name": "~1.1.4",
"**/escodegen/optionator": "^0.9.1",
"eslint/@babel/code-frame": "^7.12.13"
}, },
"prettier": { "prettier": {
"printWidth": 100, "printWidth": 100,
@ -43,17 +54,5 @@
"singleQuote": true, "singleQuote": true,
"trailingComma": "none", "trailingComma": "none",
"arrowParens": "avoid" "arrowParens": "avoid"
},
"jest": {
"clearMocks": true,
"testEnvironment": "node",
"testMatch": [
"**/*.test.ts"
],
"testRunner": "jest-circus/runner",
"transform": {
"\\.ts$": "ts-jest"
},
"verbose": true
} }
} }

View File

@ -1,49 +1,27 @@
import * as path from 'path'; import * as path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as httpm from '@actions/http-client';
import * as tc from '@actions/tool-cache'; import * as tc from '@actions/tool-cache';
import { HttpClient, HttpCodes } from '@actions/http-client';
import * as semver from 'semver'; import * as semver from 'semver';
import { getVersionFromToolcachePath } from './utils'; import { getVersionFromToolcachePath } from './utils';
export async function setupMaven(versionSpec: string, installedVersion?: string): Promise<string> {
let toolPath = tc.find('maven', versionSpec);
let resolvedVersion = getVersionFromToolcachePath(toolPath);
if (installedVersion) {
if (!toolPath || semver.gte(installedVersion, resolvedVersion)) {
core.info(
`Use system Maven version ${installedVersion} instead of the cached one: ${resolvedVersion}`
);
return installedVersion;
}
} else if (!toolPath) {
resolvedVersion = await findVersionForDownload(versionSpec);
toolPath = await downloadMaven(resolvedVersion);
}
core.addPath(path.join(toolPath, 'bin'));
return resolvedVersion;
}
const DOWNLOAD_BASE_URL = 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven'; const DOWNLOAD_BASE_URL = 'https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven';
export async function getAvailableVersions(): Promise<string[]> { export async function getAvailableVersions(): Promise<string[]> {
const resourceUrl = `${DOWNLOAD_BASE_URL}/maven-metadata.xml`; const resourceUrl = `${DOWNLOAD_BASE_URL}/maven-metadata.xml`;
const http = new HttpClient('setup-maven', undefined, { allowRetries: true }); const http = new httpm.HttpClient('setup-maven', undefined, { allowRetries: true });
core.info(`Downloading Maven versions manifest from ${resourceUrl} ...`); core.info(`Downloading Maven versions manifest from ${resourceUrl} ...`);
const response = await http.get(resourceUrl); const response = await http.get(resourceUrl);
const body = await response.readBody(); const body = await response.readBody();
if (response.message.statusCode !== HttpCodes.OK || !body) { if (response.message.statusCode !== httpm.HttpCodes.OK || !body) {
throw new Error(`Unable to get available versions from ${resourceUrl}`); throw new Error(`Unable to get available versions from ${resourceUrl}`);
} }
const availableVersions = body.match(/(?<=<version>)[^<>]+(?=<\/version>)/g) || []; const availableVersions = body.match(/(?<=<version>)[^<>]+(?=<\/version>)/g) ?? [];
core.debug(`Available Maven versions: [${availableVersions}]`); core.debug(`Available Maven versions: [${availableVersions.toString()}]`);
return availableVersions; return availableVersions;
} }
@ -75,3 +53,25 @@ export async function findVersionForDownload(versionSpec: string): Promise<strin
core.debug(`Resolved version for download: ${resolvedVersion}`); core.debug(`Resolved version for download: ${resolvedVersion}`);
return resolvedVersion; return resolvedVersion;
} }
export async function setupMaven(versionSpec: string, installedVersion?: string): Promise<string> {
let toolPath = tc.find('maven', versionSpec);
let resolvedVersion = getVersionFromToolcachePath(toolPath);
if (installedVersion) {
if (!toolPath || semver.gte(installedVersion, resolvedVersion)) {
core.info(
`Use system Maven version ${installedVersion} instead of the cached one: ${resolvedVersion}`
);
return installedVersion;
}
} else if (!toolPath) {
resolvedVersion = await findVersionForDownload(versionSpec);
toolPath = await downloadMaven(resolvedVersion);
}
core.addPath(path.join(toolPath, 'bin'));
return resolvedVersion;
}

View File

@ -4,14 +4,19 @@ import * as semver from 'semver';
import { getActiveMavenVersion } from './utils'; import { getActiveMavenVersion } from './utils';
import { setupMaven } from './installer'; import { setupMaven } from './installer';
export async function run() { function resolveVersionInput(): string {
try { const versionSpec = core.getInput('maven-version') || '3';
const versionSpec = core.getInput('maven-version') || '3';
if (!semver.validRange(versionSpec)) { if (!semver.validRange(versionSpec)) {
core.setFailed(`Invalid SemVer notation '${versionSpec}' for a Maven version`); throw new Error(`Invalid SemVer notation '${versionSpec}' for a Maven version`);
return; }
}
return versionSpec;
}
export async function run(): Promise<void> {
try {
const versionSpec = resolveVersionInput();
let installedVersion = await getActiveMavenVersion(); let installedVersion = await getActiveMavenVersion();
if (installedVersion && !semver.satisfies(installedVersion, versionSpec)) { if (installedVersion && !semver.satisfies(installedVersion, versionSpec)) {
@ -20,7 +25,7 @@ export async function run() {
installedVersion = await setupMaven(versionSpec, installedVersion); installedVersion = await setupMaven(versionSpec, installedVersion);
core.setOutput('version', installedVersion); core.setOutput('version', installedVersion);
} catch (error) { } catch (err) {
core.setFailed(error.toString()); core.setFailed((err as Error).message);
} }
} }

View File

@ -1,4 +1,5 @@
import { run } from './main'; import { run } from './main';
// noinspection JSIgnoredPromiseFromCall // noinspection JSIgnoredPromiseFromCall
// eslint-disable-next-line @typescript-eslint/no-floating-promises
run(); run();

View File

@ -2,7 +2,7 @@ import * as path from 'path';
import * as core from '@actions/core'; import * as core from '@actions/core';
import * as exec from '@actions/exec'; import * as exec from '@actions/exec';
export function getVersionFromToolcachePath(toolPath: string) { export function getVersionFromToolcachePath(toolPath: string): string {
return !toolPath ? toolPath : path.basename(path.dirname(toolPath)); return !toolPath ? toolPath : path.basename(path.dirname(toolPath));
} }
@ -11,37 +11,16 @@ export function getVersionFromToolcachePath(toolPath: string) {
*/ */
export async function getActiveMavenVersion(): Promise<string | undefined> { export async function getActiveMavenVersion(): Promise<string | undefined> {
try { try {
const { output } = await getExecOutput('mvn', ['-v']); const { stdout } = await exec.getExecOutput('mvn', ['-v'], { silent: true });
const found = output.match(/^[^\d]*(\S+)/); const found = /^[^\d]*(\S+)/.exec(stdout);
const installedVersion = !found ? '' : found[1]; const installedVersion = !found ? '' : found[1];
core.debug(`Retrieved activated Maven version: ${installedVersion}`); core.debug(`Retrieved activated Maven version: ${installedVersion}`);
return installedVersion; return installedVersion;
} catch (error) { } catch (err) {
core.info(`Failed to get activated Maven version. ${error}`); core.info(`Failed to get activated Maven version. ${(err as Error).message}`);
} }
return undefined; return undefined;
} }
/**
* Exec a command and get the standard output.
*
* @throws {Error} If the exit-code is non-zero.
*/
export async function getExecOutput(
command: string,
args?: string[]
): Promise<{ exitCode: number; output: string }> {
let output = '';
const exitCode = await exec.exec(command, args, {
silent: true,
listeners: {
stdout: (data: Buffer) => (output += data.toString())
}
});
return { exitCode, output };
}

4
tsconfig.eslint.json Normal file
View File

@ -0,0 +1,4 @@
{
"extends": "./tsconfig.json",
"exclude": ["node_modules", "lib"]
}

3109
yarn.lock Normal file

File diff suppressed because it is too large Load Diff