feat: add option to exclude submodules when detecting changes (#2047)
Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
@@ -2,55 +2,58 @@
|
||||
|
||||
exports[`getInputs should correctly parse boolean inputs 1`] = `
|
||||
{
|
||||
"apiUrl": undefined,
|
||||
"baseSha": undefined,
|
||||
"apiUrl": "",
|
||||
"baseSha": "",
|
||||
"diffRelative": "false",
|
||||
"dirNames": "false",
|
||||
"dirNamesDeletedFilesIncludeOnlyDeletedDirs": "false",
|
||||
"dirNamesExcludeCurrentDir": "false",
|
||||
"dirNamesIncludeFiles": undefined,
|
||||
"dirNamesIncludeFilesSeparator": undefined,
|
||||
"dirNamesIncludeFiles": "",
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": "false",
|
||||
"failOnInitialDiffError": "false",
|
||||
"failOnSubmoduleDiffError": "false",
|
||||
"fetchAdditionalSubmoduleHistory": "false",
|
||||
"files": undefined,
|
||||
"filesFromSourceFile": undefined,
|
||||
"filesFromSourceFileSeparator": undefined,
|
||||
"filesIgnore": undefined,
|
||||
"filesIgnoreFromSourceFile": undefined,
|
||||
"filesIgnoreFromSourceFileSeparator": undefined,
|
||||
"filesIgnoreSeparator": undefined,
|
||||
"filesIgnoreYaml": undefined,
|
||||
"filesIgnoreYamlFromSourceFile": undefined,
|
||||
"filesIgnoreYamlFromSourceFileSeparator": undefined,
|
||||
"filesSeparator": undefined,
|
||||
"filesYaml": undefined,
|
||||
"filesYamlFromSourceFile": undefined,
|
||||
"filesYamlFromSourceFileSeparator": undefined,
|
||||
"files": "",
|
||||
"filesFromSourceFile": "",
|
||||
"filesFromSourceFileSeparator": "",
|
||||
"filesIgnore": "",
|
||||
"filesIgnoreFromSourceFile": "",
|
||||
"filesIgnoreFromSourceFileSeparator": "",
|
||||
"filesIgnoreSeparator": "",
|
||||
"filesIgnoreYaml": "",
|
||||
"filesIgnoreYamlFromSourceFile": "",
|
||||
"filesIgnoreYamlFromSourceFileSeparator": "",
|
||||
"filesSeparator": "",
|
||||
"filesYaml": "",
|
||||
"filesYamlFromSourceFile": "",
|
||||
"filesYamlFromSourceFileSeparator": "",
|
||||
"includeAllOldNewRenamedFiles": "false",
|
||||
"json": true,
|
||||
"negationPatternsFirst": "false",
|
||||
"oldNewFilesSeparator": undefined,
|
||||
"oldNewSeparator": undefined,
|
||||
"outputDir": undefined,
|
||||
"oldNewFilesSeparator": " ",
|
||||
"oldNewSeparator": ",",
|
||||
"outputDir": "",
|
||||
"outputRenamedFilesAsDeletedAndAdded": "false",
|
||||
"path": undefined,
|
||||
"path": ".",
|
||||
"quotepath": "false",
|
||||
"recoverDeletedFiles": "false",
|
||||
"recoverDeletedFilesToDestination": undefined,
|
||||
"recoverFiles": undefined,
|
||||
"recoverFilesIgnore": undefined,
|
||||
"recoverFilesIgnoreSeparator": undefined,
|
||||
"recoverFilesSeparator": undefined,
|
||||
"recoverDeletedFilesToDestination": "",
|
||||
"recoverFiles": "",
|
||||
"recoverFilesIgnore": "",
|
||||
"recoverFilesIgnoreSeparator": "
|
||||
",
|
||||
"recoverFilesSeparator": "
|
||||
",
|
||||
"safeOutput": "false",
|
||||
"separator": undefined,
|
||||
"sha": undefined,
|
||||
"since": undefined,
|
||||
"separator": "",
|
||||
"sha": "",
|
||||
"since": "",
|
||||
"sinceLastRemoteCommit": "false",
|
||||
"skipInitialFetch": "true",
|
||||
"token": undefined,
|
||||
"until": undefined,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"useRestApi": "false",
|
||||
"writeOutputFiles": "false",
|
||||
}
|
||||
@@ -68,6 +71,7 @@ exports[`getInputs should correctly parse numeric inputs 1`] = `
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"dirNamesMaxDepth": 2,
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": false,
|
||||
"failOnInitialDiffError": false,
|
||||
"failOnSubmoduleDiffError": false,
|
||||
"fetchAdditionalSubmoduleHistory": false,
|
||||
@@ -125,6 +129,7 @@ exports[`getInputs should correctly parse string inputs 1`] = `
|
||||
"dirNamesIncludeFiles": "",
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": false,
|
||||
"failOnInitialDiffError": false,
|
||||
"failOnSubmoduleDiffError": false,
|
||||
"fetchAdditionalSubmoduleHistory": false,
|
||||
@@ -182,6 +187,7 @@ exports[`getInputs should handle invalid numeric inputs correctly 1`] = `
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"dirNamesMaxDepth": 2,
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": false,
|
||||
"failOnInitialDiffError": false,
|
||||
"failOnSubmoduleDiffError": false,
|
||||
"fetchAdditionalSubmoduleHistory": false,
|
||||
@@ -240,6 +246,7 @@ exports[`getInputs should handle negative numeric inputs correctly 1`] = `
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"dirNamesMaxDepth": -2,
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": false,
|
||||
"failOnInitialDiffError": false,
|
||||
"failOnSubmoduleDiffError": false,
|
||||
"fetchAdditionalSubmoduleHistory": false,
|
||||
@@ -288,55 +295,58 @@ exports[`getInputs should handle negative numeric inputs correctly 1`] = `
|
||||
|
||||
exports[`getInputs should return default values when no inputs are provided 1`] = `
|
||||
{
|
||||
"apiUrl": undefined,
|
||||
"baseSha": undefined,
|
||||
"apiUrl": "",
|
||||
"baseSha": "",
|
||||
"diffRelative": true,
|
||||
"dirNames": false,
|
||||
"dirNamesDeletedFilesIncludeOnlyDeletedDirs": false,
|
||||
"dirNamesExcludeCurrentDir": false,
|
||||
"dirNamesIncludeFiles": undefined,
|
||||
"dirNamesIncludeFilesSeparator": undefined,
|
||||
"dirNamesIncludeFiles": "",
|
||||
"dirNamesIncludeFilesSeparator": "",
|
||||
"escapeJson": false,
|
||||
"excludeSubmodules": false,
|
||||
"failOnInitialDiffError": false,
|
||||
"failOnSubmoduleDiffError": false,
|
||||
"fetchAdditionalSubmoduleHistory": false,
|
||||
"files": undefined,
|
||||
"filesFromSourceFile": undefined,
|
||||
"filesFromSourceFileSeparator": undefined,
|
||||
"filesIgnore": undefined,
|
||||
"filesIgnoreFromSourceFile": undefined,
|
||||
"filesIgnoreFromSourceFileSeparator": undefined,
|
||||
"filesIgnoreSeparator": undefined,
|
||||
"filesIgnoreYaml": undefined,
|
||||
"filesIgnoreYamlFromSourceFile": undefined,
|
||||
"filesIgnoreYamlFromSourceFileSeparator": undefined,
|
||||
"filesSeparator": undefined,
|
||||
"filesYaml": undefined,
|
||||
"filesYamlFromSourceFile": undefined,
|
||||
"filesYamlFromSourceFileSeparator": undefined,
|
||||
"files": "",
|
||||
"filesFromSourceFile": "",
|
||||
"filesFromSourceFileSeparator": "",
|
||||
"filesIgnore": "",
|
||||
"filesIgnoreFromSourceFile": "",
|
||||
"filesIgnoreFromSourceFileSeparator": "",
|
||||
"filesIgnoreSeparator": "",
|
||||
"filesIgnoreYaml": "",
|
||||
"filesIgnoreYamlFromSourceFile": "",
|
||||
"filesIgnoreYamlFromSourceFileSeparator": "",
|
||||
"filesSeparator": "",
|
||||
"filesYaml": "",
|
||||
"filesYamlFromSourceFile": "",
|
||||
"filesYamlFromSourceFileSeparator": "",
|
||||
"includeAllOldNewRenamedFiles": false,
|
||||
"json": false,
|
||||
"negationPatternsFirst": false,
|
||||
"oldNewFilesSeparator": undefined,
|
||||
"oldNewSeparator": undefined,
|
||||
"outputDir": undefined,
|
||||
"oldNewFilesSeparator": " ",
|
||||
"oldNewSeparator": ",",
|
||||
"outputDir": "",
|
||||
"outputRenamedFilesAsDeletedAndAdded": false,
|
||||
"path": undefined,
|
||||
"path": ".",
|
||||
"quotepath": true,
|
||||
"recoverDeletedFiles": false,
|
||||
"recoverDeletedFilesToDestination": undefined,
|
||||
"recoverFiles": undefined,
|
||||
"recoverFilesIgnore": undefined,
|
||||
"recoverFilesIgnoreSeparator": undefined,
|
||||
"recoverFilesSeparator": undefined,
|
||||
"recoverDeletedFilesToDestination": "",
|
||||
"recoverFiles": "",
|
||||
"recoverFilesIgnore": "",
|
||||
"recoverFilesIgnoreSeparator": "
|
||||
",
|
||||
"recoverFilesSeparator": "
|
||||
",
|
||||
"safeOutput": false,
|
||||
"separator": undefined,
|
||||
"sha": undefined,
|
||||
"since": undefined,
|
||||
"separator": "",
|
||||
"sha": "",
|
||||
"since": "",
|
||||
"sinceLastRemoteCommit": false,
|
||||
"skipInitialFetch": false,
|
||||
"token": undefined,
|
||||
"until": undefined,
|
||||
"token": "",
|
||||
"until": "",
|
||||
"useRestApi": false,
|
||||
"writeOutputFiles": false,
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ describe('getInputs', () => {
|
||||
})
|
||||
|
||||
test('should return default values when no inputs are provided', () => {
|
||||
;(core.getBooleanInput as jest.Mock).mockImplementation(name => {
|
||||
;(core.getInput as jest.Mock).mockImplementation(name => {
|
||||
const camelCaseName = name.replace(/_([a-z])/g, (g: string[]) => {
|
||||
return g[1].toUpperCase()
|
||||
}) as keyof Inputs
|
||||
@@ -30,7 +30,7 @@ describe('getInputs', () => {
|
||||
})
|
||||
|
||||
test('should correctly parse boolean inputs', () => {
|
||||
;(core.getBooleanInput as jest.Mock).mockImplementation(name => {
|
||||
;(core.getInput as jest.Mock).mockImplementation(name => {
|
||||
const camelCaseName = name.replace(/_([a-z])/g, (g: string[]) => {
|
||||
return g[1].toUpperCase()
|
||||
}) as keyof Inputs
|
||||
|
||||
@@ -635,7 +635,8 @@ describe('utils test', () => {
|
||||
failOnInitialDiffError: false,
|
||||
failOnSubmoduleDiffError: false,
|
||||
negationPatternsFirst: false,
|
||||
useRestApi: false
|
||||
useRestApi: false,
|
||||
excludeSubmodules: false
|
||||
}
|
||||
|
||||
const coreWarningSpy = jest.spyOn(core, 'warning')
|
||||
|
||||
@@ -121,13 +121,13 @@ export const processChangedFiles = async ({
|
||||
export const getRenamedFiles = async ({
|
||||
inputs,
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
diffResult,
|
||||
submodulePaths
|
||||
}: {
|
||||
inputs: Inputs
|
||||
workingDirectory: string
|
||||
hasSubmodule: boolean
|
||||
diffSubmodule: boolean
|
||||
diffResult: DiffResult
|
||||
submodulePaths: string[]
|
||||
}): Promise<{paths: string; count: string}> => {
|
||||
@@ -139,7 +139,7 @@ export const getRenamedFiles = async ({
|
||||
oldNewSeparator: inputs.oldNewSeparator
|
||||
})
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (diffSubmodule) {
|
||||
for (const submodulePath of submodulePaths) {
|
||||
const submoduleShaResult = await gitSubmoduleDiffSHA({
|
||||
cwd: workingDirectory,
|
||||
@@ -217,7 +217,7 @@ export type ChangedFiles = {
|
||||
|
||||
export const getAllDiffFiles = async ({
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
diffResult,
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
@@ -226,7 +226,7 @@ export const getAllDiffFiles = async ({
|
||||
failOnSubmoduleDiffError
|
||||
}: {
|
||||
workingDirectory: string
|
||||
hasSubmodule: boolean
|
||||
diffSubmodule: boolean
|
||||
diffResult: DiffResult
|
||||
submodulePaths: string[]
|
||||
outputRenamedFilesAsDeletedAndAdded: boolean
|
||||
@@ -243,7 +243,7 @@ export const getAllDiffFiles = async ({
|
||||
failOnInitialDiffError
|
||||
})
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (diffSubmodule) {
|
||||
for (const submodulePath of submodulePaths) {
|
||||
const submoduleShaResult = await gitSubmoduleDiffSHA({
|
||||
cwd: workingDirectory,
|
||||
|
||||
@@ -91,7 +91,7 @@ interface SHAForNonPullRequestEvent {
|
||||
env: Env
|
||||
workingDirectory: string
|
||||
isShallow: boolean
|
||||
hasSubmodule: boolean
|
||||
diffSubmodule: boolean
|
||||
gitFetchExtraArgs: string[]
|
||||
isTag: boolean
|
||||
remoteName: string
|
||||
@@ -102,7 +102,7 @@ export const getSHAForNonPullRequestEvent = async ({
|
||||
env,
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
gitFetchExtraArgs,
|
||||
isTag,
|
||||
remoteName
|
||||
@@ -152,7 +152,7 @@ export const getSHAForNonPullRequestEvent = async ({
|
||||
})
|
||||
}
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (diffSubmodule) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@@ -164,7 +164,7 @@ export const getSHAForNonPullRequestEvent = async ({
|
||||
})
|
||||
}
|
||||
} else {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
if (diffSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@@ -323,7 +323,7 @@ interface SHAForPullRequestEvent {
|
||||
inputs: Inputs
|
||||
workingDirectory: string
|
||||
isShallow: boolean
|
||||
hasSubmodule: boolean
|
||||
diffSubmodule: boolean
|
||||
gitFetchExtraArgs: string[]
|
||||
remoteName: string
|
||||
}
|
||||
@@ -332,7 +332,7 @@ export const getSHAForPullRequestEvent = async ({
|
||||
inputs,
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
gitFetchExtraArgs,
|
||||
remoteName
|
||||
}: SHAForPullRequestEvent): Promise<DiffResult> => {
|
||||
@@ -390,7 +390,7 @@ export const getSHAForPullRequestEvent = async ({
|
||||
]
|
||||
})
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (diffSubmodule) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
@@ -403,7 +403,7 @@ export const getSHAForPullRequestEvent = async ({
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (hasSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
if (diffSubmodule && inputs.fetchAdditionalSubmoduleHistory) {
|
||||
await gitFetchSubmodules({
|
||||
cwd: workingDirectory,
|
||||
args: [
|
||||
|
||||
@@ -20,5 +20,6 @@ export const DEFAULT_VALUES_OF_UNSUPPORTED_API_INPUTS: Partial<Inputs> = {
|
||||
oldNewFilesSeparator: ' ',
|
||||
skipInitialFetch: false,
|
||||
fetchAdditionalSubmoduleHistory: false,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs: false,
|
||||
excludeSubmodules: false
|
||||
}
|
||||
|
||||
@@ -54,6 +54,7 @@ export type Inputs = {
|
||||
failOnSubmoduleDiffError: boolean
|
||||
negationPatternsFirst: boolean
|
||||
useRestApi: boolean
|
||||
excludeSubmodules: boolean
|
||||
}
|
||||
|
||||
export const getInputs = (): Inputs => {
|
||||
@@ -240,6 +241,10 @@ export const getInputs = (): Inputs => {
|
||||
required: false
|
||||
})
|
||||
|
||||
const excludeSubmodules = core.getBooleanInput('exclude_submodules', {
|
||||
required: false
|
||||
})
|
||||
|
||||
const inputs: Inputs = {
|
||||
files,
|
||||
filesSeparator,
|
||||
@@ -279,6 +284,7 @@ export const getInputs = (): Inputs => {
|
||||
skipInitialFetch,
|
||||
fetchAdditionalSubmoduleHistory,
|
||||
dirNamesDeletedFilesIncludeOnlyDeletedDirs,
|
||||
excludeSubmodules,
|
||||
// End Not Supported via REST API
|
||||
dirNames,
|
||||
dirNamesExcludeCurrentDir,
|
||||
|
||||
22
src/main.ts
22
src/main.ts
@@ -64,10 +64,16 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
}
|
||||
|
||||
const isShallow = await isRepoShallow({cwd: workingDirectory})
|
||||
const hasSubmodule = await submoduleExists({cwd: workingDirectory})
|
||||
let diffSubmodule = false
|
||||
let gitFetchExtraArgs = ['--no-tags', '--prune']
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (inputs.excludeSubmodules) {
|
||||
core.info('Excluding submodules from the diff')
|
||||
} else {
|
||||
diffSubmodule = await submoduleExists({cwd: workingDirectory})
|
||||
}
|
||||
|
||||
if (diffSubmodule) {
|
||||
gitFetchExtraArgs.push('--recurse-submodules')
|
||||
}
|
||||
|
||||
@@ -77,7 +83,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
inputs.outputRenamedFilesAsDeletedAndAdded
|
||||
let submodulePaths: string[] = []
|
||||
|
||||
if (hasSubmodule) {
|
||||
if (diffSubmodule) {
|
||||
submodulePaths = await getSubmodulePath({cwd: workingDirectory})
|
||||
}
|
||||
|
||||
@@ -94,7 +100,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
env,
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
gitFetchExtraArgs,
|
||||
isTag,
|
||||
remoteName
|
||||
@@ -109,7 +115,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
inputs,
|
||||
workingDirectory,
|
||||
isShallow,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
gitFetchExtraArgs,
|
||||
remoteName
|
||||
})
|
||||
@@ -127,7 +133,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
|
||||
const allDiffFiles = await getAllDiffFiles({
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
diffResult,
|
||||
submodulePaths,
|
||||
outputRenamedFilesAsDeletedAndAdded,
|
||||
@@ -153,7 +159,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
|
||||
recoverPatterns,
|
||||
diffResult,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
submodulePaths
|
||||
})
|
||||
}
|
||||
@@ -171,7 +177,7 @@ const getChangedFilesFromLocalGitHistory = async ({
|
||||
const allOldNewRenamedFiles = await getRenamedFiles({
|
||||
inputs,
|
||||
workingDirectory,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
diffResult,
|
||||
submodulePaths
|
||||
})
|
||||
|
||||
@@ -1413,7 +1413,7 @@ export const recoverDeletedFiles = async ({
|
||||
deletedFiles,
|
||||
recoverPatterns,
|
||||
diffResult,
|
||||
hasSubmodule,
|
||||
diffSubmodule,
|
||||
submodulePaths
|
||||
}: {
|
||||
inputs: Inputs
|
||||
@@ -1421,7 +1421,7 @@ export const recoverDeletedFiles = async ({
|
||||
deletedFiles: string[]
|
||||
recoverPatterns: string[]
|
||||
diffResult: DiffResult
|
||||
hasSubmodule: boolean
|
||||
diffSubmodule: boolean
|
||||
submodulePaths: string[]
|
||||
}): Promise<void> => {
|
||||
let recoverableDeletedFiles = deletedFiles
|
||||
@@ -1451,7 +1451,7 @@ export const recoverDeletedFiles = async ({
|
||||
|
||||
const submodulePath = submodulePaths.find(p => deletedFile.startsWith(p))
|
||||
|
||||
if (hasSubmodule && submodulePath) {
|
||||
if (diffSubmodule && submodulePath) {
|
||||
const submoduleShaResult = await gitSubmoduleDiffSHA({
|
||||
cwd: workingDirectory,
|
||||
parentSha1: diffResult.previousSha,
|
||||
|
||||
Reference in New Issue
Block a user