From 6c9dcea4432fd0eb2f3e07c9149eab2807ce44b2 Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Wed, 17 Jan 2024 20:27:20 -0700 Subject: [PATCH] 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 --- dist/index.js | Bin 2201140 -> 2200471 bytes dist/index.js.map | Bin 2578101 -> 2577332 bytes src/__tests__/utils.test.ts | 88 +----------------------------------- src/constant.ts | 44 +++++++++--------- src/main.ts | 7 +-- src/utils.ts | 42 ++++------------- 6 files changed, 32 insertions(+), 149 deletions(-) diff --git a/dist/index.js b/dist/index.js index b6ddb957721fbeabcba643049087c10f7ba69270..54c42deaa73c713cab48b4bd84b2e31e845cbb44 100644 GIT binary patch delta 718 zcmZ9~y=xP37zc13wMi4xHYQC@)3p8hf=TcwzD!o6r9!bCtlCwGXYz|VbGb|JE)fxN ztGX!}o~e_9i$X(%j{XNOE>4ARBB({7$>{fzv={urXLw%j`Mq$TKCBbJU#HDCKc7Dh z3oNIs&5BG$?FJ7tN3ISg9NjEPzg{<8-SESj=9Ur7^uJ!KTdwToT)QrNBa3>ebXOXh zt2Z#n&pX^q(s*cAlr+OZFMmvu@?Xe1-)Thn``NN!HKe_$8`AN!&9z^N48nV6{~UvD zOAk%U_HV%V$0$8~(9Dk%68Xa;c+X)O#ar_6Dz0H`u4SWB?N9Ahx_b|n(a?Lxie6hX zbywGnMd=psE(aIeRp@NwFvK3L#ppt?pW)k$fU@=W_r?mZ>`|Z@O+@(R98HIWZr19q zBcAd69wqq80>!th^K@s6|NNz!L)|L3&e1}!s*1dIEzGU2Q)jrfPZ^HAPR03jn{r-w zKBbC^e3I)P)4QX$=0rAM71w#wYu|0tResl|D`fGvHcd8PeV*WGhc2hH7gb?cMa?Pa zFU>fnR*^UGi{!H2ycf$If+KJgj=>NFAPB<{f-oG12#mlej6oDmKn&tA4h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l|I+5MT9;6HD cMtYE5qz|D;KQe$skSG#E_Lg&D?c{s^0Vp}VTmS$7 diff --git a/src/__tests__/utils.test.ts b/src/__tests__/utils.test.ts index 362aee87..84f7297d 100644 --- a/src/__tests__/utils.test.ts +++ b/src/__tests__/utils.test.ts @@ -1,6 +1,4 @@ import * as core from '@actions/core' -import {promises as fs} from 'fs' -import path from 'path' import {ChangeTypeEnum} from '../changedFiles' import {Inputs} from '../inputs' import { @@ -12,7 +10,6 @@ import { } from '../utils' const originalPlatform = process.platform -const ACTION_PATH = path.resolve(__dirname, '..', '..', 'action.yml') function mockedPlatform(platform: string): void { Object.defineProperty(process, 'platform', { @@ -644,97 +641,14 @@ describe('utils test', () => { const coreWarningSpy = jest.spyOn(core, 'warning') await warnUnsupportedRESTAPIInputs({ - actionPath: ACTION_PATH, inputs }) expect(coreWarningSpy).toHaveBeenCalledWith( 'Input "sha" is not supported when using GitHub\'s REST API to get changed files' ) - }) - // Throws an error if there are YAML errors in the action file. - it('should throw an error if there are YAML errors in the action file', async () => { - const actionPath = './path/to/action.yml' - const inputs: Inputs = { - files: '', - filesSeparator: '\n', - filesFromSourceFile: '', - filesFromSourceFileSeparator: '\n', - filesYaml: '', - filesYamlFromSourceFile: '', - filesYamlFromSourceFileSeparator: '\n', - filesIgnore: '', - filesIgnoreSeparator: '\n', - filesIgnoreFromSourceFile: '', - filesIgnoreFromSourceFileSeparator: '\n', - filesIgnoreYaml: '', - filesIgnoreYamlFromSourceFile: '', - filesIgnoreYamlFromSourceFileSeparator: '\n', - separator: ' ', - includeAllOldNewRenamedFiles: false, - oldNewSeparator: ',', - oldNewFilesSeparator: ' ', - sha: '1313123', - baseSha: '', - since: '', - until: '', - path: '.', - quotepath: true, - diffRelative: true, - dirNames: false, - dirNamesMaxDepth: undefined, - dirNamesExcludeCurrentDir: false, - dirNamesIncludeFiles: '', - dirNamesIncludeFilesSeparator: '\n', - dirNamesDeletedFilesIncludeOnlyDeletedDirs: false, - json: false, - escapeJson: true, - safeOutput: true, - fetchDepth: 50, - fetchAdditionalSubmoduleHistory: false, - sinceLastRemoteCommit: false, - writeOutputFiles: false, - outputDir: '.github/outputs', - outputRenamedFilesAsDeletedAndAdded: false, - recoverDeletedFiles: false, - recoverDeletedFilesToDestination: '', - recoverFiles: '', - recoverFilesSeparator: '\n', - recoverFilesIgnore: '', - recoverFilesIgnoreSeparator: '\n', - token: '${{ github.token }}', - apiUrl: '${{ github.api_url }}', - skipInitialFetch: false, - failOnInitialDiffError: false, - failOnSubmoduleDiffError: false, - negationPatternsFirst: false, - useRestApi: false - } - - // Mocking readFile to return action file contents with errors - jest.spyOn(fs, 'readFile').mockResolvedValue(` - inputs: - files: - description: Files - required: true - default: "" - sha: - description: SHA - required: true - default: abc123 - token: - description: Token - required: true - default: my-token - warnings: - | Invalid input value`) - - await expect( - warnUnsupportedRESTAPIInputs({actionPath, inputs}) - ).rejects.toThrow( - /YAML errors in .\/path\/to\/action.yml: YAMLParseError: Not a YAML token: Invalid input value at line 16, column 13:/ - ) + expect(coreWarningSpy).toHaveBeenCalledTimes(1) }) }) }) diff --git a/src/constant.ts b/src/constant.ts index 0eb7b0ea..7ce6c05b 100644 --- a/src/constant.ts +++ b/src/constant.ts @@ -1,24 +1,24 @@ import {Inputs} from './inputs' -export const UNSUPPORTED_REST_API_INPUTS: (keyof Inputs)[] = [ - 'sha', - 'baseSha', - 'since', - 'until', - 'path', - 'quotepath', - 'diffRelative', - 'sinceLastRemoteCommit', - 'recoverDeletedFiles', - 'recoverDeletedFilesToDestination', - 'recoverFiles', - 'recoverFilesSeparator', - 'recoverFilesIgnore', - 'recoverFilesIgnoreSeparator', - 'includeAllOldNewRenamedFiles', - 'oldNewSeparator', - 'oldNewFilesSeparator', - 'skipInitialFetch', - 'fetchAdditionalSubmoduleHistory', - 'dirNamesDeletedFilesIncludeOnlyDeletedDirs' -] +export const UNSUPPORTED_REST_API_INPUTS: Partial = { + sha: '', + baseSha: '', + since: '', + until: '', + path: '.', + quotepath: true, + diffRelative: true, + sinceLastRemoteCommit: false, + recoverDeletedFiles: false, + recoverDeletedFilesToDestination: '', + recoverFiles: '', + recoverFilesSeparator: '\n', + recoverFilesIgnore: '', + recoverFilesIgnoreSeparator: '\n', + includeAllOldNewRenamedFiles: false, + oldNewSeparator: ',', + oldNewFilesSeparator: ' ', + skipInitialFetch: false, + fetchAdditionalSubmoduleHistory: false, + dirNamesDeletedFilesIncludeOnlyDeletedDirs: false +} diff --git a/src/main.ts b/src/main.ts index b4b50f4f..4ce10716 100644 --- a/src/main.ts +++ b/src/main.ts @@ -256,12 +256,7 @@ export async function run(): Promise { (!hasGitDirectory || inputs.useRestApi) ) { core.info("Using GitHub's REST API to get changed files") - if (process.env.GITHUB_ACTION_PATH) { - await warnUnsupportedRESTAPIInputs({ - actionPath: path.join(process.env.GITHUB_ACTION_PATH, 'action.yml'), - inputs - }) - } + await warnUnsupportedRESTAPIInputs({inputs}) await getChangedFilesFromRESTAPI({ inputs, filePatterns, diff --git a/src/utils.ts b/src/utils.ts index 61f745d4..c97db3bf 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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 => { - 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` ) } }