Skip to content

feat: add script-file input for lint-friendly external JS scripts#715

Open
osher wants to merge 1 commit intoactions:mainfrom
osher:feat/script-file
Open

feat: add script-file input for lint-friendly external JS scripts#715
osher wants to merge 1 commit intoactions:mainfrom
osher:feat/script-file

Conversation

@osher
Copy link
Copy Markdown

@osher osher commented Apr 25, 2026

Closes #714

Problem

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.

The current solution requires some ugly scaffolding. We can improve DevX and provide the scaffold as a part of the service :)

Solution

New optional script-file input that accepts a path to a JS file. The file module.exports an function (potentially async) that is called with the a IoC dependency bag with everything in-line scripts experience (github, octokit, getOctokit, context, core, exec, glob, io, require).

- 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.

Changes

  • action.yml — adds script-file input; makes script optional
  • src/script-file.ts — path resolution and script loading logic
  • src/args.tsAsyncFunctionArguments 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)

@osher osher requested a review from a team as a code owner April 25, 2026 16:59
@osher osher marked this pull request as draft April 25, 2026 17:05
@osher
Copy link
Copy Markdown
Author

osher commented Apr 25, 2026

still draft - need to add more integration tests

@osher osher force-pushed the feat/script-file branch from 2c6be1d to 37c2031 Compare April 25, 2026 17:16
@osher osher marked this pull request as ready for review April 26, 2026 07:55
@osher osher force-pushed the feat/script-file branch 4 times, most recently from 1e953cb to 23d9e30 Compare April 26, 2026 08:53
Closes actions#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)
@osher osher force-pushed the feat/script-file branch from 23d9e30 to 67c280d Compare April 26, 2026 09:06
@osher
Copy link
Copy Markdown
Author

osher commented Apr 26, 2026

ok. done... no more petty polishing. I'll just wait for feedback now...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

support script-file - path to a file.

1 participant