From c6fd00ceb9747fb23ffdf72987450a2664414867 Mon Sep 17 00:00:00 2001 From: Thomas Boop <52323235+thboop@users.noreply.github.com> Date: Thu, 1 Oct 2020 12:03:22 -0400 Subject: [PATCH 1/2] Swap to env files (#200) * Swap to env files * revert to old method for tests * disable executing of commands during tests * bump package.json @actions/core version --- .licenses/npm/@actions/core-1.2.2.dep.yml | 30 ------ .licenses/npm/@actions/core-1.2.6.dep.yml | 20 ++++ __tests__/authutil.test.ts | 3 + __tests__/installer.test.ts | 6 +- dist/index.js | 123 +++++++++++++++++++--- package-lock.json | 6 +- package.json | 2 +- 7 files changed, 143 insertions(+), 47 deletions(-) delete mode 100644 .licenses/npm/@actions/core-1.2.2.dep.yml create mode 100644 .licenses/npm/@actions/core-1.2.6.dep.yml diff --git a/.licenses/npm/@actions/core-1.2.2.dep.yml b/.licenses/npm/@actions/core-1.2.2.dep.yml deleted file mode 100644 index 92b8b02..0000000 --- a/.licenses/npm/@actions/core-1.2.2.dep.yml +++ /dev/null @@ -1,30 +0,0 @@ ---- -name: "@actions/core" -version: 1.2.2 -type: npm -summary: Actions core lib -homepage: https://github.com/actions/toolkit/tree/master/packages/core -license: mit -licenses: -- sources: Auto-generated MIT license text - text: | - MIT License - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. -notices: [] diff --git a/.licenses/npm/@actions/core-1.2.6.dep.yml b/.licenses/npm/@actions/core-1.2.6.dep.yml new file mode 100644 index 0000000..b1152f5 --- /dev/null +++ b/.licenses/npm/@actions/core-1.2.6.dep.yml @@ -0,0 +1,20 @@ +--- +name: "@actions/core" +version: 1.2.6 +type: npm +summary: Actions core lib +homepage: https://github.com/actions/toolkit/tree/main/packages/core +license: mit +licenses: +- sources: LICENSE.md + text: |- + The MIT License (MIT) + + Copyright 2019 GitHub + + Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +notices: [] diff --git a/__tests__/authutil.test.ts b/__tests__/authutil.test.ts index 85dcb31..a57a317 100644 --- a/__tests__/authutil.test.ts +++ b/__tests__/authutil.test.ts @@ -20,6 +20,8 @@ describe('authutil tests', () => { .toString(36) .substring(7) ); + console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions + process.env['GITHUB_ENV'] = ''; // Stub out Environment file functionality so we can verify it writes to standard out (toolkit is backwards compatible) const tempDir = path.join(_runnerDir, randPath, 'temp'); await io.rmRF(tempDir); await io.mkdirP(tempDir); @@ -61,6 +63,7 @@ describe('authutil tests', () => { if (_runnerDir) { await io.rmRF(_runnerDir); } + console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions }, 100000); function readRcFile(rcFile: string) { diff --git a/__tests__/installer.test.ts b/__tests__/installer.test.ts index 6f3a411..dbbc4b4 100644 --- a/__tests__/installer.test.ts +++ b/__tests__/installer.test.ts @@ -42,6 +42,8 @@ describe('setup-node', () => { beforeEach(() => { // @actions/core + console.log('::stop-commands::stoptoken'); // Disable executing of runner commands when running tests in actions + process.env['GITHUB_PATH'] = ''; // Stub out ENV file functionality so we can verify it writes to standard out inputs = {}; inSpy = jest.spyOn(core, 'getInput'); inSpy.mockImplementation(name => inputs[name]); @@ -102,7 +104,9 @@ describe('setup-node', () => { //jest.restoreAllMocks(); }); - afterAll(async () => {}, 100000); + afterAll(async () => { + console.log('::stoptoken::'); // Re-enable executing of runner commands when running tests in actions + }, 100000); //-------------------------------------------------- // Manifest find tests diff --git a/dist/index.js b/dist/index.js index 481183e..e0e73c5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -3028,6 +3028,32 @@ const windowsRelease = release => { module.exports = windowsRelease; +/***/ }), + +/***/ 82: +/***/ (function(__unusedmodule, exports) { + +"use strict"; + +// We use any as a valid input type +/* eslint-disable @typescript-eslint/no-explicit-any */ +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Sanitizes an input into a string so it can be passed into issueCommand safely + * @param input input to sanitize into a string + */ +function toCommandValue(input) { + if (input === null || input === undefined) { + return ''; + } + else if (typeof input === 'string' || input instanceof String) { + return input; + } + return JSON.stringify(input); +} +exports.toCommandValue = toCommandValue; +//# sourceMappingURL=utils.js.map + /***/ }), /***/ 87: @@ -3037,6 +3063,42 @@ module.exports = require("os"); /***/ }), +/***/ 102: +/***/ (function(__unusedmodule, exports, __webpack_require__) { + +"use strict"; + +// For internal use, subject to change. +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 }); +// We use any as a valid input type +/* eslint-disable @typescript-eslint/no-explicit-any */ +const fs = __importStar(__webpack_require__(747)); +const os = __importStar(__webpack_require__(87)); +const utils_1 = __webpack_require__(82); +function issueCommand(command, message) { + const filePath = process.env[`GITHUB_${command}`]; + if (!filePath) { + throw new Error(`Unable to find environment variable for file command ${command}`); + } + if (!fs.existsSync(filePath)) { + throw new Error(`Missing file at path: ${filePath}`); + } + fs.appendFileSync(filePath, `${utils_1.toCommandValue(message)}${os.EOL}`, { + encoding: 'utf8' + }); +} +exports.issueCommand = issueCommand; +//# sourceMappingURL=file-command.js.map + +/***/ }), + /***/ 108: /***/ (function(module, __unusedexports, __webpack_require__) { @@ -8396,6 +8458,7 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const os = __importStar(__webpack_require__(87)); +const utils_1 = __webpack_require__(82); /** * Commands * @@ -8450,13 +8513,13 @@ class Command { } } function escapeData(s) { - return (s || '') + return utils_1.toCommandValue(s) .replace(/%/g, '%25') .replace(/\r/g, '%0D') .replace(/\n/g, '%0A'); } function escapeProperty(s) { - return (s || '') + return utils_1.toCommandValue(s) .replace(/%/g, '%25') .replace(/\r/g, '%0D') .replace(/\n/g, '%0A') @@ -10381,6 +10444,8 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = __webpack_require__(431); +const file_command_1 = __webpack_require__(102); +const utils_1 = __webpack_require__(82); const os = __importStar(__webpack_require__(87)); const path = __importStar(__webpack_require__(622)); /** @@ -10403,11 +10468,21 @@ var ExitCode; /** * Sets env variable for this action and future actions in the job * @param name the name of the variable to set - * @param val the value of the variable + * @param val the value of the variable. Non-string values will be converted to a string via JSON.stringify */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any function exportVariable(name, val) { - process.env[name] = val; - command_1.issueCommand('set-env', { name }, val); + const convertedVal = utils_1.toCommandValue(val); + process.env[name] = convertedVal; + const filePath = process.env['GITHUB_ENV'] || ''; + if (filePath) { + const delimiter = '_GitHubActionsFileCommandDelimeter_'; + const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`; + file_command_1.issueCommand('ENV', commandValue); + } + else { + command_1.issueCommand('set-env', { name }, convertedVal); + } } exports.exportVariable = exportVariable; /** @@ -10423,7 +10498,13 @@ exports.setSecret = setSecret; * @param inputPath */ function addPath(inputPath) { - command_1.issueCommand('add-path', {}, inputPath); + const filePath = process.env['GITHUB_PATH'] || ''; + if (filePath) { + file_command_1.issueCommand('PATH', inputPath); + } + else { + command_1.issueCommand('add-path', {}, inputPath); + } process.env['PATH'] = `${inputPath}${path.delimiter}${process.env['PATH']}`; } exports.addPath = addPath; @@ -10446,12 +10527,22 @@ exports.getInput = getInput; * Sets the value of an output. * * @param name name of the output to set - * @param value value to store + * @param value value to store. Non-string values will be converted to a string via JSON.stringify */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any function setOutput(name, value) { command_1.issueCommand('set-output', { name }, value); } exports.setOutput = setOutput; +/** + * Enables or disables the echoing of commands into stdout for the rest of the step. + * Echoing is disabled by default if ACTIONS_STEP_DEBUG is not set. + * + */ +function setCommandEcho(enabled) { + command_1.issue('echo', enabled ? 'on' : 'off'); +} +exports.setCommandEcho = setCommandEcho; //----------------------------------------------------------------------- // Results //----------------------------------------------------------------------- @@ -10468,6 +10559,13 @@ exports.setFailed = setFailed; //----------------------------------------------------------------------- // Logging Commands //----------------------------------------------------------------------- +/** + * Gets whether Actions Step Debug is on or not + */ +function isDebug() { + return process.env['RUNNER_DEBUG'] === '1'; +} +exports.isDebug = isDebug; /** * Writes debug message to user log * @param message debug message @@ -10478,18 +10576,18 @@ function debug(message) { exports.debug = debug; /** * Adds an error issue - * @param message error issue message + * @param message error issue message. Errors will be converted to string via toString() */ function error(message) { - command_1.issue('error', message); + command_1.issue('error', message instanceof Error ? message.toString() : message); } exports.error = error; /** * Adds an warning issue - * @param message warning issue message + * @param message warning issue message. Errors will be converted to string via toString() */ function warning(message) { - command_1.issue('warning', message); + command_1.issue('warning', message instanceof Error ? message.toString() : message); } exports.warning = warning; /** @@ -10547,8 +10645,9 @@ exports.group = group; * Saves state for current action, the state can only be retrieved by this action's post job execution. * * @param name name of the state to store - * @param value value to store + * @param value value to store. Non-string values will be converted to a string via JSON.stringify */ +// eslint-disable-next-line @typescript-eslint/no-explicit-any function saveState(name, value) { command_1.issueCommand('save-state', { name }, value); } diff --git a/package-lock.json b/package-lock.json index be7fec2..10f7faa 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5,9 +5,9 @@ "requires": true, "dependencies": { "@actions/core": { - "version": "1.2.2", - "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz", - "integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg==" + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", + "integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==" }, "@actions/exec": { "version": "1.0.4", diff --git a/package.json b/package.json index 9a3f1c5..44f8dda 100644 --- a/package.json +++ b/package.json @@ -23,7 +23,7 @@ "author": "GitHub", "license": "MIT", "dependencies": { - "@actions/core": "^1.2.2", + "@actions/core": "^1.2.6", "@actions/exec": "^1.0.3", "@actions/github": "^1.1.0", "@actions/http-client": "^1.0.6", From 70b9252472eee7495c93bb1588261539c3c2b98d Mon Sep 17 00:00:00 2001 From: nulltoken Date: Thu, 19 Nov 2020 23:01:35 +0100 Subject: [PATCH 2/2] [Readme] Using `check-latest` requires `v2-beta` (#207) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0bd60db..b271c0d 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ Check latest version: ```yaml steps: - uses: actions/checkout@v2 -- uses: actions/setup-node@v2 +- uses: actions/setup-node@v2-beta with: node-version: '12' check-latest: true