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:
parent
79b060d445
commit
6c9dcea443
77
dist/index.js
generated
vendored
77
dist/index.js
generated
vendored
@ -1359,28 +1359,28 @@ exports.getSHAForPullRequestEvent = getSHAForPullRequestEvent;
|
|||||||
|
|
||||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||||
exports.UNSUPPORTED_REST_API_INPUTS = void 0;
|
exports.UNSUPPORTED_REST_API_INPUTS = void 0;
|
||||||
exports.UNSUPPORTED_REST_API_INPUTS = [
|
exports.UNSUPPORTED_REST_API_INPUTS = {
|
||||||
'sha',
|
sha: '',
|
||||||
'baseSha',
|
baseSha: '',
|
||||||
'since',
|
since: '',
|
||||||
'until',
|
until: '',
|
||||||
'path',
|
path: '.',
|
||||||
'quotepath',
|
quotepath: true,
|
||||||
'diffRelative',
|
diffRelative: true,
|
||||||
'sinceLastRemoteCommit',
|
sinceLastRemoteCommit: false,
|
||||||
'recoverDeletedFiles',
|
recoverDeletedFiles: false,
|
||||||
'recoverDeletedFilesToDestination',
|
recoverDeletedFilesToDestination: '',
|
||||||
'recoverFiles',
|
recoverFiles: '',
|
||||||
'recoverFilesSeparator',
|
recoverFilesSeparator: '\n',
|
||||||
'recoverFilesIgnore',
|
recoverFilesIgnore: '',
|
||||||
'recoverFilesIgnoreSeparator',
|
recoverFilesIgnoreSeparator: '\n',
|
||||||
'includeAllOldNewRenamedFiles',
|
includeAllOldNewRenamedFiles: false,
|
||||||
'oldNewSeparator',
|
oldNewSeparator: ',',
|
||||||
'oldNewFilesSeparator',
|
oldNewFilesSeparator: ' ',
|
||||||
'skipInitialFetch',
|
skipInitialFetch: false,
|
||||||
'fetchAdditionalSubmoduleHistory',
|
fetchAdditionalSubmoduleHistory: false,
|
||||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false
|
||||||
];
|
};
|
||||||
|
|
||||||
|
|
||||||
/***/ }),
|
/***/ }),
|
||||||
@ -1859,12 +1859,7 @@ function run() {
|
|||||||
((_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number) &&
|
((_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number) &&
|
||||||
(!hasGitDirectory || inputs.useRestApi)) {
|
(!hasGitDirectory || inputs.useRestApi)) {
|
||||||
core.info("Using GitHub's REST API to get changed files");
|
core.info("Using GitHub's REST API to get changed files");
|
||||||
if (process.env.GITHUB_ACTION_PATH) {
|
yield (0, utils_1.warnUnsupportedRESTAPIInputs)({ inputs });
|
||||||
yield (0, utils_1.warnUnsupportedRESTAPIInputs)({
|
|
||||||
actionPath: path_1.default.join(process.env.GITHUB_ACTION_PATH, 'action.yml'),
|
|
||||||
inputs
|
|
||||||
});
|
|
||||||
}
|
|
||||||
yield getChangedFilesFromRESTAPI({
|
yield getChangedFilesFromRESTAPI({
|
||||||
inputs,
|
inputs,
|
||||||
filePatterns,
|
filePatterns,
|
||||||
@ -2957,28 +2952,16 @@ exports.hasLocalGitDirectory = hasLocalGitDirectory;
|
|||||||
/**
|
/**
|
||||||
* Warns about unsupported inputs when using the REST API.
|
* Warns about unsupported inputs when using the REST API.
|
||||||
*
|
*
|
||||||
* @param actionPath - The path to the action file.
|
|
||||||
* @param inputs - The inputs object.
|
* @param inputs - The inputs object.
|
||||||
*/
|
*/
|
||||||
const warnUnsupportedRESTAPIInputs = ({ actionPath, inputs }) => __awaiter(void 0, void 0, void 0, function* () {
|
const warnUnsupportedRESTAPIInputs = ({ inputs }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
var _m;
|
var _m, _o;
|
||||||
const actionContents = yield fs_1.promises.readFile(actionPath, 'utf8');
|
for (const key of Object.keys(constant_1.UNSUPPORTED_REST_API_INPUTS)) {
|
||||||
const actionYaml = (0, yaml_1.parseDocument)(actionContents, { schema: 'failsafe' });
|
const defaultValue = Object.hasOwnProperty.call(constant_1.UNSUPPORTED_REST_API_INPUTS, key)
|
||||||
if (actionYaml.errors.length > 0) {
|
? (_m = constant_1.UNSUPPORTED_REST_API_INPUTS[key]) === null || _m === void 0 ? void 0 : _m.toString()
|
||||||
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();
|
|
||||||
const actionInputs = action.inputs;
|
|
||||||
for (const key of constant_1.UNSUPPORTED_REST_API_INPUTS) {
|
|
||||||
const inputKey = (0, lodash_1.snakeCase)(key);
|
|
||||||
const defaultValue = Object.hasOwnProperty.call(actionInputs[inputKey], 'default')
|
|
||||||
? actionInputs[inputKey].default.toString()
|
|
||||||
: '';
|
: '';
|
||||||
if (defaultValue !== ((_m = inputs[key]) === null || _m === void 0 ? void 0 : _m.toString())) {
|
if (defaultValue !== ((_o = inputs[key]) === null || _o === void 0 ? void 0 : _o.toString())) {
|
||||||
core.warning(`Input "${inputKey}" is not supported when using GitHub's REST API to get changed files`);
|
core.warning(`Input "${(0, lodash_1.snakeCase)(key)}" is not supported when using GitHub's REST API to get changed files`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -1,6 +1,4 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import {promises as fs} from 'fs'
|
|
||||||
import path from 'path'
|
|
||||||
import {ChangeTypeEnum} from '../changedFiles'
|
import {ChangeTypeEnum} from '../changedFiles'
|
||||||
import {Inputs} from '../inputs'
|
import {Inputs} from '../inputs'
|
||||||
import {
|
import {
|
||||||
@ -12,7 +10,6 @@ import {
|
|||||||
} from '../utils'
|
} from '../utils'
|
||||||
|
|
||||||
const originalPlatform = process.platform
|
const originalPlatform = process.platform
|
||||||
const ACTION_PATH = path.resolve(__dirname, '..', '..', 'action.yml')
|
|
||||||
|
|
||||||
function mockedPlatform(platform: string): void {
|
function mockedPlatform(platform: string): void {
|
||||||
Object.defineProperty(process, 'platform', {
|
Object.defineProperty(process, 'platform', {
|
||||||
@ -644,97 +641,14 @@ describe('utils test', () => {
|
|||||||
const coreWarningSpy = jest.spyOn(core, 'warning')
|
const coreWarningSpy = jest.spyOn(core, 'warning')
|
||||||
|
|
||||||
await warnUnsupportedRESTAPIInputs({
|
await warnUnsupportedRESTAPIInputs({
|
||||||
actionPath: ACTION_PATH,
|
|
||||||
inputs
|
inputs
|
||||||
})
|
})
|
||||||
|
|
||||||
expect(coreWarningSpy).toHaveBeenCalledWith(
|
expect(coreWarningSpy).toHaveBeenCalledWith(
|
||||||
'Input "sha" is not supported when using GitHub\'s REST API to get changed files'
|
'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.
|
expect(coreWarningSpy).toHaveBeenCalledTimes(1)
|
||||||
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:/
|
|
||||||
)
|
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
import {Inputs} from './inputs'
|
import {Inputs} from './inputs'
|
||||||
|
|
||||||
export const UNSUPPORTED_REST_API_INPUTS: (keyof Inputs)[] = [
|
export const UNSUPPORTED_REST_API_INPUTS: Partial<Inputs> = {
|
||||||
'sha',
|
sha: '',
|
||||||
'baseSha',
|
baseSha: '',
|
||||||
'since',
|
since: '',
|
||||||
'until',
|
until: '',
|
||||||
'path',
|
path: '.',
|
||||||
'quotepath',
|
quotepath: true,
|
||||||
'diffRelative',
|
diffRelative: true,
|
||||||
'sinceLastRemoteCommit',
|
sinceLastRemoteCommit: false,
|
||||||
'recoverDeletedFiles',
|
recoverDeletedFiles: false,
|
||||||
'recoverDeletedFilesToDestination',
|
recoverDeletedFilesToDestination: '',
|
||||||
'recoverFiles',
|
recoverFiles: '',
|
||||||
'recoverFilesSeparator',
|
recoverFilesSeparator: '\n',
|
||||||
'recoverFilesIgnore',
|
recoverFilesIgnore: '',
|
||||||
'recoverFilesIgnoreSeparator',
|
recoverFilesIgnoreSeparator: '\n',
|
||||||
'includeAllOldNewRenamedFiles',
|
includeAllOldNewRenamedFiles: false,
|
||||||
'oldNewSeparator',
|
oldNewSeparator: ',',
|
||||||
'oldNewFilesSeparator',
|
oldNewFilesSeparator: ' ',
|
||||||
'skipInitialFetch',
|
skipInitialFetch: false,
|
||||||
'fetchAdditionalSubmoduleHistory',
|
fetchAdditionalSubmoduleHistory: false,
|
||||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false
|
||||||
]
|
}
|
||||||
|
@ -256,12 +256,7 @@ export async function run(): Promise<void> {
|
|||||||
(!hasGitDirectory || inputs.useRestApi)
|
(!hasGitDirectory || inputs.useRestApi)
|
||||||
) {
|
) {
|
||||||
core.info("Using GitHub's REST API to get changed files")
|
core.info("Using GitHub's REST API to get changed files")
|
||||||
if (process.env.GITHUB_ACTION_PATH) {
|
await warnUnsupportedRESTAPIInputs({inputs})
|
||||||
await warnUnsupportedRESTAPIInputs({
|
|
||||||
actionPath: path.join(process.env.GITHUB_ACTION_PATH, 'action.yml'),
|
|
||||||
inputs
|
|
||||||
})
|
|
||||||
}
|
|
||||||
await getChangedFilesFromRESTAPI({
|
await getChangedFilesFromRESTAPI({
|
||||||
inputs,
|
inputs,
|
||||||
filePatterns,
|
filePatterns,
|
||||||
|
42
src/utils.ts
42
src/utils.ts
@ -1513,52 +1513,26 @@ export const hasLocalGitDirectory = async ({
|
|||||||
/**
|
/**
|
||||||
* Warns about unsupported inputs when using the REST API.
|
* Warns about unsupported inputs when using the REST API.
|
||||||
*
|
*
|
||||||
* @param actionPath - The path to the action file.
|
|
||||||
* @param inputs - The inputs object.
|
* @param inputs - The inputs object.
|
||||||
*/
|
*/
|
||||||
export const warnUnsupportedRESTAPIInputs = async ({
|
export const warnUnsupportedRESTAPIInputs = async ({
|
||||||
actionPath,
|
|
||||||
inputs
|
inputs
|
||||||
}: {
|
}: {
|
||||||
actionPath: string
|
|
||||||
inputs: Inputs
|
inputs: Inputs
|
||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
const actionContents = await fs.readFile(actionPath, 'utf8')
|
for (const key of Object.keys(UNSUPPORTED_REST_API_INPUTS)) {
|
||||||
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
|
|
||||||
|
|
||||||
const defaultValue = Object.hasOwnProperty.call(
|
const defaultValue = Object.hasOwnProperty.call(
|
||||||
actionInputs[inputKey],
|
UNSUPPORTED_REST_API_INPUTS,
|
||||||
'default'
|
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(
|
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`
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user