Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 3110e8d

Browse filesBrowse files
authored
Merge 2923e50 into 59cb74c
2 parents 59cb74c + 2923e50 commit 3110e8d
Copy full SHA for 3110e8d

File tree

8 files changed

+181
-69
lines changed
Filter options

8 files changed

+181
-69
lines changed

‎.github/workflows/integration.yml

Copy file name to clipboardExpand all lines: .github/workflows/integration.yml
+40-2Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@ name: Integration
22

33
on:
44
push: {branches: main}
5+
pull_request: {branches: main}
56

67
jobs:
7-
integration:
8+
test-return:
89
runs-on: ubuntu-latest
910
steps:
11+
- uses: actions/checkout@v2
1012
- id: output-set
11-
uses: actions/github-script@main
13+
uses: ./
1214
with:
1315
script: return core.getInput('input-value')
1416
result-encoding: string
@@ -17,3 +19,39 @@ jobs:
1719
if [[ "${{steps.output-set.outputs.result}}" != "output" ]]; then
1820
exit 1
1921
fi
22+
23+
test-relative-require:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- uses: actions/checkout@v2
27+
- id: output-set
28+
uses: ./
29+
with:
30+
script: return require('./package.json').name
31+
result-encoding: string
32+
input-value: output
33+
- run: |
34+
if [[ "${{steps.output-set.outputs.result}}" != "github-script" ]]; then
35+
exit 1
36+
fi
37+
38+
test-npm-require:
39+
runs-on: ubuntu-latest
40+
steps:
41+
- uses: actions/checkout@v2
42+
- uses: actions/cache@v1
43+
with:
44+
path: ~/.npm
45+
key: ${{runner.os}}-npm-${{hashFiles('**/package-lock.json')}}
46+
restore-keys: ${{runner.os}}-npm-
47+
- run: npm ci
48+
- id: output-set
49+
uses: ./
50+
with:
51+
script: return require('@actions/core/package.json').name
52+
result-encoding: string
53+
input-value: output
54+
- run: |
55+
if [[ "${{steps.output-set.outputs.result}}" != "@actions/core" ]]; then
56+
exit 1
57+
fi

‎README.md

Copy file name to clipboardExpand all lines: README.md
+30-26Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ arguments will be provided:
1818
- `core` A reference to the [@actions/core](https://github.com/actions/toolkit/tree/main/packages/core) package
1919
- `glob` A reference to the [@actions/glob](https://github.com/actions/toolkit/tree/main/packages/glob) package
2020
- `io` A reference to the [@actions/io](https://github.com/actions/toolkit/tree/main/packages/io) package
21+
- `require` A proxy wrapper around the normal Node.js `require` to enable
22+
requiring relative paths (relative to the current working directory) and
23+
requiring npm packages installed in the current working directory. If for
24+
some reason you need the non-wrapped `require`, there is an escape hatch
25+
available: `__original_require__` is the original value of `require` without
26+
our wrapping applied.
2127

2228
Since the `script` is just a function body, these values will already be
2329
defined, so you don't have to (see examples below).
@@ -38,7 +44,7 @@ The return value of the script will be in the step's outputs under the
3844
"result" key.
3945

4046
```yaml
41-
- uses: actions/github-script@v3
47+
- uses: actions/github-script@v4
4248
id: set-result
4349
with:
4450
script: return "Hello!"
@@ -57,7 +63,7 @@ output of a github-script step. For some workflows, string encoding is preferred
5763
`result-encoding` input:
5864

5965
```yaml
60-
- uses: actions/github-script@v3
66+
- uses: actions/github-script@v4
6167
id: my-script
6268
with:
6369
github-token: ${{secrets.GITHUB_TOKEN}}
@@ -76,7 +82,7 @@ By default, github-script will use the token provided to your workflow.
7682

7783
```yaml
7884
- name: View context attributes
79-
uses: actions/github-script@v3
85+
uses: actions/github-script@v4
8086
with:
8187
script: console.log(context)
8288
```
@@ -92,7 +98,7 @@ jobs:
9298
comment:
9399
runs-on: ubuntu-latest
94100
steps:
95-
- uses: actions/github-script@v3
101+
- uses: actions/github-script@v4
96102
with:
97103
github-token: ${{secrets.GITHUB_TOKEN}}
98104
script: |
@@ -115,7 +121,7 @@ jobs:
115121
apply-label:
116122
runs-on: ubuntu-latest
117123
steps:
118-
- uses: actions/github-script@v3
124+
- uses: actions/github-script@v4
119125
with:
120126
github-token: ${{secrets.GITHUB_TOKEN}}
121127
script: |
@@ -136,7 +142,7 @@ jobs:
136142
welcome:
137143
runs-on: ubuntu-latest
138144
steps:
139-
- uses: actions/github-script@v3
145+
- uses: actions/github-script@v4
140146
with:
141147
github-token: ${{secrets.GITHUB_TOKEN}}
142148
script: |
@@ -180,7 +186,7 @@ jobs:
180186
diff:
181187
runs-on: ubuntu-latest
182188
steps:
183-
- uses: actions/github-script@v3
189+
- uses: actions/github-script@v4
184190
with:
185191
github-token: ${{secrets.GITHUB_TOKEN}}
186192
script: |
@@ -205,7 +211,7 @@ jobs:
205211
list-issues:
206212
runs-on: ubuntu-latest
207213
steps:
208-
- uses: actions/github-script@v3
214+
- uses: actions/github-script@v4
209215
with:
210216
github-token: ${{secrets.GITHUB_TOKEN}}
211217
script: |
@@ -240,15 +246,13 @@ jobs:
240246
runs-on: ubuntu-latest
241247
steps:
242248
- uses: actions/checkout@v2
243-
- uses: actions/github-script@v3
249+
- uses: actions/github-script@v4
244250
with:
245251
script: |
246-
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
252+
const script = require('./path/to/script.js')
247253
console.log(script({github, context}))
248254
```
249255
250-
_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)._
251-
252256
And then export a function from your module:
253257
254258
```javascript
@@ -280,26 +284,26 @@ jobs:
280284
runs-on: ubuntu-latest
281285
steps:
282286
- uses: actions/checkout@v2
283-
- uses: actions/github-script@v3
287+
- uses: actions/github-script@v4
284288
env:
285-
SHA: "${{env.parentSHA}}"
289+
SHA: '${{env.parentSHA}}'
286290
with:
287291
script: |
288-
const script = require(`${process.env.GITHUB_WORKSPACE}/path/to/script.js`)
292+
const script = require('./path/to/script.js')
289293
await script({github, context, core})
290294
```
291295
292296
And then export an async function from your module:
293297
294298
```javascript
295-
module.exports = async ({ github, context, core }) => {
296-
const { SHA } = process.env
297-
const commit = await github.repos.getCommit({
298-
owner: context.repo.owner,
299-
repo: context.repo.repo,
300-
ref: `${SHA}`
301-
})
302-
core.exportVariable('author', commit.data.commit.author.email);
299+
module.exports = async ({github, context, core}) => {
300+
const {SHA} = process.env
301+
const commit = await github.repos.getCommit({
302+
owner: context.repo.owner,
303+
repo: context.repo.repo,
304+
ref: `${SHA}`
305+
})
306+
core.exportVariable('author', commit.data.commit.author.email)
303307
}
304308
```
305309

@@ -321,10 +325,10 @@ jobs:
321325
- run: npm ci
322326
# or one-off:
323327
- run: npm install execa
324-
- uses: actions/github-script@v3
328+
- uses: actions/github-script@v4
325329
with:
326330
script: |
327-
const execa = require(`${process.env.GITHUB_WORKSPACE}/node_modules/execa`)
331+
const execa = require('execa')
328332
329333
const { stdout } = await execa('echo', ['hello', 'world'])
330334
@@ -342,7 +346,7 @@ jobs:
342346
echo-input:
343347
runs-on: ubuntu-latest
344348
steps:
345-
- uses: actions/github-script@v3
349+
- uses: actions/github-script@v4
346350
env:
347351
FIRST_NAME: Mona
348352
LAST_NAME: Octocat

‎dist/index.js

Copy file name to clipboardExpand all lines: dist/index.js
+69-39Lines changed: 69 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2883,6 +2883,43 @@ function escapeProperty(s) {
28832883

28842884
module.exports = require("assert");
28852885

2886+
/***/ }),
2887+
2888+
/***/ 366:
2889+
/***/ (function(__unusedmodule, __webpack_exports__, __webpack_require__) {
2890+
2891+
"use strict";
2892+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "wrapRequire", function() { return wrapRequire; });
2893+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(622);
2894+
/* harmony import */ var path__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(path__WEBPACK_IMPORTED_MODULE_0__);
2895+
2896+
const wrapRequire = new Proxy(require, {
2897+
apply: (target, thisArg, [moduleID]) => {
2898+
if (moduleID.startsWith('.')) {
2899+
moduleID = path__WEBPACK_IMPORTED_MODULE_0__.resolve(moduleID);
2900+
return target.apply(thisArg, [moduleID]);
2901+
}
2902+
try {
2903+
return target.apply(thisArg, [moduleID]);
2904+
}
2905+
catch (err) {
2906+
const modulePath = target.resolve.apply(thisArg, [
2907+
moduleID,
2908+
{
2909+
// Webpack does not have an escape hatch for getting the actual
2910+
// module, other than `eval`.
2911+
paths: eval('module').paths.concat(process.cwd())
2912+
}
2913+
]);
2914+
return target.apply(thisArg, [modulePath]);
2915+
}
2916+
},
2917+
get: (target, prop, receiver) => {
2918+
Reflect.get(target, prop, receiver);
2919+
}
2920+
});
2921+
2922+
28862923
/***/ }),
28872924

28882925
/***/ 413:
@@ -6121,12 +6158,16 @@ function callAsyncFunction(args, source) {
61216158
return fn(...Object.values(args));
61226159
}
61236160

6161+
// EXTERNAL MODULE: ./src/wrap-require.ts
6162+
var wrap_require = __webpack_require__(366);
6163+
61246164
// CONCATENATED MODULE: ./src/main.ts
61256165

61266166

61276167

61286168

61296169

6170+
61306171
process.on('unhandledRejection', handleError);
61316172
main().catch(handleError);
61326173
async function main() {
@@ -6144,7 +6185,15 @@ async function main() {
61446185
const github = Object(lib_github.getOctokit)(token, opts);
61456186
const script = Object(core.getInput)('script', { required: true });
61466187
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
6147-
const result = await callAsyncFunction({ require: __webpack_require__(875), github, context: lib_github.context, core: core, glob: glob, io: io }, script);
6188+
const result = await callAsyncFunction({
6189+
require: wrap_require.wrapRequire,
6190+
__original_require__: require,
6191+
github,
6192+
context: lib_github.context,
6193+
core: core,
6194+
glob: glob,
6195+
io: io
6196+
}, script);
61486197
let encoding = Object(core.getInput)('result-encoding');
61496198
encoding = encoding ? encoding : 'json';
61506199
let output;
@@ -6901,25 +6950,6 @@ function expand(str, isTop) {
69016950

69026951

69036952

6904-
/***/ }),
6905-
6906-
/***/ 875:
6907-
/***/ (function(module) {
6908-
6909-
function webpackEmptyContext(req) {
6910-
if (typeof req === 'number' && __webpack_require__.m[req])
6911-
return __webpack_require__(req);
6912-
try { return require(req) }
6913-
catch (e) { if (e.code !== 'MODULE_NOT_FOUND') throw e }
6914-
var e = new Error("Cannot find module '" + req + "'");
6915-
e.code = 'MODULE_NOT_FOUND';
6916-
throw e;
6917-
}
6918-
webpackEmptyContext.keys = function() { return []; };
6919-
webpackEmptyContext.resolve = webpackEmptyContext;
6920-
module.exports = webpackEmptyContext;
6921-
webpackEmptyContext.id = 875;
6922-
69236953
/***/ }),
69246954

69256955
/***/ 877:
@@ -8743,14 +8773,15 @@ function regExpEscape (s) {
87438773
/******/ function(__webpack_require__) { // webpackRuntimeModules
87448774
/******/ "use strict";
87458775
/******/
8746-
/******/ /* webpack/runtime/make namespace object */
8776+
/******/ /* webpack/runtime/compat get default export */
87478777
/******/ !function() {
8748-
/******/ // define __esModule on exports
8749-
/******/ __webpack_require__.r = function(exports) {
8750-
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
8751-
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
8752-
/******/ }
8753-
/******/ Object.defineProperty(exports, '__esModule', { value: true });
8778+
/******/ // getDefaultExport function for compatibility with non-harmony modules
8779+
/******/ __webpack_require__.n = function(module) {
8780+
/******/ var getter = module && module.__esModule ?
8781+
/******/ function getDefault() { return module['default']; } :
8782+
/******/ function getModuleExports() { return module; };
8783+
/******/ __webpack_require__.d(getter, 'a', getter);
8784+
/******/ return getter;
87548785
/******/ };
87558786
/******/ }();
87568787
/******/
@@ -8765,6 +8796,17 @@ function regExpEscape (s) {
87658796
/******/ };
87668797
/******/ }();
87678798
/******/
8799+
/******/ /* webpack/runtime/make namespace object */
8800+
/******/ !function() {
8801+
/******/ // define __esModule on exports
8802+
/******/ __webpack_require__.r = function(exports) {
8803+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
8804+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
8805+
/******/ }
8806+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
8807+
/******/ };
8808+
/******/ }();
8809+
/******/
87688810
/******/ /* webpack/runtime/create fake namespace object */
87698811
/******/ !function() {
87708812
/******/ // create a fake namespace object
@@ -8784,17 +8826,5 @@ function regExpEscape (s) {
87848826
/******/ };
87858827
/******/ }();
87868828
/******/
8787-
/******/ /* webpack/runtime/compat get default export */
8788-
/******/ !function() {
8789-
/******/ // getDefaultExport function for compatibility with non-harmony modules
8790-
/******/ __webpack_require__.n = function(module) {
8791-
/******/ var getter = module && module.__esModule ?
8792-
/******/ function getDefault() { return module['default']; } :
8793-
/******/ function getModuleExports() { return module; };
8794-
/******/ __webpack_require__.d(getter, 'a', getter);
8795-
/******/ return getter;
8796-
/******/ };
8797-
/******/ }();
8798-
/******/
87998829
/******/ }
88008830
);

‎package.json

Copy file name to clipboardExpand all lines: package.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "github-script",
33
"description": "A GitHub action for executing a simple script",
4-
"version": "3.1.1",
4+
"version": "4.0.0",
55
"author": "GitHub",
66
"license": "MIT",
77
"main": "dist/index.js",

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.