Skip to content

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 11 commits into from
Feb 8, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
"@types/js-yaml": "^4.0.9",
"@types/node": "^20.11.5",
"@types/node-fetch": "^2.6.11",
"ajv": "^8.12.0",
"expand-tilde": "^2.0.2",
"fs-extra": "^11.2.0",
"yaml": "^2.3.4"
"yaml": "^2.3.4",
"zod": "^3.22.4"
},
"devDependencies": {
"@vercel/ncc": "^0.38.1",
Expand Down
43 changes: 7 additions & 36 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

88 changes: 34 additions & 54 deletions src/inputs/run-install.ts
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(),
})

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),
])

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;
}