feat: add script-file input for lint-friendly external JS scripts#715
Open
osher wants to merge 1 commit intoactions:mainfrom
Open
feat: add script-file input for lint-friendly external JS scripts#715osher wants to merge 1 commit intoactions:mainfrom
osher wants to merge 1 commit intoactions:mainfrom
Conversation
Author
|
still draft - need to add more integration tests |
1e953cb to
23d9e30
Compare
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)
Author
|
ok. done... no more petty polishing. I'll just wait for feedback now... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #714
Problem
Inline
scriptis a YAML string — invisible to linters and IDEs. The common workaround was wrapping arequirecall 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-fileinput that accepts a path to a JS file. The filemodule.exportsan 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).scriptandscript-fileare mutually exclusive — exactly one must be provided. Relative paths resolve against$GITHUB_WORKSPACE; absolute paths are used as-is.Changes
action.yml— addsscript-fileinput; makesscriptoptionalsrc/script-file.ts— path resolution and script loading logicsrc/args.ts—AsyncFunctionArgumentsextracted fromasync-function.tsso neither execution path depends on the othersrc/main.ts— mutual-exclusion validation; dispatches to the right execution pathtypes/non-webpack-require.ts— corrects__non_webpack_require__type from deprecatedNodeRequire/ wrongNodeJS.RequireResolvetoNodeJS.Require__test__/script-file.test.ts— 10 tests covering path resolution, arg forwarding, error casesREADME.md— new## Script filesection 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)