-
-
Notifications
You must be signed in to change notification settings - Fork 120
node20 upgrade #110
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
node20 upgrade #110
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
cd44942
upgrade versions to latest
erikburt 7b9ebc1
remove usage of ts-schema-autogen
erikburt a4ed51b
fix: update pnpm sources
erikburt 698b742
update build/output
erikburt 7df928f
use node20
erikburt 8e68382
fix: run-install array output
erikburt 3dac3a5
fix: maintain behaviour for parseRunInstall, error messages
erikburt 7302d3b
fix: another edge case for input.args
erikburt 2be3e92
fix: use zod for input validation
erikburt e801474
fix: use zod.infer for exported RunInstall types
erikburt 5ad762b
fix: remove @types/js-yaml
zkochan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,70 +1,50 @@ | ||
import { getInput, InputOptions, error } from '@actions/core' | ||
import { parse } from 'yaml' | ||
import { getInput, error } from '@actions/core' | ||
import * as yaml from 'yaml' | ||
import { z, ZodError } from 'zod' | ||
|
||
export interface RunInstall { | ||
readonly recursive?: boolean | ||
readonly cwd?: string | ||
readonly args?: readonly string[] | ||
} | ||
|
||
const zRunInstall = z.object({ | ||
recursive: z.boolean().optional(), | ||
cwd: z.string().optional(), | ||
args: z.array(z.string()).optional(), | ||
}) | ||
|
||
KSXGitHub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
export type RunInstallInput = | ||
| null | ||
| boolean | ||
| RunInstall | ||
| RunInstall[] | ||
|
||
const options: InputOptions = { | ||
required: true, | ||
} | ||
|
||
export function parseRunInstall(name: string): RunInstall[] { | ||
const input: any = parse(getInput(name, options)) | ||
|
||
if (!input) return [] | ||
if (input === true) return [{ recursive: true }] | ||
|
||
if (!isInputValid(input)) process.exit(1); | ||
|
||
return Array.isArray(input) ? input : [input] | ||
} | ||
|
||
function isInputValid(input: any) { | ||
if (Array.isArray(input)) { | ||
return input.every(isEntryValid) | ||
} else { | ||
return isEntryValid(input) | ||
} | ||
} | ||
|
||
function isEntryValid(input: any): boolean { | ||
if (typeof input !== 'object') { | ||
error(`Invalid input for run_install. Expected object, but got ${typeof input}`) | ||
return false; | ||
} | ||
|
||
if (input.recursive !== undefined && typeof input.recursive !== 'boolean') { | ||
error(`Invalid input for run_install.recursive. Expected boolean, but got ${typeof input.recursive}`) | ||
return false; | ||
} | ||
|
||
if (input.cwd !== undefined && typeof input.cwd !== 'string') { | ||
error(`Invalid input for run_install.cwd. Expected string, but got ${typeof input.cwd}`) | ||
return false; | ||
} | ||
|
||
if (input.args !== undefined) { | ||
if (!Array.isArray(input.args)) { | ||
error(`Invalid input for run_install.args. Expected array, but got ${typeof input.args}`) | ||
return false; | ||
} | ||
|
||
const invalidArgs: any[] = input.args.filter((arg: any) => typeof arg !== 'string'); | ||
if (invalidArgs.length > 0) { | ||
const invalidArgsMessage = invalidArgs.map((arg: any) => typeof arg).join(', '); | ||
error(`Invalid input for run_install.args. Expected array of strings, but got ${invalidArgsMessage}`) | ||
return false; | ||
const zRunInstallInput = z.union([ | ||
z.null(), | ||
z.boolean(), | ||
zRunInstall, | ||
z.array(zRunInstall), | ||
]) | ||
KSXGitHub marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
export function parseRunInstall(inputName: string): RunInstall[] { | ||
const input = getInput(inputName, { required: true }) | ||
const parsedInput: unknown = yaml.parse(input) | ||
|
||
try { | ||
const result: RunInstallInput = zRunInstallInput.parse(parsedInput) | ||
if (!result) return [] | ||
if (result === true) return [{ recursive: true }] | ||
if (Array.isArray(result)) return result | ||
return [result] | ||
} catch (exception: unknown) { | ||
error(`Error for input "${inputName}" = ${input}`) | ||
|
||
if (exception instanceof ZodError) { | ||
error(`Errors: ${exception.errors}`) | ||
} else { | ||
error(`Exception: ${exception}`) | ||
} | ||
process.exit(1) | ||
} | ||
|
||
return true; | ||
} |
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.
Uh oh!
There was an error while loading. Please reload this page.