Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "test/demo"]
path = test/demo
url = git@github.com:tj-actions/demo.git
url = git@github.com:spartan322/demo.git
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,10 @@ inputs:
description: "Separator used to split the `recover_files_ignore` input"
default: "\n"
required: false
recurse_submodules:
description: "Recurse nested submodule changes"
required: false
default: "true"
token:
description: "GitHub token used to fetch changed files from Github's API."
required: false
Expand Down
245 changes: 162 additions & 83 deletions dist/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/__tests__/__snapshots__/inputs.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ exports[`getInputs should correctly parse boolean inputs 1`] = `
",
"recoverFilesSeparator": "
",
"recurseSubmodules": "false",
"safeOutput": "false",
"separator": "",
"sha": "",
Expand Down Expand Up @@ -112,6 +113,7 @@ exports[`getInputs should correctly parse numeric inputs 1`] = `
"recoverFilesIgnore": "",
"recoverFilesIgnoreSeparator": "",
"recoverFilesSeparator": "",
"recurseSubmodules": true,
"safeOutput": false,
"separator": "",
"sha": "",
Expand Down Expand Up @@ -174,6 +176,7 @@ exports[`getInputs should correctly parse string inputs 1`] = `
"recoverFilesIgnore": "",
"recoverFilesIgnoreSeparator": "",
"recoverFilesSeparator": "",
"recurseSubmodules": true,
"safeOutput": false,
"separator": "",
"sha": "",
Expand Down Expand Up @@ -238,6 +241,7 @@ exports[`getInputs should handle invalid numeric inputs correctly 1`] = `
"recoverFilesIgnore": "",
"recoverFilesIgnoreSeparator": "",
"recoverFilesSeparator": "",
"recurseSubmodules": true,
"safeOutput": false,
"separator": "",
"sha": "",
Expand Down Expand Up @@ -302,6 +306,7 @@ exports[`getInputs should handle negative numeric inputs correctly 1`] = `
"recoverFilesIgnore": "",
"recoverFilesIgnoreSeparator": "",
"recoverFilesSeparator": "",
"recurseSubmodules": true,
"safeOutput": false,
"separator": "",
"sha": "",
Expand Down Expand Up @@ -367,6 +372,7 @@ exports[`getInputs should return default values when no inputs are provided 1`]
",
"recoverFilesSeparator": "
",
"recurseSubmodules": true,
"safeOutput": false,
"separator": "",
"sha": "",
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/changedFiles.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ const baseInputs: Inputs = {
recoverFilesSeparator: '\n',
recoverFilesIgnore: '',
recoverFilesIgnoreSeparator: '\n',
recurseSubmodules: true,
token: 'fake-token',
apiUrl: 'https://api.github.com',
skipInitialFetch: false,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ jest.mock('../inputs', () => ({
recoverFilesSeparator: '\n',
recoverFilesIgnore: '',
recoverFilesIgnoreSeparator: '\n',
recurseSubmodules: true,
token: 'fake-token',
apiUrl: 'https://api.github.com',
skipInitialFetch: false,
Expand Down
1 change: 1 addition & 0 deletions src/__tests__/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,7 @@ describe('utils test', () => {
recoverFilesSeparator: '\n',
recoverFilesIgnore: '',
recoverFilesIgnoreSeparator: '\n',
recurseSubmodules: true,
token: '${{ github.token }}',
apiUrl: '${{ github.api_url }}',
skipInitialFetch: false,
Expand Down
180 changes: 129 additions & 51 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
getDirnameMaxDepth,
getDirNamesIncludeFilesPattern,
getFilteredChangedFiles,
getSubmodulePath,
gitRenamedFiles,
gitSubmoduleDiffSHA,
isSymlinkInGitTree,
Expand Down Expand Up @@ -214,6 +215,115 @@ export type ChangedFiles = {
[key in ChangeTypeEnum]: string[]
}

export const getAllSubmoduleDiffFiles = async ({
submodulePath,
workingDirectory,
previousSha,
currentSha,
diffType,
outputRenamedFilesAsDeletedAndAdded,
fetchAdditionalSubmoduleHistory,
failOnSubmoduleDiffError,
submoduleShas,
recurseSubmodules
}: {
submodulePath: string
workingDirectory: string
previousSha: string
currentSha: string
diffType: string
outputRenamedFilesAsDeletedAndAdded: boolean
fetchAdditionalSubmoduleHistory: boolean
failOnSubmoduleDiffError: boolean
submoduleShas?: Record<string, {previousSha?: string; currentSha?: string}>
recurseSubmodules: boolean
}): Promise<ChangedFiles> => {
const submoduleShaResult = await gitSubmoduleDiffSHA({
cwd: workingDirectory,
parentSha1: previousSha,
parentSha2: currentSha,
submodulePath,
diff: diffType
})

const submoduleWorkingDirectory = path.join(workingDirectory, submodulePath)

if (!(submoduleShaResult.currentSha && submoduleShaResult.previousSha)) {
return {
[ChangeTypeEnum.Added]: [],
[ChangeTypeEnum.Copied]: [],
[ChangeTypeEnum.Deleted]: [],
[ChangeTypeEnum.Modified]: [],
[ChangeTypeEnum.Renamed]: [],
[ChangeTypeEnum.TypeChanged]: [],
[ChangeTypeEnum.Unmerged]: [],
[ChangeTypeEnum.Unknown]: []
}
}

if (submoduleShas) {
submoduleShas[submodulePath] = submoduleShaResult
}
let diff = '...'

if (
!(await canDiffCommits({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff
}))
) {
let message = `Set 'fetch_additional_submodule_history: true' to fetch additional submodule history for: ${submodulePath}`
if (fetchAdditionalSubmoduleHistory) {
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`
}
core.warning(message)
diff = '..'
}

const files = await getAllChangedFiles({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff,
isSubmodule: true,
parentDir: submodulePath,
outputRenamedFilesAsDeletedAndAdded,
failOnSubmoduleDiffError
})

if (!recurseSubmodules) {
return files
}

for (const innerSubmodulePath of await getSubmodulePath({
cwd: submoduleWorkingDirectory
})) {
const submoduleFiles = await getAllSubmoduleDiffFiles({
submodulePath: innerSubmodulePath,
workingDirectory: submoduleWorkingDirectory,
previousSha: submoduleShaResult.previousSha,
currentSha: submoduleShaResult.currentSha,
diffType,
outputRenamedFilesAsDeletedAndAdded,
fetchAdditionalSubmoduleHistory,
failOnSubmoduleDiffError,
submoduleShas,
recurseSubmodules
})

for (const changeType of Object.keys(submoduleFiles) as ChangeTypeEnum[]) {
if (!files[changeType]) {
files[changeType] = []
}
files[changeType].push(...submoduleFiles[changeType])
}
}

return files
}

export const getAllDiffFiles = async ({
workingDirectory,
diffSubmodule,
Expand All @@ -223,7 +333,8 @@ export const getAllDiffFiles = async ({
fetchAdditionalSubmoduleHistory,
failOnInitialDiffError,
failOnSubmoduleDiffError,
submoduleShas
submoduleShas,
recurseSubmodules
}: {
workingDirectory: string
diffSubmodule: boolean
Expand All @@ -234,6 +345,7 @@ export const getAllDiffFiles = async ({
failOnInitialDiffError: boolean
failOnSubmoduleDiffError: boolean
submoduleShas?: Record<string, {previousSha?: string; currentSha?: string}>
recurseSubmodules: boolean
}): Promise<ChangedFiles> => {
const files = await getAllChangedFiles({
cwd: workingDirectory,
Expand All @@ -246,60 +358,26 @@ export const getAllDiffFiles = async ({

if (diffSubmodule) {
for (const submodulePath of submodulePaths) {
const submoduleShaResult = await gitSubmoduleDiffSHA({
cwd: workingDirectory,
parentSha1: diffResult.previousSha,
parentSha2: diffResult.currentSha,
const submoduleFiles = await getAllSubmoduleDiffFiles({
submodulePath,
diff: diffResult.diff
})

const submoduleWorkingDirectory = path.join(
workingDirectory,
submodulePath
)

if (submoduleShaResult.currentSha && submoduleShaResult.previousSha) {
if (submoduleShas) {
submoduleShas[submodulePath] = submoduleShaResult
}
let diff = '...'

if (
!(await canDiffCommits({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff
}))
) {
let message = `Set 'fetch_additional_submodule_history: true' to fetch additional submodule history for: ${submodulePath}`
if (fetchAdditionalSubmoduleHistory) {
message = `To fetch additional submodule history for: ${submodulePath} you can increase history depth using 'fetch_depth' input`
}
core.warning(message)
diff = '..'
}

const submoduleFiles = await getAllChangedFiles({
cwd: submoduleWorkingDirectory,
sha1: submoduleShaResult.previousSha,
sha2: submoduleShaResult.currentSha,
diff,
isSubmodule: true,
parentDir: submodulePath,
outputRenamedFilesAsDeletedAndAdded,
failOnSubmoduleDiffError
})
previousSha: diffResult.previousSha,
currentSha: diffResult.currentSha,
diffType: diffResult.diff,
outputRenamedFilesAsDeletedAndAdded,
fetchAdditionalSubmoduleHistory,
failOnSubmoduleDiffError,
submoduleShas,
recurseSubmodules
})

for (const changeType of Object.keys(
submoduleFiles
) as ChangeTypeEnum[]) {
if (!files[changeType]) {
files[changeType] = []
}
files[changeType].push(...submoduleFiles[changeType])
for (const changeType of Object.keys(
submoduleFiles
) as ChangeTypeEnum[]) {
if (!files[changeType]) {
files[changeType] = []
}
files[changeType].push(...submoduleFiles[changeType])
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export const DEFAULT_VALUES_OF_UNSUPPORTED_API_INPUTS: Partial<Inputs> = {
recoverFilesSeparator: '\n',
recoverFilesIgnore: '',
recoverFilesIgnoreSeparator: '\n',
recurseSubmodules: true,
includeAllOldNewRenamedFiles: false,
oldNewSeparator: ',',
oldNewFilesSeparator: ' ',
Expand Down
5 changes: 5 additions & 0 deletions src/inputs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ export type Inputs = {
recoverFilesSeparator: string
recoverFilesIgnore: string
recoverFilesIgnoreSeparator: string
recurseSubmodules: boolean
token: string
apiUrl: string
skipInitialFetch: boolean
Expand Down Expand Up @@ -206,6 +207,9 @@ export const getInputs = (): Inputs => {
trimWhitespace: false
}
)
const recurseSubmodules = core.getBooleanInput('recurse_submodules', {
required: false
})
const token = core.getInput('token', {required: false})
const apiUrl = core.getInput('api_url', {required: false})
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
Expand Down Expand Up @@ -313,6 +317,7 @@ export const getInputs = (): Inputs => {
recoverFilesSeparator,
recoverFilesIgnore,
recoverFilesIgnoreSeparator,
recurseSubmodules,
includeAllOldNewRenamedFiles,
oldNewSeparator,
oldNewFilesSeparator,
Expand Down
3 changes: 2 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ const getChangedFilesFromLocalGitHistory = async ({
fetchAdditionalSubmoduleHistory: inputs.fetchAdditionalSubmoduleHistory,
failOnInitialDiffError: inputs.failOnInitialDiffError,
failOnSubmoduleDiffError: inputs.failOnSubmoduleDiffError,
submoduleShas
submoduleShas,
recurseSubmodules: inputs.recurseSubmodules
})

if (inputs.excludeSymlinks) {
Expand Down
2 changes: 1 addition & 1 deletion test/demo
Submodule demo updated 2 files
+3 −0 .gitmodules
+1 −0 test/submoduleTest