From ddba1b195df0a72d684224e037a854574145e15c Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:16:20 -0400 Subject: [PATCH 01/24] Use non-Webpack-require in evaluated scripts --- dist/index.js | 21 +-------------------- src/async-function.ts | 4 ++-- src/main.ts | 4 +++- 3 files changed, 6 insertions(+), 23 deletions(-) diff --git a/dist/index.js b/dist/index.js index 096668f4..4c95e1c5 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6144,7 +6144,7 @@ async function main() { const github = Object(lib_github.getOctokit)(token, opts); const script = Object(core.getInput)('script', { required: true }); // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. - const result = await callAsyncFunction({ require: __webpack_require__(875), github, context: lib_github.context, core: core, glob: glob, io: io }, script); + const result = await callAsyncFunction({ require: require, github, context: lib_github.context, core: core, glob: glob, io: io }, script); let encoding = Object(core.getInput)('result-encoding'); encoding = encoding ? encoding : 'json'; let output; @@ -6901,25 +6901,6 @@ function expand(str, isTop) { -/***/ }), - -/***/ 875: -/***/ (function(module) { - -function webpackEmptyContext(req) { - if (typeof req === 'number' && __webpack_require__.m[req]) - return __webpack_require__(req); -try { return require(req) } -catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e } -var e = new Error("Cannot find module '" + req + "'"); - e.code = 'MODULE_NOT_FOUND'; - throw e; -} -webpackEmptyContext.keys = function() { return []; }; -webpackEmptyContext.resolve = webpackEmptyContext; -module.exports = webpackEmptyContext; -webpackEmptyContext.id = 875; - /***/ }), /***/ 877: diff --git a/src/async-function.ts b/src/async-function.ts index 64d12abf..17b25483 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' -import {Context} from '@actions/github/lib/context' -import {GitHub} from '@actions/github/lib/utils' +import { Context } from '@actions/github/lib/context' +import { GitHub } from '@actions/github/lib/utils' import * as glob from '@actions/glob' import * as io from '@actions/io' diff --git a/src/main.ts b/src/main.ts index dd47f2c2..726bf7e4 100644 --- a/src/main.ts +++ b/src/main.ts @@ -4,6 +4,8 @@ import * as glob from '@actions/glob' import * as io from '@actions/io' import {callAsyncFunction} from './async-function' +declare const __non_webpack_require__: typeof require + process.on('unhandledRejection', handleError) main().catch(handleError) @@ -29,7 +31,7 @@ async function main(): Promise { // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. const result = await callAsyncFunction( - {require: require, github, context, core, glob, io}, + {require: __non_webpack_require__, github, context, core, glob, io}, script ) From f4e5d39c2ae1bcb0726aed39da38b49d54fd9661 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:32:28 -0400 Subject: [PATCH 02/24] Use a proxy to support relative requires --- src/async-function.ts | 4 ++-- src/main.ts | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/async-function.ts b/src/async-function.ts index 17b25483..64d12abf 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' -import { Context } from '@actions/github/lib/context' -import { GitHub } from '@actions/github/lib/utils' +import {Context} from '@actions/github/lib/context' +import {GitHub} from '@actions/github/lib/utils' import * as glob from '@actions/glob' import * as io from '@actions/io' diff --git a/src/main.ts b/src/main.ts index 726bf7e4..7d169877 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,9 +2,10 @@ import * as core from '@actions/core' import {context, getOctokit} from '@actions/github' import * as glob from '@actions/glob' import * as io from '@actions/io' +import * as path from 'path' import {callAsyncFunction} from './async-function' -declare const __non_webpack_require__: typeof require +declare const __non_webpack_require__: NodeRequire process.on('unhandledRejection', handleError) main().catch(handleError) @@ -31,7 +32,14 @@ async function main(): Promise { // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. const result = await callAsyncFunction( - {require: __non_webpack_require__, github, context, core, glob, io}, + { + require: wrapRequire, + github, + context, + core, + glob, + io + }, script ) @@ -54,6 +62,19 @@ async function main(): Promise { core.setOutput('result', output) } +const wrapRequire = new Proxy(__non_webpack_require__, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = path.join(process.cwd(), moduleID) + } + return target.apply(thisArg, [moduleID]) + }, + + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver) + } +}) + // eslint-disable-next-line @typescript-eslint/no-explicit-any function handleError(err: any): void { console.error(err) From e853490b1371a1cfab8a6073bca0f17caa028eb7 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:35:28 -0400 Subject: [PATCH 03/24] Run build script --- dist/index.js | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 4c95e1c5..0ada9d2d 100644 --- a/dist/index.js +++ b/dist/index.js @@ -6114,6 +6114,9 @@ var glob = __webpack_require__(90); // EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js var io = __webpack_require__(436); +// EXTERNAL MODULE: external "path" +var external_path_ = __webpack_require__(622); + // CONCATENATED MODULE: ./src/async-function.ts const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; function callAsyncFunction(args, source) { @@ -6127,6 +6130,7 @@ function callAsyncFunction(args, source) { + process.on('unhandledRejection', handleError); main().catch(handleError); async function main() { @@ -6144,7 +6148,14 @@ async function main() { const github = Object(lib_github.getOctokit)(token, opts); const script = Object(core.getInput)('script', { required: true }); // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. - const result = await callAsyncFunction({ require: require, github, context: lib_github.context, core: core, glob: glob, io: io }, script); + const result = await callAsyncFunction({ + require: wrapRequire, + github, + context: lib_github.context, + core: core, + glob: glob, + io: io + }, script); let encoding = Object(core.getInput)('result-encoding'); encoding = encoding ? encoding : 'json'; let output; @@ -6160,6 +6171,17 @@ async function main() { } Object(core.setOutput)('result', output); } +const wrapRequire = new Proxy(require, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = Object(external_path_.join)(process.cwd(), moduleID); + } + return target.apply(thisArg, [moduleID]); + }, + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver); + } +}); // eslint-disable-next-line @typescript-eslint/no-explicit-any function handleError(err) { console.error(err); From 75e3a5b35d2084178abc1aacfc939a3e89338b14 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:37:24 -0400 Subject: [PATCH 04/24] Move wrapRequire to its own module --- dist/index.js | 195 ++++++++++++++++++++++---------------------- src/main.ts | 17 +--- src/wrap-require.ts | 16 ++++ 3 files changed, 116 insertions(+), 112 deletions(-) create mode 100644 src/wrap-require.ts diff --git a/dist/index.js b/dist/index.js index 0ada9d2d..090d6f16 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,7 +40,7 @@ module.exports = /******/ // the startup function /******/ function startup() { /******/ // Load entry module and return exports -/******/ return __webpack_require__(720); +/******/ return __webpack_require__(272); /******/ }; /******/ // initialize runtime /******/ runtime(__webpack_require__); @@ -2424,6 +2424,104 @@ exports.request = request; //# sourceMappingURL=index.js.map +/***/ }), + +/***/ 272: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js +var core = __webpack_require__(186); + +// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js +var lib_github = __webpack_require__(438); + +// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js +var glob = __webpack_require__(90); + +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __webpack_require__(436); + +// CONCATENATED MODULE: ./src/async-function.ts +const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; +function callAsyncFunction(args, source) { + const fn = new AsyncFunction(...Object.keys(args), source); + return fn(...Object.values(args)); +} + +// EXTERNAL MODULE: external "path" +var external_path_ = __webpack_require__(622); + +// CONCATENATED MODULE: ./src/wrap-require.ts + +const wrapRequire = new Proxy(require, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = Object(external_path_.join)(process.cwd(), moduleID); + } + return target.apply(thisArg, [moduleID]); + }, + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver); + } +}); + +// CONCATENATED MODULE: ./src/main.ts + + + + + + +process.on('unhandledRejection', handleError); +main().catch(handleError); +async function main() { + const token = Object(core.getInput)('github-token', { required: true }); + const debug = Object(core.getInput)('debug'); + const userAgent = Object(core.getInput)('user-agent'); + const previews = Object(core.getInput)('previews'); + const opts = {}; + if (debug === 'true') + opts.log = console; + if (userAgent != null) + opts.userAgent = userAgent; + if (previews != null) + opts.previews = previews.split(','); + const github = Object(lib_github.getOctokit)(token, opts); + const script = Object(core.getInput)('script', { required: true }); + // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. + const result = await callAsyncFunction({ + require: wrapRequire, + github, + context: lib_github.context, + core: core, + glob: glob, + io: io + }, script); + let encoding = Object(core.getInput)('result-encoding'); + encoding = encoding ? encoding : 'json'; + let output; + switch (encoding) { + case 'json': + output = JSON.stringify(result); + break; + case 'string': + output = String(result); + break; + default: + throw new Error('"result-encoding" must be either "string" or "json"'); + } + Object(core.setOutput)('result', output); +} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function handleError(err) { + console.error(err); + Object(core.setFailed)(`Unhandled error: ${err}`); +} + + /***/ }), /***/ 278: @@ -6094,101 +6192,6 @@ function issueCommand(command, message) { exports.issueCommand = issueCommand; //# sourceMappingURL=file-command.js.map -/***/ }), - -/***/ 720: -/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); - -// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js -var core = __webpack_require__(186); - -// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js -var lib_github = __webpack_require__(438); - -// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js -var glob = __webpack_require__(90); - -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __webpack_require__(436); - -// EXTERNAL MODULE: external "path" -var external_path_ = __webpack_require__(622); - -// CONCATENATED MODULE: ./src/async-function.ts -const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; -function callAsyncFunction(args, source) { - const fn = new AsyncFunction(...Object.keys(args), source); - return fn(...Object.values(args)); -} - -// CONCATENATED MODULE: ./src/main.ts - - - - - - -process.on('unhandledRejection', handleError); -main().catch(handleError); -async function main() { - const token = Object(core.getInput)('github-token', { required: true }); - const debug = Object(core.getInput)('debug'); - const userAgent = Object(core.getInput)('user-agent'); - const previews = Object(core.getInput)('previews'); - const opts = {}; - if (debug === 'true') - opts.log = console; - if (userAgent != null) - opts.userAgent = userAgent; - if (previews != null) - opts.previews = previews.split(','); - const github = Object(lib_github.getOctokit)(token, opts); - const script = Object(core.getInput)('script', { required: true }); - // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. - const result = await callAsyncFunction({ - require: wrapRequire, - github, - context: lib_github.context, - core: core, - glob: glob, - io: io - }, script); - let encoding = Object(core.getInput)('result-encoding'); - encoding = encoding ? encoding : 'json'; - let output; - switch (encoding) { - case 'json': - output = JSON.stringify(result); - break; - case 'string': - output = String(result); - break; - default: - throw new Error('"result-encoding" must be either "string" or "json"'); - } - Object(core.setOutput)('result', output); -} -const wrapRequire = new Proxy(require, { - apply: (target, thisArg, [moduleID]) => { - if (moduleID.startsWith('.')) { - moduleID = Object(external_path_.join)(process.cwd(), moduleID); - } - return target.apply(thisArg, [moduleID]); - }, - get: (target, prop, receiver) => { - Reflect.get(target, prop, receiver); - } -}); -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function handleError(err) { - console.error(err); - Object(core.setFailed)(`Unhandled error: ${err}`); -} - - /***/ }), /***/ 747: diff --git a/src/main.ts b/src/main.ts index 7d169877..bd2f660c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -2,10 +2,8 @@ import * as core from '@actions/core' import {context, getOctokit} from '@actions/github' import * as glob from '@actions/glob' import * as io from '@actions/io' -import * as path from 'path' import {callAsyncFunction} from './async-function' - -declare const __non_webpack_require__: NodeRequire +import {wrapRequire} from './wrap-require' process.on('unhandledRejection', handleError) main().catch(handleError) @@ -62,19 +60,6 @@ async function main(): Promise { core.setOutput('result', output) } -const wrapRequire = new Proxy(__non_webpack_require__, { - apply: (target, thisArg, [moduleID]) => { - if (moduleID.startsWith('.')) { - moduleID = path.join(process.cwd(), moduleID) - } - return target.apply(thisArg, [moduleID]) - }, - - get: (target, prop, receiver) => { - Reflect.get(target, prop, receiver) - } -}) - // eslint-disable-next-line @typescript-eslint/no-explicit-any function handleError(err: any): void { console.error(err) diff --git a/src/wrap-require.ts b/src/wrap-require.ts new file mode 100644 index 00000000..a7ce0844 --- /dev/null +++ b/src/wrap-require.ts @@ -0,0 +1,16 @@ +import * as path from 'path' + +declare const __non_webpack_require__: NodeRequire + +export const wrapRequire = new Proxy(__non_webpack_require__, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = path.join(process.cwd(), moduleID) + } + return target.apply(thisArg, [moduleID]) + }, + + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver) + } +}) From c416f56b51c47a3aa24eb34cd72e72116711d289 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:40:48 -0400 Subject: [PATCH 05/24] Pass nativeRequire, as well --- dist/index.js | 1 + src/async-function.ts | 1 + src/main.ts | 1 + src/wrap-require.ts | 2 -- types/non-webpack-require.ts | 1 + 5 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 types/non-webpack-require.ts diff --git a/dist/index.js b/dist/index.js index 090d6f16..7701f924 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2494,6 +2494,7 @@ async function main() { // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. const result = await callAsyncFunction({ require: wrapRequire, + nativeRequire: require, github, context: lib_github.context, core: core, diff --git a/src/async-function.ts b/src/async-function.ts index 64d12abf..a9c47902 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -13,6 +13,7 @@ type AsyncFunctionArguments = { glob: typeof glob io: typeof io require: NodeRequire + nativeRequire: NodeRequire } export function callAsyncFunction( diff --git a/src/main.ts b/src/main.ts index bd2f660c..2aa55ae8 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,6 +32,7 @@ async function main(): Promise { const result = await callAsyncFunction( { require: wrapRequire, + nativeRequire: __non_webpack_require__, github, context, core, diff --git a/src/wrap-require.ts b/src/wrap-require.ts index a7ce0844..6b29a298 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -1,7 +1,5 @@ import * as path from 'path' -declare const __non_webpack_require__: NodeRequire - export const wrapRequire = new Proxy(__non_webpack_require__, { apply: (target, thisArg, [moduleID]) => { if (moduleID.startsWith('.')) { diff --git a/types/non-webpack-require.ts b/types/non-webpack-require.ts new file mode 100644 index 00000000..71052e7a --- /dev/null +++ b/types/non-webpack-require.ts @@ -0,0 +1 @@ +declare const __non_webpack_require__: NodeRequire From 83c92d65115d90479cc03a35c7906965ec07a80c Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:41:31 -0400 Subject: [PATCH 06/24] Rename nativeRequire to __original_require__ --- src/async-function.ts | 2 +- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/async-function.ts b/src/async-function.ts index a9c47902..7483414e 100644 --- a/src/async-function.ts +++ b/src/async-function.ts @@ -13,7 +13,7 @@ type AsyncFunctionArguments = { glob: typeof glob io: typeof io require: NodeRequire - nativeRequire: NodeRequire + __original_require__: NodeRequire } export function callAsyncFunction( diff --git a/src/main.ts b/src/main.ts index 2aa55ae8..c0668c62 100644 --- a/src/main.ts +++ b/src/main.ts @@ -32,7 +32,7 @@ async function main(): Promise { const result = await callAsyncFunction( { require: wrapRequire, - nativeRequire: __non_webpack_require__, + __original_require__: __non_webpack_require__, github, context, core, From 3ca4cd5a00172f475ebd7f36005ea8c3c468cbec Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:48:53 -0400 Subject: [PATCH 07/24] Update documentation for relative require support --- README.md | 43 +++++++++++++++++++++++++++++-------------- 1 file changed, 29 insertions(+), 14 deletions(-) diff --git a/README.md b/README.md index 4c1eb0a1..211f8b1f 100644 --- a/README.md +++ b/README.md @@ -18,6 +18,18 @@ arguments will be provided: - `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package - `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package - `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package +- `require` Is available, with some caveats: + - The location of the module that runs this action is where the Actions + runner downloads the github-script action to, so the `require` passed to + your script is actually a proxy that intercepts calls to require relative + paths and transforms them into an absolute path in the working directory, + instead. + - If you want to require an npm module in your working directory, you still + need to specify the relative path, including `node_modules`, such as + `./node_modules/lodash`. + - If for some reason you need the non-wrapped `require`, there is an escape + hatch available: `__original_require__` is the original value of `require` + without our wrapping applied. Since the `script` is just a function body, these values will already be defined, so you don't have to (see examples below). @@ -243,12 +255,10 @@ jobs: - uses: actions/github-script@v3 with: script: | - const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`) + const script = require(`./path/to/script.js`) console.log(script({github, context})) ``` -_Note that the script path given to `require()` must be an **absolute path** in this case, hence using [`GITHUB_WORKSPACE`](https://docs.github.com/en/actions/configuring-and-managing-workflows/using-environment-variables#default-environment-variables)._ - And then export a function from your module: ```javascript @@ -282,24 +292,24 @@ jobs: - uses: actions/checkout@v2 - uses: actions/github-script@v3 env: - SHA: "${{env.parentSHA}}" + SHA: '${{env.parentSHA}}' with: script: | - const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`) + const script = require(`./path/to/script.js`) await script({github, context, core}) ``` And then export an async function from your module: ```javascript -module.exports = async ({ github, context, core }) => { - const { SHA } = process.env - const commit = await github.repos.getCommit({ - owner: context.repo.owner, - repo: context.repo.repo, - ref: `${SHA}` - }) - core.exportVariable('author', commit.data.commit.author.email); +module.exports = async ({github, context, core}) => { + const {SHA} = process.env + const commit = await github.repos.getCommit({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `${SHA}` + }) + core.exportVariable('author', commit.data.commit.author.email) } ``` @@ -324,13 +334,18 @@ jobs: - uses: actions/github-script@v3 with: script: | - const execa = require(`${process.env.GITHUB_WORKSPACE}/node_modules/execa`) + const execa = require(`./node_modules/execa`) const { stdout } = await execa('echo', ['hello', 'world']) console.log(stdout) ``` +_(Note that at this time, one still has to specify `node_modules` in the +require path for modules in the working directory of the step that is +running. Hopefully we will have a solution for this in the future, but not +quite, yet.)_ + ### Use env as input You can set env vars to use them in your script: From c1c139b0abfbbdac4ee6ab5d5d83739bc2e56854 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 16:58:37 -0400 Subject: [PATCH 08/24] Add a catch to support requiring installed modules --- dist/index.js | 36 +++++++++++++++++++++++++++++++++--- src/wrap-require.ts | 8 +++++++- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7701f924..dfe53664 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2427,7 +2427,7 @@ exports.request = request; /***/ }), /***/ 272: -/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { +/***/ (function(module, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -2455,13 +2455,20 @@ function callAsyncFunction(args, source) { var external_path_ = __webpack_require__(622); // CONCATENATED MODULE: ./src/wrap-require.ts +/* module decorator */ module = __webpack_require__.hmd(module); const wrapRequire = new Proxy(require, { apply: (target, thisArg, [moduleID]) => { if (moduleID.startsWith('.')) { moduleID = Object(external_path_.join)(process.cwd(), moduleID); + return target.apply(thisArg, [moduleID]); + } + try { + return target.apply(thisArg, [moduleID]); + } + catch (err) { + return target.resolve(moduleID, { paths: [...module.paths, process.cwd()] }); } - return target.apply(thisArg, [moduleID]); }, get: (target, prop, receiver) => { Reflect.get(target, prop, receiver); @@ -2494,7 +2501,7 @@ async function main() { // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. const result = await callAsyncFunction({ require: wrapRequire, - nativeRequire: require, + __original_require__: require, github, context: lib_github.context, core: core, @@ -8803,5 +8810,28 @@ function regExpEscape (s) { /******/ }; /******/ }(); /******/ +/******/ /* webpack/runtime/harmony module decorator */ +/******/ !function() { +/******/ __webpack_require__.hmd = function(module) { +/******/ module = Object.create(module); +/******/ if (!module.children) module.children = []; +/******/ Object.defineProperty(module, 'loaded', { +/******/ enumerable: true, +/******/ get: function () { return module.l; } +/******/ }); +/******/ Object.defineProperty(module, 'id', { +/******/ enumerable: true, +/******/ get: function () { return module.i; } +/******/ }); +/******/ Object.defineProperty(module, 'exports', { +/******/ enumerable: true, +/******/ set: function () { +/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id); +/******/ } +/******/ }); +/******/ return module; +/******/ }; +/******/ }(); +/******/ /******/ } ); \ No newline at end of file diff --git a/src/wrap-require.ts b/src/wrap-require.ts index 6b29a298..b803069e 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -4,8 +4,14 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { apply: (target, thisArg, [moduleID]) => { if (moduleID.startsWith('.')) { moduleID = path.join(process.cwd(), moduleID) + return target.apply(thisArg, [moduleID]) + } + + try { + return target.apply(thisArg, [moduleID]) + } catch (err) { + return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]}) } - return target.apply(thisArg, [moduleID]) }, get: (target, prop, receiver) => { From ade5cea98518854348345e2003402434d703b4ca Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:02:53 -0400 Subject: [PATCH 09/24] Use concat for paths --- dist/index.js | 4 +++- src/wrap-require.ts | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index dfe53664..10de55d8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2467,7 +2467,9 @@ const wrapRequire = new Proxy(require, { return target.apply(thisArg, [moduleID]); } catch (err) { - return target.resolve(moduleID, { paths: [...module.paths, process.cwd()] }); + return target.resolve(moduleID, { + paths: module.paths.concat(process.cwd()) + }); } }, get: (target, prop, receiver) => { diff --git a/src/wrap-require.ts b/src/wrap-require.ts index b803069e..e38d9d92 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -10,7 +10,9 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { try { return target.apply(thisArg, [moduleID]) } catch (err) { - return target.resolve(moduleID, {paths: [...module.paths, process.cwd()]}) + return target.resolve(moduleID, { + paths: module.paths.concat(process.cwd()) + }) } }, From f57c84a8e860990ce763bd7d64b5a9a9e25b09da Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:04:41 -0400 Subject: [PATCH 10/24] Try global.module --- src/wrap-require.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrap-require.ts b/src/wrap-require.ts index e38d9d92..adb5d0ed 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -11,7 +11,7 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { return target.apply(thisArg, [moduleID]) } catch (err) { return target.resolve(moduleID, { - paths: module.paths.concat(process.cwd()) + paths: global.module.paths.concat(process.cwd()) }) } }, From 1f8fc98741b80b5d8436316606e8ecd335165240 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:05:03 -0400 Subject: [PATCH 11/24] Run build --- dist/index.js | 28 ++-------------------------- 1 file changed, 2 insertions(+), 26 deletions(-) diff --git a/dist/index.js b/dist/index.js index 10de55d8..504c67e1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2427,7 +2427,7 @@ exports.request = request; /***/ }), /***/ 272: -/***/ (function(module, __webpack_exports__, __webpack_require__) { +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { "use strict"; __webpack_require__.r(__webpack_exports__); @@ -2455,7 +2455,6 @@ function callAsyncFunction(args, source) { var external_path_ = __webpack_require__(622); // CONCATENATED MODULE: ./src/wrap-require.ts -/* module decorator */ module = __webpack_require__.hmd(module); const wrapRequire = new Proxy(require, { apply: (target, thisArg, [moduleID]) => { @@ -2468,7 +2467,7 @@ const wrapRequire = new Proxy(require, { } catch (err) { return target.resolve(moduleID, { - paths: module.paths.concat(process.cwd()) + paths: global.module.paths.concat(process.cwd()) }); } }, @@ -8812,28 +8811,5 @@ function regExpEscape (s) { /******/ }; /******/ }(); /******/ -/******/ /* webpack/runtime/harmony module decorator */ -/******/ !function() { -/******/ __webpack_require__.hmd = function(module) { -/******/ module = Object.create(module); -/******/ if (!module.children) module.children = []; -/******/ Object.defineProperty(module, 'loaded', { -/******/ enumerable: true, -/******/ get: function () { return module.l; } -/******/ }); -/******/ Object.defineProperty(module, 'id', { -/******/ enumerable: true, -/******/ get: function () { return module.i; } -/******/ }); -/******/ Object.defineProperty(module, 'exports', { -/******/ enumerable: true, -/******/ set: function () { -/******/ throw new Error('ES Modules may not assign module.exports or exports.*, Use ESM export syntax, instead: ' + module.id); -/******/ } -/******/ }); -/******/ return module; -/******/ }; -/******/ }(); -/******/ /******/ } ); \ No newline at end of file From d37f92ff119000bc02eba914427b6c5903f09eea Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:06:36 -0400 Subject: [PATCH 12/24] Test eval --- src/wrap-require.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrap-require.ts b/src/wrap-require.ts index adb5d0ed..22e4b008 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -11,7 +11,7 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { return target.apply(thisArg, [moduleID]) } catch (err) { return target.resolve(moduleID, { - paths: global.module.paths.concat(process.cwd()) + paths: eval('module').paths.concat(process.cwd()) }) } }, From 7e8659dcd45ea7a2ad51debcf965db706e2f5c81 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:06:44 -0400 Subject: [PATCH 13/24] Run build --- dist/index.js | 263 ++++++++++++++++++++++++++------------------------ 1 file changed, 136 insertions(+), 127 deletions(-) diff --git a/dist/index.js b/dist/index.js index 504c67e1..3e3b9052 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,7 +40,7 @@ module.exports = /******/ // the startup function /******/ function startup() { /******/ // Load entry module and return exports -/******/ return __webpack_require__(272); +/******/ return __webpack_require__(720); /******/ }; /******/ // initialize runtime /******/ runtime(__webpack_require__); @@ -2424,113 +2424,6 @@ exports.request = request; //# sourceMappingURL=index.js.map -/***/ }), - -/***/ 272: -/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { - -"use strict"; -__webpack_require__.r(__webpack_exports__); - -// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js -var core = __webpack_require__(186); - -// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js -var lib_github = __webpack_require__(438); - -// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js -var glob = __webpack_require__(90); - -// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js -var io = __webpack_require__(436); - -// CONCATENATED MODULE: ./src/async-function.ts -const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; -function callAsyncFunction(args, source) { - const fn = new AsyncFunction(...Object.keys(args), source); - return fn(...Object.values(args)); -} - -// EXTERNAL MODULE: external "path" -var external_path_ = __webpack_require__(622); - -// CONCATENATED MODULE: ./src/wrap-require.ts - -const wrapRequire = new Proxy(require, { - apply: (target, thisArg, [moduleID]) => { - if (moduleID.startsWith('.')) { - moduleID = Object(external_path_.join)(process.cwd(), moduleID); - return target.apply(thisArg, [moduleID]); - } - try { - return target.apply(thisArg, [moduleID]); - } - catch (err) { - return target.resolve(moduleID, { - paths: global.module.paths.concat(process.cwd()) - }); - } - }, - get: (target, prop, receiver) => { - Reflect.get(target, prop, receiver); - } -}); - -// CONCATENATED MODULE: ./src/main.ts - - - - - - -process.on('unhandledRejection', handleError); -main().catch(handleError); -async function main() { - const token = Object(core.getInput)('github-token', { required: true }); - const debug = Object(core.getInput)('debug'); - const userAgent = Object(core.getInput)('user-agent'); - const previews = Object(core.getInput)('previews'); - const opts = {}; - if (debug === 'true') - opts.log = console; - if (userAgent != null) - opts.userAgent = userAgent; - if (previews != null) - opts.previews = previews.split(','); - const github = Object(lib_github.getOctokit)(token, opts); - const script = Object(core.getInput)('script', { required: true }); - // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. - const result = await callAsyncFunction({ - require: wrapRequire, - __original_require__: require, - github, - context: lib_github.context, - core: core, - glob: glob, - io: io - }, script); - let encoding = Object(core.getInput)('result-encoding'); - encoding = encoding ? encoding : 'json'; - let output; - switch (encoding) { - case 'json': - output = JSON.stringify(result); - break; - case 'string': - output = String(result); - break; - default: - throw new Error('"result-encoding" must be either "string" or "json"'); - } - Object(core.setOutput)('result', output); -} -// eslint-disable-next-line @typescript-eslint/no-explicit-any -function handleError(err) { - console.error(err); - Object(core.setFailed)(`Unhandled error: ${err}`); -} - - /***/ }), /***/ 278: @@ -2990,6 +2883,37 @@ function escapeProperty(s) { module.exports = require("assert"); +/***/ }), + +/***/ 366: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrapRequire", function() { return wrapRequire; }); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(622); +/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__); + +const wrapRequire = new Proxy(require, { + apply: (target, thisArg, [moduleID]) => { + if (moduleID.startsWith('.')) { + moduleID = path__WEBPACK_IMPORTED_MODULE_0__.join(process.cwd(), moduleID); + return target.apply(thisArg, [moduleID]); + } + try { + return target.apply(thisArg, [moduleID]); + } + catch (err) { + return target.resolve(moduleID, { + paths: eval('module').paths.concat(process.cwd()) + }); + } + }, + get: (target, prop, receiver) => { + Reflect.get(target, prop, receiver); + } +}); + + /***/ }), /***/ 413: @@ -6201,6 +6125,91 @@ function issueCommand(command, message) { exports.issueCommand = issueCommand; //# sourceMappingURL=file-command.js.map +/***/ }), + +/***/ 720: +/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) { + +"use strict"; +__webpack_require__.r(__webpack_exports__); + +// EXTERNAL MODULE: ./node_modules/@actions/core/lib/core.js +var core = __webpack_require__(186); + +// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js +var lib_github = __webpack_require__(438); + +// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js +var glob = __webpack_require__(90); + +// EXTERNAL MODULE: ./node_modules/@actions/io/lib/io.js +var io = __webpack_require__(436); + +// CONCATENATED MODULE: ./src/async-function.ts +const AsyncFunction = Object.getPrototypeOf(async () => null).constructor; +function callAsyncFunction(args, source) { + const fn = new AsyncFunction(...Object.keys(args), source); + return fn(...Object.values(args)); +} + +// EXTERNAL MODULE: ./src/wrap-require.ts +var wrap_require = __webpack_require__(366); + +// CONCATENATED MODULE: ./src/main.ts + + + + + + +process.on('unhandledRejection', handleError); +main().catch(handleError); +async function main() { + const token = Object(core.getInput)('github-token', { required: true }); + const debug = Object(core.getInput)('debug'); + const userAgent = Object(core.getInput)('user-agent'); + const previews = Object(core.getInput)('previews'); + const opts = {}; + if (debug === 'true') + opts.log = console; + if (userAgent != null) + opts.userAgent = userAgent; + if (previews != null) + opts.previews = previews.split(','); + const github = Object(lib_github.getOctokit)(token, opts); + const script = Object(core.getInput)('script', { required: true }); + // Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors. + const result = await callAsyncFunction({ + require: wrap_require.wrapRequire, + __original_require__: require, + github, + context: lib_github.context, + core: core, + glob: glob, + io: io + }, script); + let encoding = Object(core.getInput)('result-encoding'); + encoding = encoding ? encoding : 'json'; + let output; + switch (encoding) { + case 'json': + output = JSON.stringify(result); + break; + case 'string': + output = String(result); + break; + default: + throw new Error('"result-encoding" must be either "string" or "json"'); + } + Object(core.setOutput)('result', output); +} +// eslint-disable-next-line @typescript-eslint/no-explicit-any +function handleError(err) { + console.error(err); + Object(core.setFailed)(`Unhandled error: ${err}`); +} + + /***/ }), /***/ 747: @@ -8758,14 +8767,15 @@ function regExpEscape (s) { /******/ function(__webpack_require__) { // webpackRuntimeModules /******/ "use strict"; /******/ -/******/ /* webpack/runtime/make namespace object */ +/******/ /* webpack/runtime/compat get default export */ /******/ !function() { -/******/ // define __esModule on exports -/******/ __webpack_require__.r = function(exports) { -/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { -/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); -/******/ } -/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ // getDefaultExport function for compatibility with non-harmony modules +/******/ __webpack_require__.n = function(module) { +/******/ var getter = module && module.__esModule ? +/******/ function getDefault() { return module['default']; } : +/******/ function getModuleExports() { return module; }; +/******/ __webpack_require__.d(getter, 'a', getter); +/******/ return getter; /******/ }; /******/ }(); /******/ @@ -8780,6 +8790,17 @@ function regExpEscape (s) { /******/ }; /******/ }(); /******/ +/******/ /* webpack/runtime/make namespace object */ +/******/ !function() { +/******/ // define __esModule on exports +/******/ __webpack_require__.r = function(exports) { +/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) { +/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' }); +/******/ } +/******/ Object.defineProperty(exports, '__esModule', { value: true }); +/******/ }; +/******/ }(); +/******/ /******/ /* webpack/runtime/create fake namespace object */ /******/ !function() { /******/ // create a fake namespace object @@ -8799,17 +8820,5 @@ function regExpEscape (s) { /******/ }; /******/ }(); /******/ -/******/ /* webpack/runtime/compat get default export */ -/******/ !function() { -/******/ // getDefaultExport function for compatibility with non-harmony modules -/******/ __webpack_require__.n = function(module) { -/******/ var getter = module && module.__esModule ? -/******/ function getDefault() { return module['default']; } : -/******/ function getModuleExports() { return module; }; -/******/ __webpack_require__.d(getter, 'a', getter); -/******/ return getter; -/******/ }; -/******/ }(); -/******/ /******/ } ); \ No newline at end of file From 7e12bd73952c9992711142f5dec2f787345e8c5a Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:10:11 -0400 Subject: [PATCH 14/24] Call resolve, then require --- dist/index.js | 10 +++++++--- src/wrap-require.ts | 11 ++++++++--- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/dist/index.js b/dist/index.js index 3e3b9052..159c7c5f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2903,9 +2903,13 @@ const wrapRequire = new Proxy(require, { return target.apply(thisArg, [moduleID]); } catch (err) { - return target.resolve(moduleID, { - paths: eval('module').paths.concat(process.cwd()) - }); + const modulePath = target.resolve.apply(thisArg, [ + moduleID, + { + paths: eval('module').paths.concat(process.cwd()) + } + ]); + return target.apply(thisArg, [modulePath]); } }, get: (target, prop, receiver) => { diff --git a/src/wrap-require.ts b/src/wrap-require.ts index 22e4b008..de15f6ed 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -10,9 +10,14 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { try { return target.apply(thisArg, [moduleID]) } catch (err) { - return target.resolve(moduleID, { - paths: eval('module').paths.concat(process.cwd()) - }) + const modulePath = target.resolve.apply(thisArg, [ + moduleID, + { + paths: eval('module').paths.concat(process.cwd()) + } + ]) + + return target.apply(thisArg, [modulePath]) } }, From b0e12e725ba5182c4b0cb8c2bf2ca0f25097754b Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:12:21 -0400 Subject: [PATCH 15/24] Add Webpack comment vis-a-vis eval --- dist/index.js | 2 ++ src/wrap-require.ts | 2 ++ 2 files changed, 4 insertions(+) diff --git a/dist/index.js b/dist/index.js index 159c7c5f..19a31020 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2906,6 +2906,8 @@ const wrapRequire = new Proxy(require, { const modulePath = target.resolve.apply(thisArg, [ moduleID, { + // Webpack does not have an escape hatch for getting the actual + // module, other than `eval`. paths: eval('module').paths.concat(process.cwd()) } ]); diff --git a/src/wrap-require.ts b/src/wrap-require.ts index de15f6ed..22311d99 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -13,6 +13,8 @@ export const wrapRequire = new Proxy(__non_webpack_require__, { const modulePath = target.resolve.apply(thisArg, [ moduleID, { + // Webpack does not have an escape hatch for getting the actual + // module, other than `eval`. paths: eval('module').paths.concat(process.cwd()) } ]) From 01f87b6c0176fe65a0bf754bc1c727612ddf7e15 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:21:31 -0400 Subject: [PATCH 16/24] Remove caveat about node_modules --- README.md | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 211f8b1f..49a96675 100644 --- a/README.md +++ b/README.md @@ -18,18 +18,12 @@ arguments will be provided: - `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package - `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package - `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package -- `require` Is available, with some caveats: - - The location of the module that runs this action is where the Actions - runner downloads the github-script action to, so the `require` passed to - your script is actually a proxy that intercepts calls to require relative - paths and transforms them into an absolute path in the working directory, - instead. - - If you want to require an npm module in your working directory, you still - need to specify the relative path, including `node_modules`, such as - `./node_modules/lodash`. - - If for some reason you need the non-wrapped `require`, there is an escape - hatch available: `__original_require__` is the original value of `require` - without our wrapping applied. +- `require` A proxy wrapper around the normal Node.js `require` to enable + requiring relative paths (relative to the current working directory) and + requiring npm packages installed in the current working directory. If for + some reason you need the non-wrapped `require`, there is an escape hatch + available: `__original_require__` is the original value of `require` without + our wrapping applied. Since the `script` is just a function body, these values will already be defined, so you don't have to (see examples below). @@ -255,7 +249,7 @@ jobs: - uses: actions/github-script@v3 with: script: | - const script = require(`./path/to/script.js`) + const script = require('./path/to/script.js') console.log(script({github, context})) ``` @@ -295,7 +289,7 @@ jobs: SHA: '${{env.parentSHA}}' with: script: | - const script = require(`./path/to/script.js`) + const script = require('./path/to/script.js') await script({github, context, core}) ``` @@ -334,18 +328,13 @@ jobs: - uses: actions/github-script@v3 with: script: | - const execa = require(`./node_modules/execa`) + const execa = require('execa') const { stdout } = await execa('echo', ['hello', 'world']) console.log(stdout) ``` -_(Note that at this time, one still has to specify `node_modules` in the -require path for modules in the working directory of the step that is -running. Hopefully we will have a solution for this in the future, but not -quite, yet.)_ - ### Use env as input You can set env vars to use them in your script: From 3ede58996d5e6c900502e1e4d3b970fdb8b572df Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:37:37 -0400 Subject: [PATCH 17/24] Add new integration tests --- .github/workflows/integration.yml | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 512e134c..25da4f8d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -4,7 +4,7 @@ on: push: {branches: main} jobs: - integration: + test-return: runs-on: ubuntu-latest steps: - id: output-set @@ -17,3 +17,31 @@ jobs: if [[ "${{steps.output-set.outputs.result}}" != "output" ]]; then exit 1 fi + + test-relative-require: + runs-on: ubuntu-latest + steps: + - id: output-set + uses: actions/github-script@main + with: + script: return require('./package.json').name + result-encoding: string + input-value: output + - run: | + if [[ "${{steps.output-set.outputs.result}}" != "github-script" ]]; then + exit 1 + fi + + test-npm-require: + runs-on: ubuntu-latest + steps: + - id: output-set + uses: actions/github-script@main + with: + script: return require('@actions/core/package.json').name + result-encoding: string + input-value: output + - run: | + if [[ "${{steps.output-set.outputs.result}}" != "@actions/core" ]]; then + exit 1 + fi From 19e79140230e3cb67ba4a97e2e841f2612cbaf6c Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:39:54 -0400 Subject: [PATCH 18/24] Add integration test running --- .github/workflows/integration.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 25da4f8d..2fac1546 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -2,13 +2,14 @@ name: Integration on: push: {branches: main} + pull_request: {branches: main} jobs: test-return: runs-on: ubuntu-latest steps: - id: output-set - uses: actions/github-script@main + uses: ./ with: script: return core.getInput('input-value') result-encoding: string @@ -22,7 +23,7 @@ jobs: runs-on: ubuntu-latest steps: - id: output-set - uses: actions/github-script@main + uses: ./ with: script: return require('./package.json').name result-encoding: string @@ -36,7 +37,7 @@ jobs: runs-on: ubuntu-latest steps: - id: output-set - uses: actions/github-script@main + uses: ./ with: script: return require('@actions/core/package.json').name result-encoding: string From 4a93ad9f9e3797db43bcae36c69d3dca8358a1b1 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:41:41 -0400 Subject: [PATCH 19/24] Add actions/checkout --- .github/workflows/integration.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 2fac1546..101b8a18 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -8,6 +8,7 @@ jobs: test-return: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - id: output-set uses: ./ with: @@ -22,6 +23,7 @@ jobs: test-relative-require: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - id: output-set uses: ./ with: @@ -36,6 +38,7 @@ jobs: test-npm-require: runs-on: ubuntu-latest steps: + - uses: actions/checkout@v2 - id: output-set uses: ./ with: From fb7e8f7c67bc1f9601f71b9bd48bb1148b5e06f4 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:43:02 -0400 Subject: [PATCH 20/24] Add npm ci to integration test --- .github/workflows/integration.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 101b8a18..4479d5f8 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -39,6 +39,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 + - uses: actions/cache@v1 + with: + path: ~/.npm + key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}} + restore-keys: ${{runner.os}}-npm- + - uses: npm ci - id: output-set uses: ./ with: From 5ee517dae8a89d8f425c220d4c8b79151bb7ff02 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:43:39 -0400 Subject: [PATCH 21/24] Workflow syntax error --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 4479d5f8..ade6760d 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -44,7 +44,7 @@ jobs: path: ~/.npm key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}} restore-keys: ${{runner.os}}-npm- - - uses: npm ci + - run: npm ci - id: output-set uses: ./ with: From 256da4ea4d14f7090616071be552b0b2c1df5bf8 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:46:09 -0400 Subject: [PATCH 22/24] Update src/wrap-require.ts Co-authored-by: Josh Gross --- src/wrap-require.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/wrap-require.ts b/src/wrap-require.ts index 22311d99..d7e45ef3 100644 --- a/src/wrap-require.ts +++ b/src/wrap-require.ts @@ -3,7 +3,7 @@ import * as path from 'path' export const wrapRequire = new Proxy(__non_webpack_require__, { apply: (target, thisArg, [moduleID]) => { if (moduleID.startsWith('.')) { - moduleID = path.join(process.cwd(), moduleID) + moduleID = path.resolve(moduleID) return target.apply(thisArg, [moduleID]) } From c758586ea188048eb04fe9297138b77740ac3523 Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:48:25 -0400 Subject: [PATCH 23/24] v4.0.0 --- README.md | 24 ++++++++++++------------ package.json | 2 +- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 49a96675..31669d52 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ The return value of the script will be in the step's outputs under the "result" key. ```yaml -- uses: actions/github-script@v3 +- uses: actions/github-script@v4 id: set-result with: script: return "Hello!" @@ -63,7 +63,7 @@ output of a github-script step. For some workflows, string encoding is preferred `result-encoding` input: ```yaml -- uses: actions/github-script@v3 +- uses: actions/github-script@v4 id: my-script with: github-token: ${{secrets.GITHUB_TOKEN}} @@ -82,7 +82,7 @@ By default, github-script will use the token provided to your workflow. ```yaml - name: View context attributes - uses: actions/github-script@v3 + uses: actions/github-script@v4 with: script: console.log(context) ``` @@ -98,7 +98,7 @@ jobs: comment: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | @@ -121,7 +121,7 @@ jobs: apply-label: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | @@ -142,7 +142,7 @@ jobs: welcome: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | @@ -186,7 +186,7 @@ jobs: diff: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | @@ -211,7 +211,7 @@ jobs: list-issues: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: github-token: ${{secrets.GITHUB_TOKEN}} script: | @@ -246,7 +246,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: script: | const script = require('./path/to/script.js') @@ -284,7 +284,7 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 env: SHA: '${{env.parentSHA}}' with: @@ -325,7 +325,7 @@ jobs: - run: npm ci # or one-off: - run: npm install execa - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 with: script: | const execa = require('execa') @@ -346,7 +346,7 @@ jobs: echo-input: runs-on: ubuntu-latest steps: - - uses: actions/github-script@v3 + - uses: actions/github-script@v4 env: FIRST_NAME: Mona LAST_NAME: Octocat diff --git a/package.json b/package.json index 3e953650..a68abc2a 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "github-script", "description": "A GitHub action for executing a simple script", - "version": "3.1.1", + "version": "4.0.0", "author": "GitHub", "license": "MIT", "main": "dist/index.js", From 2923e50f2900cc87d1480ca89c5058b1b9bb4c4e Mon Sep 17 00:00:00 2001 From: Jonathan Clem Date: Wed, 21 Apr 2021 17:49:15 -0400 Subject: [PATCH 24/24] Run build script --- dist/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/index.js b/dist/index.js index 19a31020..2dd846e6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -2896,7 +2896,7 @@ module.exports = require("assert"); const wrapRequire = new Proxy(require, { apply: (target, thisArg, [moduleID]) => { if (moduleID.startsWith('.')) { - moduleID = path__WEBPACK_IMPORTED_MODULE_0__.join(process.cwd(), moduleID); + moduleID = path__WEBPACK_IMPORTED_MODULE_0__.resolve(moduleID); return target.apply(thisArg, [moduleID]); } try {