mirror of
https://github.com/actions/github-script.git
synced 2026-06-06 17:14:23 +00:00
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)
This commit is contained in:
parent
3a2844b7e9
commit
67c280d263
18 changed files with 519 additions and 97 deletions
11
action.yml
11
action.yml
|
|
@ -6,8 +6,15 @@ branding:
|
|||
icon: code
|
||||
inputs:
|
||||
script:
|
||||
description: The script to run
|
||||
required: true
|
||||
description: The script to run (mutually exclusive with script-file)
|
||||
required: false
|
||||
script-file:
|
||||
description: |
|
||||
A path to a JS file that exports an action handler. (mutually exclusive with script)
|
||||
Path may be absolute, or relative to your repo root.
|
||||
The handler may be async.
|
||||
The handler is called with an IoC bag with {context, core, exec, github, octokit, getOctokit, glob, io, require} - destructure what you need.
|
||||
required: false
|
||||
github-token:
|
||||
description: The GitHub token used to create an authenticated client
|
||||
default: ${{ github.token }}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue