fix: update input warning (#1870)

Co-authored-by: tj-actions[bot] <109116665+tj-actions-bot@users.noreply.github.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack
2024-01-17 20:27:20 -07:00
committed by GitHub
parent 79b060d445
commit 6c9dcea443
6 changed files with 63 additions and 197 deletions

View File

@@ -1513,52 +1513,26 @@ export const hasLocalGitDirectory = async ({
/**
* Warns about unsupported inputs when using the REST API.
*
* @param actionPath - The path to the action file.
* @param inputs - The inputs object.
*/
export const warnUnsupportedRESTAPIInputs = async ({
actionPath,
inputs
}: {
actionPath: string
inputs: Inputs
}): Promise<void> => {
const actionContents = await fs.readFile(actionPath, 'utf8')
const actionYaml = parseDocument(actionContents, {schema: 'failsafe'})
if (actionYaml.errors.length > 0) {
throw new Error(
`YAML errors in ${actionPath}: ${actionYaml.errors.join(', ')}`
)
}
if (actionYaml.warnings.length > 0) {
throw new Error(
`YAML warnings in ${actionPath}: ${actionYaml.warnings.join(', ')}`
)
}
const action = actionYaml.toJS() as {
inputs: {
[key: string]: {description: string; required: boolean; default: string}
}
}
const actionInputs = action.inputs
for (const key of UNSUPPORTED_REST_API_INPUTS) {
const inputKey = snakeCase(key) as keyof Inputs
for (const key of Object.keys(UNSUPPORTED_REST_API_INPUTS)) {
const defaultValue = Object.hasOwnProperty.call(
actionInputs[inputKey],
'default'
UNSUPPORTED_REST_API_INPUTS,
key
)
? actionInputs[inputKey].default.toString()
? UNSUPPORTED_REST_API_INPUTS[key as keyof Inputs]?.toString()
: ''
if (defaultValue !== inputs[key]?.toString()) {
if (defaultValue !== inputs[key as keyof Inputs]?.toString()) {
core.warning(
`Input "${inputKey}" is not supported when using GitHub's REST API to get changed files`
`Input "${snakeCase(
key
)}" is not supported when using GitHub's REST API to get changed files`
)
}
}