fix: bug with inaccurate warnings (#1853)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
parent
e0579abf95
commit
62f4729b5d
144
dist/index.js
generated
vendored
144
dist/index.js
generated
vendored
@ -157,7 +157,7 @@ const getRenamedFiles = ({ inputs, workingDirectory, hasSubmodule, diffResult, s
|
||||
diff
|
||||
}))) {
|
||||
let message = `Unable to use three dot diff for: ${submodulePath} submodule. Falling back to two dot diff. You can set 'fetch_additional_submodule_history: true' to fetch additional submodule history in order to use three dot diff`;
|
||||
if (inputs.fetchSubmoduleHistory) {
|
||||
if (inputs.fetchAdditionalSubmoduleHistory) {
|
||||
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`;
|
||||
}
|
||||
core.info(message);
|
||||
@ -199,7 +199,7 @@ var ChangeTypeEnum;
|
||||
ChangeTypeEnum["Unmerged"] = "U";
|
||||
ChangeTypeEnum["Unknown"] = "X";
|
||||
})(ChangeTypeEnum || (exports.ChangeTypeEnum = ChangeTypeEnum = {}));
|
||||
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths, outputRenamedFilesAsDeletedAndAdded, fetchSubmoduleHistory, failOnInitialDiffError, failOnSubmoduleDiffError }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodulePaths, outputRenamedFilesAsDeletedAndAdded, fetchAdditionalSubmoduleHistory, failOnInitialDiffError, failOnSubmoduleDiffError }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const files = yield (0, utils_1.getAllChangedFiles)({
|
||||
cwd: workingDirectory,
|
||||
sha1: diffResult.previousSha,
|
||||
@ -227,7 +227,7 @@ const getAllDiffFiles = ({ workingDirectory, hasSubmodule, diffResult, submodule
|
||||
diff
|
||||
}))) {
|
||||
let message = `Set 'fetch_additional_submodule_history: true' to fetch additional submodule history for: ${submodulePath}`;
|
||||
if (fetchSubmoduleHistory) {
|
||||
if (fetchAdditionalSubmoduleHistory) {
|
||||
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`;
|
||||
}
|
||||
core.warning(message);
|
||||
@ -981,7 +981,7 @@ const getSHAForNonPullRequestEvent = (inputs, env, workingDirectory, isShallow,
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hasSubmodule && inputs.fetchSubmoduleHistory) {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
yield (0, utils_1.gitFetchSubmodules)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@ -1170,7 +1170,7 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (hasSubmodule && inputs.fetchSubmoduleHistory) {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
yield (0, utils_1.gitFetchSubmodules)({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@ -1350,6 +1350,39 @@ const getSHAForPullRequestEvent = (inputs, env, workingDirectory, isShallow, has
|
||||
exports.getSHAForPullRequestEvent = getSHAForPullRequestEvent;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 2363:
|
||||
/***/ ((__unused_webpack_module, exports) => {
|
||||
|
||||
"use strict";
|
||||
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.UNSUPPORTED_REST_API_INPUTS = void 0;
|
||||
exports.UNSUPPORTED_REST_API_INPUTS = [
|
||||
'sha',
|
||||
'baseSha',
|
||||
'since',
|
||||
'until',
|
||||
'path',
|
||||
'quotepath',
|
||||
'diffRelative',
|
||||
'sinceLastRemoteCommit',
|
||||
'recoverDeletedFiles',
|
||||
'recoverDeletedFilesToDestination',
|
||||
'recoverFiles',
|
||||
'recoverFilesSeparator',
|
||||
'recoverFilesIgnore',
|
||||
'recoverFilesIgnoreSeparator',
|
||||
'includeAllOldNewRenamedFiles',
|
||||
'oldNewSeparator',
|
||||
'oldNewFilesSeparator',
|
||||
'skipInitialFetch',
|
||||
'fetchAdditionalSubmoduleHistory',
|
||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
||||
];
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 9763:
|
||||
@ -1491,7 +1524,7 @@ const getInputs = () => {
|
||||
const since = core.getInput('since', { required: false });
|
||||
const until = core.getInput('until', { required: false });
|
||||
const path = core.getInput('path', { required: false });
|
||||
const quotePath = core.getBooleanInput('quotepath', { required: false });
|
||||
const quotepath = core.getBooleanInput('quotepath', { required: false });
|
||||
const diffRelative = core.getBooleanInput('diff_relative', { required: false });
|
||||
const dirNames = core.getBooleanInput('dir_names', { required: false });
|
||||
const dirNamesMaxDepth = core.getInput('dir_names_max_depth', {
|
||||
@ -1538,7 +1571,7 @@ const getInputs = () => {
|
||||
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
|
||||
required: false
|
||||
});
|
||||
const fetchSubmoduleHistory = core.getBooleanInput('fetch_additional_submodule_history', {
|
||||
const fetchAdditionalSubmoduleHistory = core.getBooleanInput('fetch_additional_submodule_history', {
|
||||
required: false
|
||||
});
|
||||
const failOnInitialDiffError = core.getBooleanInput('fail_on_initial_diff_error', {
|
||||
@ -1580,7 +1613,7 @@ const getInputs = () => {
|
||||
since,
|
||||
until,
|
||||
path,
|
||||
quotePath,
|
||||
quotepath,
|
||||
diffRelative,
|
||||
sinceLastRemoteCommit,
|
||||
recoverDeletedFiles,
|
||||
@ -1593,7 +1626,7 @@ const getInputs = () => {
|
||||
oldNewSeparator,
|
||||
oldNewFilesSeparator,
|
||||
skipInitialFetch,
|
||||
fetchSubmoduleHistory,
|
||||
fetchAdditionalSubmoduleHistory,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
@ -1677,13 +1710,13 @@ const utils_1 = __nccwpck_require__(918);
|
||||
const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _a, _b, _c;
|
||||
yield (0, utils_1.verifyMinimumGitVersion)();
|
||||
let quotePathValue = 'on';
|
||||
if (!inputs.quotePath) {
|
||||
quotePathValue = 'off';
|
||||
let quotepathValue = 'on';
|
||||
if (!inputs.quotepath) {
|
||||
quotepathValue = 'off';
|
||||
}
|
||||
yield (0, utils_1.updateGitGlobalConfig)({
|
||||
name: 'core.quotepath',
|
||||
value: quotePathValue
|
||||
value: quotepathValue
|
||||
});
|
||||
if (inputs.diffRelative) {
|
||||
yield (0, utils_1.updateGitGlobalConfig)({
|
||||
@ -1724,7 +1757,7 @@ const getChangedFilesFromLocalGitHistory = ({ inputs, env, workingDirectory, fil
|
||||
diffResult,
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory,
|
||||
fetchAdditionalSubmoduleHistory: inputs.fetchAdditionalSubmoduleHistory,
|
||||
failOnInitialDiffError: inputs.failOnInitialDiffError,
|
||||
failOnSubmoduleDiffError: inputs.failOnSubmoduleDiffError
|
||||
});
|
||||
@ -1826,32 +1859,11 @@ function run() {
|
||||
((_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.number) &&
|
||||
(!hasGitDirectory || inputs.useRestApi)) {
|
||||
core.info("Using GitHub's REST API to get changed files");
|
||||
const unsupportedInputs = [
|
||||
'sha',
|
||||
'baseSha',
|
||||
'since',
|
||||
'until',
|
||||
'path',
|
||||
'quotePath',
|
||||
'diffRelative',
|
||||
'sinceLastRemoteCommit',
|
||||
'recoverDeletedFiles',
|
||||
'recoverDeletedFilesToDestination',
|
||||
'recoverFiles',
|
||||
'recoverFilesSeparator',
|
||||
'recoverFilesIgnore',
|
||||
'recoverFilesIgnoreSeparator',
|
||||
'includeAllOldNewRenamedFiles',
|
||||
'oldNewSeparator',
|
||||
'oldNewFilesSeparator',
|
||||
'skipInitialFetch',
|
||||
'fetchSubmoduleHistory',
|
||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
||||
];
|
||||
for (const input of unsupportedInputs) {
|
||||
if (inputs[input]) {
|
||||
core.warning(`Input "${input}" is not supported when using GitHub's REST API to get changed files`);
|
||||
}
|
||||
if (process.env.GITHUB_ACTION_PATH) {
|
||||
yield (0, utils_1.warnUnsupportedRESTAPIInputs)({
|
||||
actionPath: process.env.GITHUB_ACTION_PATH,
|
||||
inputs
|
||||
});
|
||||
}
|
||||
yield getChangedFilesFromRESTAPI({
|
||||
inputs,
|
||||
@ -1949,19 +1961,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", ({ value: true }));
|
||||
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.setArrayOutput = exports.getOutputKey = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.getDirNamesIncludeFilesPattern = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.cleanShaInput = exports.verifyCommitSha = exports.getParentSha = exports.getCurrentBranchName = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.exists = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
||||
exports.warnUnsupportedRESTAPIInputs = exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.setArrayOutput = exports.getOutputKey = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.getDirNamesIncludeFilesPattern = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.cleanShaInput = exports.verifyCommitSha = exports.getParentSha = exports.getCurrentBranchName = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.exists = exports.verifyMinimumGitVersion = exports.getDirname = exports.normalizeSeparators = exports.isWindows = void 0;
|
||||
/*global AsyncIterableIterator*/
|
||||
const core = __importStar(__nccwpck_require__(2186));
|
||||
const exec = __importStar(__nccwpck_require__(1514));
|
||||
const github = __importStar(__nccwpck_require__(5438));
|
||||
const fs_1 = __nccwpck_require__(7147);
|
||||
const promises_1 = __nccwpck_require__(3292);
|
||||
const lodash_1 = __nccwpck_require__(250);
|
||||
const micromatch_1 = __importDefault(__nccwpck_require__(6228));
|
||||
const path = __importStar(__nccwpck_require__(1017));
|
||||
const readline_1 = __nccwpck_require__(4521);
|
||||
const yaml_1 = __nccwpck_require__(4083);
|
||||
const changedFiles_1 = __nccwpck_require__(7358);
|
||||
const constant_1 = __nccwpck_require__(2363);
|
||||
const MINIMUM_GIT_VERSION = '2.18.0';
|
||||
const isWindows = () => {
|
||||
return process.platform === 'win32';
|
||||
@ -2202,6 +2214,7 @@ exports.submoduleExists = submoduleExists;
|
||||
* Fetches the git repository
|
||||
* @param args - arguments for fetch command
|
||||
* @param cwd - working directory
|
||||
* @returns exit code
|
||||
*/
|
||||
const gitFetch = ({ args, cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { exitCode } = yield exec.getExecOutput('git', ['fetch', '-q', ...args], {
|
||||
@ -2232,6 +2245,7 @@ exports.gitFetchSubmodules = gitFetchSubmodules;
|
||||
/**
|
||||
* Retrieves all the submodule paths
|
||||
* @param cwd - working directory
|
||||
* @returns submodule paths
|
||||
*/
|
||||
const getSubmodulePath = ({ cwd }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
const { exitCode, stdout, stderr } = yield exec.getExecOutput('git', ['submodule', 'status'], {
|
||||
@ -2256,6 +2270,7 @@ exports.getSubmodulePath = getSubmodulePath;
|
||||
* @param parentSha2 - parent commit sha
|
||||
* @param submodulePath - path of submodule
|
||||
* @param diff - diff type between parent commits (`..` or `...`)
|
||||
* @returns commit sha of submodule
|
||||
*/
|
||||
const gitSubmoduleDiffSHA = ({ cwd, parentSha1, parentSha2, submodulePath, diff }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _h, _j, _k, _l;
|
||||
@ -2697,7 +2712,7 @@ const getYamlFilePatternsFromContents = ({ content = '', filePath = '', excluded
|
||||
core.error(`File does not exist: ${filePath}`);
|
||||
throw new Error(`File does not exist: ${filePath}`);
|
||||
}
|
||||
source = yield (0, promises_1.readFile)(filePath, 'utf8');
|
||||
source = yield fs_1.promises.readFile(filePath, 'utf8');
|
||||
}
|
||||
else {
|
||||
source = content;
|
||||
@ -2927,12 +2942,47 @@ const recoverDeletedFiles = ({ inputs, workingDirectory, deletedFiles, recoverPa
|
||||
}
|
||||
});
|
||||
exports.recoverDeletedFiles = recoverDeletedFiles;
|
||||
/**
|
||||
* Determines whether the specified working directory has a local Git directory.
|
||||
*
|
||||
* @param workingDirectory - The path of the working directory.
|
||||
* @returns A boolean value indicating whether the working directory has a local Git directory.
|
||||
*/
|
||||
const hasLocalGitDirectory = ({ workingDirectory }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
return yield (0, exports.isInsideWorkTree)({
|
||||
cwd: workingDirectory
|
||||
});
|
||||
});
|
||||
exports.hasLocalGitDirectory = hasLocalGitDirectory;
|
||||
/**
|
||||
* Warns about unsupported inputs when using the REST API.
|
||||
*
|
||||
* @param actionPath - The path to the action file.
|
||||
* @param inputs - The inputs object.
|
||||
*/
|
||||
const warnUnsupportedRESTAPIInputs = ({ actionPath, inputs }) => __awaiter(void 0, void 0, void 0, function* () {
|
||||
var _m;
|
||||
const actionContents = yield fs_1.promises.readFile(actionPath, 'utf8');
|
||||
const actionYaml = (0, yaml_1.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();
|
||||
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())) {
|
||||
core.warning(`Input "${inputKey}" is not supported when using GitHub's REST API to get changed files`);
|
||||
}
|
||||
}
|
||||
});
|
||||
exports.warnUnsupportedRESTAPIInputs = warnUnsupportedRESTAPIInputs;
|
||||
|
||||
|
||||
/***/ }),
|
||||
@ -54886,14 +54936,6 @@ module.exports = require("fs");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3292:
|
||||
/***/ ((module) => {
|
||||
|
||||
"use strict";
|
||||
module.exports = require("fs/promises");
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 3685:
|
||||
/***/ ((module) => {
|
||||
|
||||
|
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,12 +1,18 @@
|
||||
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 {
|
||||
getDirname,
|
||||
getDirnameMaxDepth,
|
||||
getFilteredChangedFiles,
|
||||
normalizeSeparators
|
||||
normalizeSeparators,
|
||||
warnUnsupportedRESTAPIInputs
|
||||
} from '../utils'
|
||||
|
||||
const originalPlatform = process.platform
|
||||
const ACTION_PATH = path.resolve(__dirname, '..', '..', 'action.yml')
|
||||
|
||||
function mockedPlatform(platform: string): void {
|
||||
Object.defineProperty(process, 'platform', {
|
||||
@ -575,4 +581,160 @@ describe('utils test', () => {
|
||||
expect(filteredFiles[ChangeTypeEnum.Modified]).toEqual([])
|
||||
})
|
||||
})
|
||||
|
||||
describe('warnUnsupportedRESTAPIInputs', () => {
|
||||
// Warns about unsupported inputs when using the REST API.
|
||||
it('should warn about unsupported inputs when all inputs are supported', async () => {
|
||||
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
|
||||
}
|
||||
|
||||
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:/
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
@ -166,7 +166,7 @@ export const getRenamedFiles = async ({
|
||||
}))
|
||||
) {
|
||||
let message = `Unable to use three dot diff for: ${submodulePath} submodule. Falling back to two dot diff. You can set 'fetch_additional_submodule_history: true' to fetch additional submodule history in order to use three dot diff`
|
||||
if (inputs.fetchSubmoduleHistory) {
|
||||
if (inputs.fetchAdditionalSubmoduleHistory) {
|
||||
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`
|
||||
}
|
||||
core.info(message)
|
||||
@ -221,7 +221,7 @@ export const getAllDiffFiles = async ({
|
||||
diffResult,
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
fetchSubmoduleHistory,
|
||||
fetchAdditionalSubmoduleHistory,
|
||||
failOnInitialDiffError,
|
||||
failOnSubmoduleDiffError
|
||||
}: {
|
||||
@ -230,7 +230,7 @@ export const getAllDiffFiles = async ({
|
||||
diffResult: DiffResult
|
||||
submodulePaths: string[]
|
||||
outputRenamedFilesAsDeletedAndAdded: boolean
|
||||
fetchSubmoduleHistory: boolean
|
||||
fetchAdditionalSubmoduleHistory: boolean
|
||||
failOnInitialDiffError: boolean
|
||||
failOnSubmoduleDiffError: boolean
|
||||
}): Promise<ChangedFiles> => {
|
||||
@ -270,7 +270,7 @@ export const getAllDiffFiles = async ({
|
||||
}))
|
||||
) {
|
||||
let message = `Set 'fetch_additional_submodule_history: true' to fetch additional submodule history for: ${submodulePath}`
|
||||
if (fetchSubmoduleHistory) {
|
||||
if (fetchAdditionalSubmoduleHistory) {
|
||||
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`
|
||||
}
|
||||
core.warning(message)
|
||||
|
@ -152,7 +152,7 @@ export const getSHAForNonPullRequestEvent = async (
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (hasSubmodule && inputs.fetchSubmoduleHistory) {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@ -382,7 +382,7 @@ export const getSHAForPullRequestEvent = async (
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasSubmodule && inputs.fetchSubmoduleHistory) {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
|
24
src/constant.ts
Normal file
24
src/constant.ts
Normal file
@ -0,0 +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'
|
||||
]
|
@ -24,7 +24,7 @@ export type Inputs = {
|
||||
since: string
|
||||
until: string
|
||||
path: string
|
||||
quotePath: boolean
|
||||
quotepath: boolean
|
||||
diffRelative: boolean
|
||||
dirNames: boolean
|
||||
dirNamesMaxDepth?: number
|
||||
@ -36,7 +36,7 @@ export type Inputs = {
|
||||
escapeJson: boolean
|
||||
safeOutput: boolean
|
||||
fetchDepth?: number
|
||||
fetchSubmoduleHistory: boolean
|
||||
fetchAdditionalSubmoduleHistory: boolean
|
||||
sinceLastRemoteCommit: boolean
|
||||
writeOutputFiles: boolean
|
||||
outputDir: string
|
||||
@ -132,7 +132,7 @@ export const getInputs = (): Inputs => {
|
||||
const since = core.getInput('since', {required: false})
|
||||
const until = core.getInput('until', {required: false})
|
||||
const path = core.getInput('path', {required: false})
|
||||
const quotePath = core.getBooleanInput('quotepath', {required: false})
|
||||
const quotepath = core.getBooleanInput('quotepath', {required: false})
|
||||
const diffRelative = core.getBooleanInput('diff_relative', {required: false})
|
||||
const dirNames = core.getBooleanInput('dir_names', {required: false})
|
||||
const dirNamesMaxDepth = core.getInput('dir_names_max_depth', {
|
||||
@ -197,7 +197,7 @@ export const getInputs = (): Inputs => {
|
||||
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
|
||||
required: false
|
||||
})
|
||||
const fetchSubmoduleHistory = core.getBooleanInput(
|
||||
const fetchAdditionalSubmoduleHistory = core.getBooleanInput(
|
||||
'fetch_additional_submodule_history',
|
||||
{
|
||||
required: false
|
||||
@ -257,7 +257,7 @@ export const getInputs = (): Inputs => {
|
||||
since,
|
||||
until,
|
||||
path,
|
||||
quotePath,
|
||||
quotepath,
|
||||
diffRelative,
|
||||
sinceLastRemoteCommit,
|
||||
recoverDeletedFiles,
|
||||
@ -270,7 +270,7 @@ export const getInputs = (): Inputs => {
|
||||
oldNewSeparator,
|
||||
oldNewFilesSeparator,
|
||||
skipInitialFetch,
|
||||
fetchSubmoduleHistory,
|
||||
fetchAdditionalSubmoduleHistory,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
|
47
src/main.ts
47
src/main.ts
@ -26,7 +26,8 @@ import {
|
||||
setOutput,
|
||||
submoduleExists,
|
||||
updateGitGlobalConfig,
|
||||
verifyMinimumGitVersion
|
||||
verifyMinimumGitVersion,
|
||||
warnUnsupportedRESTAPIInputs
|
||||
} from './utils'
|
||||
|
||||
const getChangedFilesFromLocalGitHistory = async ({
|
||||
@ -44,15 +45,15 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
}): Promise<void> => {
|
||||
await verifyMinimumGitVersion()
|
||||
|
||||
let quotePathValue = 'on'
|
||||
let quotepathValue = 'on'
|
||||
|
||||
if (!inputs.quotePath) {
|
||||
quotePathValue = 'off'
|
||||
if (!inputs.quotepath) {
|
||||
quotepathValue = 'off'
|
||||
}
|
||||
|
||||
await updateGitGlobalConfig({
|
||||
name: 'core.quotepath',
|
||||
value: quotePathValue
|
||||
value: quotepathValue
|
||||
})
|
||||
|
||||
if (inputs.diffRelative) {
|
||||
@ -123,7 +124,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
diffResult,
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
fetchSubmoduleHistory: inputs.fetchSubmoduleHistory,
|
||||
fetchAdditionalSubmoduleHistory: inputs.fetchAdditionalSubmoduleHistory,
|
||||
failOnInitialDiffError: inputs.failOnInitialDiffError,
|
||||
failOnSubmoduleDiffError: inputs.failOnSubmoduleDiffError
|
||||
})
|
||||
@ -255,35 +256,11 @@ export async function run(): Promise<void> {
|
||||
(!hasGitDirectory || inputs.useRestApi)
|
||||
) {
|
||||
core.info("Using GitHub's REST API to get changed files")
|
||||
const unsupportedInputs: (keyof Inputs)[] = [
|
||||
'sha',
|
||||
'baseSha',
|
||||
'since',
|
||||
'until',
|
||||
'path',
|
||||
'quotePath',
|
||||
'diffRelative',
|
||||
'sinceLastRemoteCommit',
|
||||
'recoverDeletedFiles',
|
||||
'recoverDeletedFilesToDestination',
|
||||
'recoverFiles',
|
||||
'recoverFilesSeparator',
|
||||
'recoverFilesIgnore',
|
||||
'recoverFilesIgnoreSeparator',
|
||||
'includeAllOldNewRenamedFiles',
|
||||
'oldNewSeparator',
|
||||
'oldNewFilesSeparator',
|
||||
'skipInitialFetch',
|
||||
'fetchSubmoduleHistory',
|
||||
'dirNamesDeletedFilesIncludeOnlyDeletedDirs'
|
||||
]
|
||||
|
||||
for (const input of unsupportedInputs) {
|
||||
if (inputs[input]) {
|
||||
core.warning(
|
||||
`Input "${input}" is not supported when using GitHub's REST API to get changed files`
|
||||
)
|
||||
}
|
||||
if (process.env.GITHUB_ACTION_PATH) {
|
||||
await warnUnsupportedRESTAPIInputs({
|
||||
actionPath: process.env.GITHUB_ACTION_PATH,
|
||||
inputs
|
||||
})
|
||||
}
|
||||
await getChangedFilesFromRESTAPI({
|
||||
inputs,
|
||||
|
69
src/utils.ts
69
src/utils.ts
@ -3,14 +3,14 @@ import * as core from '@actions/core'
|
||||
import * as exec from '@actions/exec'
|
||||
import * as github from '@actions/github'
|
||||
import {createReadStream, promises as fs} from 'fs'
|
||||
import {readFile} from 'fs/promises'
|
||||
import {flattenDeep} from 'lodash'
|
||||
import {flattenDeep, snakeCase} from 'lodash'
|
||||
import mm from 'micromatch'
|
||||
import * as path from 'path'
|
||||
import {createInterface} from 'readline'
|
||||
import {parseDocument} from 'yaml'
|
||||
import {ChangedFiles, ChangeTypeEnum} from './changedFiles'
|
||||
import {DiffResult} from './commitSha'
|
||||
import {UNSUPPORTED_REST_API_INPUTS} from './constant'
|
||||
import {Inputs} from './inputs'
|
||||
|
||||
const MINIMUM_GIT_VERSION = '2.18.0'
|
||||
@ -285,6 +285,7 @@ export const submoduleExists = async ({
|
||||
* Fetches the git repository
|
||||
* @param args - arguments for fetch command
|
||||
* @param cwd - working directory
|
||||
* @returns exit code
|
||||
*/
|
||||
export const gitFetch = async ({
|
||||
args,
|
||||
@ -333,6 +334,7 @@ export const gitFetchSubmodules = async ({
|
||||
/**
|
||||
* Retrieves all the submodule paths
|
||||
* @param cwd - working directory
|
||||
* @returns submodule paths
|
||||
*/
|
||||
export const getSubmodulePath = async ({
|
||||
cwd
|
||||
@ -367,6 +369,7 @@ export const getSubmodulePath = async ({
|
||||
* @param parentSha2 - parent commit sha
|
||||
* @param submodulePath - path of submodule
|
||||
* @param diff - diff type between parent commits (`..` or `...`)
|
||||
* @returns commit sha of submodule
|
||||
*/
|
||||
export const gitSubmoduleDiffSHA = async ({
|
||||
cwd,
|
||||
@ -1128,7 +1131,7 @@ const getYamlFilePatternsFromContents = async ({
|
||||
throw new Error(`File does not exist: ${filePath}`)
|
||||
}
|
||||
|
||||
source = await readFile(filePath, 'utf8')
|
||||
source = await fs.readFile(filePath, 'utf8')
|
||||
} else {
|
||||
source = content
|
||||
}
|
||||
@ -1491,6 +1494,12 @@ export const recoverDeletedFiles = async ({
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether the specified working directory has a local Git directory.
|
||||
*
|
||||
* @param workingDirectory - The path of the working directory.
|
||||
* @returns A boolean value indicating whether the working directory has a local Git directory.
|
||||
*/
|
||||
export const hasLocalGitDirectory = async ({
|
||||
workingDirectory
|
||||
}: {
|
||||
@ -1500,3 +1509,57 @@ export const hasLocalGitDirectory = async ({
|
||||
cwd: workingDirectory
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
|
||||
const defaultValue = Object.hasOwnProperty.call(
|
||||
actionInputs[inputKey],
|
||||
'default'
|
||||
)
|
||||
? actionInputs[inputKey].default.toString()
|
||||
: ''
|
||||
|
||||
if (defaultValue !== inputs[key]?.toString()) {
|
||||
core.warning(
|
||||
`Input "${inputKey}" is not supported when using GitHub's REST API to get changed files`
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user