Skip to content

Commit 6c9dcea

Browse files
jackton1tj-actions-botrenovate[bot]actions-user
authored
fix: update input warning (#1870)
Co-authored-by: tj-actions[bot] <[email protected]> Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com> Co-authored-by: GitHub Action <[email protected]>
1 parent 79b060d commit 6c9dcea

File tree

6 files changed

+63
-197
lines changed

6 files changed

+63
-197
lines changed

dist/index.js

Lines changed: 30 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/__tests__/utils.test.ts

Lines changed: 1 addition & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
import * as core from '@actions/core'
2-
import {promises as fs} from 'fs'
3-
import path from 'path'
42
import {ChangeTypeEnum} from '../changedFiles'
53
import {Inputs} from '../inputs'
64
import {
@@ -12,7 +10,6 @@ import {
1210
} from '../utils'
1311

1412
const originalPlatform = process.platform
15-
const ACTION_PATH = path.resolve(__dirname, '..', '..', 'action.yml')
1613

1714
function mockedPlatform(platform: string): void {
1815
Object.defineProperty(process, 'platform', {
@@ -644,97 +641,14 @@ describe('utils test', () => {
644641
const coreWarningSpy = jest.spyOn(core, 'warning')
645642

646643
await warnUnsupportedRESTAPIInputs({
647-
actionPath: ACTION_PATH,
648644
inputs
649645
})
650646

651647
expect(coreWarningSpy).toHaveBeenCalledWith(
652648
'Input "sha" is not supported when using GitHub\'s REST API to get changed files'
653649
)
654-
})
655-
656-
// Throws an error if there are YAML errors in the action file.
657-
it('should throw an error if there are YAML errors in the action file', async () => {
658-
const actionPath = './path/to/action.yml'
659-
const inputs: Inputs = {
660-
files: '',
661-
filesSeparator: '\n',
662-
filesFromSourceFile: '',
663-
filesFromSourceFileSeparator: '\n',
664-
filesYaml: '',
665-
filesYamlFromSourceFile: '',
666-
filesYamlFromSourceFileSeparator: '\n',
667-
filesIgnore: '',
668-
filesIgnoreSeparator: '\n',
669-
filesIgnoreFromSourceFile: '',
670-
filesIgnoreFromSourceFileSeparator: '\n',
671-
filesIgnoreYaml: '',
672-
filesIgnoreYamlFromSourceFile: '',
673-
filesIgnoreYamlFromSourceFileSeparator: '\n',
674-
separator: ' ',
675-
includeAllOldNewRenamedFiles: false,
676-
oldNewSeparator: ',',
677-
oldNewFilesSeparator: ' ',
678-
sha: '1313123',
679-
baseSha: '',
680-
since: '',
681-
until: '',
682-
path: '.',
683-
quotepath: true,
684-
diffRelative: true,
685-
dirNames: false,
686-
dirNamesMaxDepth: undefined,
687-
dirNamesExcludeCurrentDir: false,
688-
dirNamesIncludeFiles: '',
689-
dirNamesIncludeFilesSeparator: '\n',
690-
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false,
691-
json: false,
692-
escapeJson: true,
693-
safeOutput: true,
694-
fetchDepth: 50,
695-
fetchAdditionalSubmoduleHistory: false,
696-
sinceLastRemoteCommit: false,
697-
writeOutputFiles: false,
698-
outputDir: '.github/outputs',
699-
outputRenamedFilesAsDeletedAndAdded: false,
700-
recoverDeletedFiles: false,
701-
recoverDeletedFilesToDestination: '',
702-
recoverFiles: '',
703-
recoverFilesSeparator: '\n',
704-
recoverFilesIgnore: '',
705-
recoverFilesIgnoreSeparator: '\n',
706-
token: '${{ github.token }}',
707-
apiUrl: '${{ github.api_url }}',
708-
skipInitialFetch: false,
709-
failOnInitialDiffError: false,
710-
failOnSubmoduleDiffError: false,
711-
negationPatternsFirst: false,
712-
useRestApi: false
713-
}
714650

715-
// Mocking readFile to return action file contents with errors
716-
jest.spyOn(fs, 'readFile').mockResolvedValue(`
717-
inputs:
718-
files:
719-
description: Files
720-
required: true
721-
default: ""
722-
sha:
723-
description: SHA
724-
required: true
725-
default: abc123
726-
token:
727-
description: Token
728-
required: true
729-
default: my-token
730-
warnings:
731-
| Invalid input value`)
732-
733-
await expect(
734-
warnUnsupportedRESTAPIInputs({actionPath, inputs})
735-
).rejects.toThrow(
736-
/YAML errors in .\/path\/to\/action.yml: YAMLParseError: Not a YAML token: Invalid input value at line 16, column 13:/
737-
)
651+
expect(coreWarningSpy).toHaveBeenCalledTimes(1)
738652
})
739653
})
740654
})

src/constant.ts

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,24 @@
11
import {Inputs} from './inputs'
22

3-
export const UNSUPPORTED_REST_API_INPUTS: (keyof Inputs)[] = [
4-
'sha',
5-
'baseSha',
6-
'since',
7-
'until',
8-
'path',
9-
'quotepath',
10-
'diffRelative',
11-
'sinceLastRemoteCommit',
12-
'recoverDeletedFiles',
13-
'recoverDeletedFilesToDestination',
14-
'recoverFiles',
15-
'recoverFilesSeparator',
16-
'recoverFilesIgnore',
17-
'recoverFilesIgnoreSeparator',
18-
'includeAllOldNewRenamedFiles',
19-
'oldNewSeparator',
20-
'oldNewFilesSeparator',
21-
'skipInitialFetch',
22-
'fetchAdditionalSubmoduleHistory',
23-
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
24-
]
3+
export const UNSUPPORTED_REST_API_INPUTS: Partial<Inputs> = {
4+
sha: '',
5+
baseSha: '',
6+
since: '',
7+
until: '',
8+
path: '.',
9+
quotepath: true,
10+
diffRelative: true,
11+
sinceLastRemoteCommit: false,
12+
recoverDeletedFiles: false,
13+
recoverDeletedFilesToDestination: '',
14+
recoverFiles: '',
15+
recoverFilesSeparator: '\n',
16+
recoverFilesIgnore: '',
17+
recoverFilesIgnoreSeparator: '\n',
18+
includeAllOldNewRenamedFiles: false,
19+
oldNewSeparator: ',',
20+
oldNewFilesSeparator: ' ',
21+
skipInitialFetch: false,
22+
fetchAdditionalSubmoduleHistory: false,
23+
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false
24+
}

src/main.ts

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -256,12 +256,7 @@ export async function run(): Promise<void> {
256256
(!hasGitDirectory || inputs.useRestApi)
257257
) {
258258
core.info("Using GitHub's REST API to get changed files")
259-
if (process.env.GITHUB_ACTION_PATH) {
260-
await warnUnsupportedRESTAPIInputs({
261-
actionPath: path.join(process.env.GITHUB_ACTION_PATH, 'action.yml'),
262-
inputs
263-
})
264-
}
259+
await warnUnsupportedRESTAPIInputs({inputs})
265260
await getChangedFilesFromRESTAPI({
266261
inputs,
267262
filePatterns,

src/utils.ts

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,52 +1513,26 @@ export const hasLocalGitDirectory = async ({
15131513
/**
15141514
* Warns about unsupported inputs when using the REST API.
15151515
*
1516-
* @param actionPath - The path to the action file.
15171516
* @param inputs - The inputs object.
15181517
*/
15191518
export const warnUnsupportedRESTAPIInputs = async ({
1520-
actionPath,
15211519
inputs
15221520
}: {
1523-
actionPath: string
15241521
inputs: Inputs
15251522
}): Promise<void> => {
1526-
const actionContents = await fs.readFile(actionPath, 'utf8')
1527-
const actionYaml = parseDocument(actionContents, {schema: 'failsafe'})
1528-
1529-
if (actionYaml.errors.length > 0) {
1530-
throw new Error(
1531-
`YAML errors in ${actionPath}: ${actionYaml.errors.join(', ')}`
1532-
)
1533-
}
1534-
1535-
if (actionYaml.warnings.length > 0) {
1536-
throw new Error(
1537-
`YAML warnings in ${actionPath}: ${actionYaml.warnings.join(', ')}`
1538-
)
1539-
}
1540-
1541-
const action = actionYaml.toJS() as {
1542-
inputs: {
1543-
[key: string]: {description: string; required: boolean; default: string}
1544-
}
1545-
}
1546-
1547-
const actionInputs = action.inputs
1548-
1549-
for (const key of UNSUPPORTED_REST_API_INPUTS) {
1550-
const inputKey = snakeCase(key) as keyof Inputs
1551-
1523+
for (const key of Object.keys(UNSUPPORTED_REST_API_INPUTS)) {
15521524
const defaultValue = Object.hasOwnProperty.call(
1553-
actionInputs[inputKey],
1554-
'default'
1525+
UNSUPPORTED_REST_API_INPUTS,
1526+
key
15551527
)
1556-
? actionInputs[inputKey].default.toString()
1528+
? UNSUPPORTED_REST_API_INPUTS[key as keyof Inputs]?.toString()
15571529
: ''
15581530

1559-
if (defaultValue !== inputs[key]?.toString()) {
1531+
if (defaultValue !== inputs[key as keyof Inputs]?.toString()) {
15601532
core.warning(
1561-
`Input "${inputKey}" is not supported when using GitHub's REST API to get changed files`
1533+
`Input "${snakeCase(
1534+
key
1535+
)}" is not supported when using GitHub's REST API to get changed files`
15621536
)
15631537
}
15641538
}

0 commit comments

Comments
 (0)