You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat: add script-file input for lint-friendly external JS scripts
Closes#714
Inline `script` is a YAML string — invisible to linters and IDEs.
The common workaround was wrapping a `require` call inside the inline script,
which still needs boilerplate and assumes a path convention.
New optional `script-file` input that accepts a path to a JS file.
The file must `module.exports` an async function receiving the standard
IoC dependency bag (`github`, `octokit`, `getOctokit`, `context`, `core`,
`exec`, `glob`, `io`, `require`).
```yaml
- uses: actions/checkout@v4
- uses: actions/github-script@v9
with:
script-file: .github/scripts/my-script.js
```
`script` and `script-file` are mutually exclusive — exactly one must be provided.
Relative paths resolve against `$GITHUB_WORKSPACE`; absolute paths are used as-is.
- `action.yml` — adds `script-file` input; makes `script` optional
- `src/script-file.ts` — path resolution and script loading logic
- `src/args.ts` — `AsyncFunctionArguments` extracted from `async-function.ts` so neither execution path depends on the other
- `src/main.ts` — mutual-exclusion validation; dispatches to the right execution path
- `types/non-webpack-require.ts` — corrects `__non_webpack_require__` type from deprecated `NodeRequire` / wrong `NodeJS.RequireResolve` to `NodeJS.Require`
- `__test__/script-file.test.ts` — 10 tests covering path resolution, arg forwarding, error cases
- `README.md` — new `## Script file` section with usage, IoC bag table, path resolution rules
- `.github/fixtures/script-file/` — fixture JS files for integration tests
- `.github/workflows/integration.yml` — 10 new integration test jobs: happy path (relative path, absolute path, all IoC args, json/string encoding,
require-in-file) and error cases (both inputs set, neither set, nonexistent file, non-function export, file:// protocol)
Copy file name to clipboardExpand all lines: README.md
+65-39Lines changed: 65 additions & 39 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,8 +27,9 @@ You are welcome to still raise bugs in this repo.
27
27
28
28
### This action
29
29
30
-
To use this action, provide an input named `script` that contains the body of an asynchronous JavaScript function call.
31
-
The following arguments will be provided:
30
+
To use this action, provide either a `script` input (the body of an async function, inline in your workflow YAML) or a `script-file` input (a path to a JS file that `module.exports` an async function). Exactly one of the two must be provided.
31
+
32
+
The following arguments are available to both forms:
32
33
33
34
-`github` A pre-authenticated
34
35
[octokit/rest.js](https://octokit.github.io/rest.js) client with pagination plugins
@@ -201,6 +202,56 @@ By default, the following status codes will not be retried: `400, 401, 403, 404,
201
202
202
203
These retries are implemented using the [octokit/plugin-retry.js](https://github.com/octokit/plugin-retry.js) plugin. The retries use [exponential backoff](https://en.wikipedia.org/wiki/Exponential_backoff) to space out retries. ([source](https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/error-request.ts#L13))
203
204
205
+
## Script file
206
+
207
+
Coding long JS logic in yaml is not linted as JS/TS.
208
+
Instead of providing the `script` inline, you can use `script-file` to point to a JS file in your repository. The file must proide `module.exports` as an function (that may be async) — making it a proper module that linters and IDEs can fully analyse.
209
+
210
+
The action handler is called with a single [IoC](https://en.wikipedia.org/wiki/Inversion_of_control) dependency bag (defined in [`src/args.ts`](src/args.ts)). Its members are the same as those available to the inline `script`:
Note that because you can't `require` things like the GitHub context or
458
+
Actions Toolkit libraries, you'll want to accept them as arguments to your
459
+
external function: Your action is called with an [IoC](https://en.wikipedia.org/wiki/Inversion_of_control) dependency bag - destructure from it whatever you need. Check the docs above in the **Script file** section.
460
+
461
+
Additionally, you'll want to use the [checkout
462
+
action](https://github.com/actions/checkout) to make sure your script file is
463
+
available.
464
+
439
465
### Use npm packages
440
466
441
467
Like importing your own files above, you can also use installed modules.
0 commit comments