2023-05-25 18:22:24 +00:00
|
|
|
import * as core from '@actions/core'
|
|
|
|
import path from 'path'
|
|
|
|
import {
|
2023-06-14 18:45:32 +00:00
|
|
|
getAllChangeTypeFiles,
|
|
|
|
getAllDiffFiles,
|
|
|
|
getChangeTypeFiles,
|
|
|
|
getRenamedFiles,
|
|
|
|
ChangeTypeEnum
|
|
|
|
} from './changedFiles'
|
|
|
|
import {
|
|
|
|
DiffResult,
|
2023-05-25 18:22:24 +00:00
|
|
|
getSHAForPullRequestEvent,
|
2023-06-14 18:45:32 +00:00
|
|
|
getSHAForPushEvent
|
2023-05-25 18:22:24 +00:00
|
|
|
} from './commitSha'
|
|
|
|
import {getEnv} from './env'
|
|
|
|
import {getInputs} from './inputs'
|
|
|
|
import {
|
|
|
|
getFilePatterns,
|
2023-06-14 18:45:32 +00:00
|
|
|
getFilteredChangedFiles,
|
2023-05-25 18:22:24 +00:00
|
|
|
getSubmodulePath,
|
|
|
|
isRepoShallow,
|
|
|
|
setOutput,
|
|
|
|
submoduleExists,
|
|
|
|
updateGitGlobalConfig,
|
|
|
|
verifyMinimumGitVersion
|
|
|
|
} from './utils'
|
|
|
|
|
|
|
|
export async function run(): Promise<void> {
|
|
|
|
core.startGroup('changed-files')
|
|
|
|
|
|
|
|
const env = await getEnv()
|
|
|
|
core.debug(`Env: ${JSON.stringify(env, null, 2)}`)
|
|
|
|
const inputs = getInputs()
|
|
|
|
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
|
|
|
|
|
|
|
|
await verifyMinimumGitVersion()
|
|
|
|
|
|
|
|
let quotePathValue = 'on'
|
|
|
|
|
|
|
|
if (!inputs.quotePath) {
|
|
|
|
quotePathValue = 'off'
|
|
|
|
}
|
|
|
|
|
|
|
|
await updateGitGlobalConfig({
|
|
|
|
name: 'core.quotepath',
|
|
|
|
value: quotePathValue
|
|
|
|
})
|
|
|
|
|
|
|
|
if (inputs.diffRelative) {
|
|
|
|
await updateGitGlobalConfig({
|
|
|
|
name: 'diff.relative',
|
|
|
|
value: 'true'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
const workingDirectory = path.resolve(
|
|
|
|
env.GITHUB_WORKSPACE || process.cwd(),
|
|
|
|
inputs.path
|
|
|
|
)
|
|
|
|
const isShallow = await isRepoShallow({cwd: workingDirectory})
|
|
|
|
const hasSubmodule = await submoduleExists({cwd: workingDirectory})
|
2023-06-14 19:22:47 +00:00
|
|
|
let gitFetchExtraArgs = ['--no-tags', '--prune', '--recurse-submodules']
|
2023-05-25 18:22:24 +00:00
|
|
|
const isTag = env.GITHUB_REF?.startsWith('refs/tags/')
|
2023-05-25 21:53:58 +00:00
|
|
|
let submodulePaths: string[] = []
|
2023-05-25 21:43:31 +00:00
|
|
|
|
|
|
|
if (hasSubmodule) {
|
2023-05-25 21:53:58 +00:00
|
|
|
submodulePaths = await getSubmodulePath({cwd: workingDirectory})
|
2023-05-25 21:43:31 +00:00
|
|
|
}
|
2023-05-25 18:22:24 +00:00
|
|
|
|
|
|
|
if (isTag) {
|
2023-06-14 19:22:47 +00:00
|
|
|
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules']
|
2023-05-25 18:22:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
let diffResult: DiffResult
|
|
|
|
|
|
|
|
if (!env.GITHUB_EVENT_PULL_REQUEST_BASE_REF) {
|
2023-06-08 12:12:03 +00:00
|
|
|
core.info(`Running on a ${env.GITHUB_EVENT_NAME || 'push'} event...`)
|
2023-05-25 18:22:24 +00:00
|
|
|
diffResult = await getSHAForPushEvent(
|
|
|
|
inputs,
|
|
|
|
env,
|
|
|
|
workingDirectory,
|
|
|
|
isShallow,
|
|
|
|
hasSubmodule,
|
2023-06-14 19:22:47 +00:00
|
|
|
gitFetchExtraArgs,
|
2023-05-25 18:22:24 +00:00
|
|
|
isTag
|
|
|
|
)
|
|
|
|
} else {
|
2023-06-08 12:12:03 +00:00
|
|
|
core.info(
|
|
|
|
`Running on a ${env.GITHUB_EVENT_NAME || 'pull_request'} event...`
|
|
|
|
)
|
2023-05-25 18:22:24 +00:00
|
|
|
diffResult = await getSHAForPullRequestEvent(
|
|
|
|
inputs,
|
|
|
|
env,
|
|
|
|
workingDirectory,
|
|
|
|
isShallow,
|
|
|
|
hasSubmodule,
|
2023-06-14 19:22:47 +00:00
|
|
|
gitFetchExtraArgs
|
2023-05-25 18:22:24 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2023-05-26 16:48:32 +00:00
|
|
|
if (diffResult.initialCommit) {
|
|
|
|
core.info('This is the first commit for this repository; exiting...')
|
|
|
|
core.endGroup()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2023-05-25 18:22:24 +00:00
|
|
|
core.info(
|
|
|
|
`Retrieving changes between ${diffResult.previousSha} (${diffResult.targetBranch}) → ${diffResult.currentSha} (${diffResult.currentBranch})`
|
|
|
|
)
|
|
|
|
|
|
|
|
const filePatterns = await getFilePatterns({
|
2023-05-26 14:20:56 +00:00
|
|
|
inputs,
|
|
|
|
workingDirectory
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
2023-06-14 18:45:32 +00:00
|
|
|
core.debug(`File patterns: ${filePatterns}`)
|
2023-05-25 18:22:24 +00:00
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allDiffFiles = await getAllDiffFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
workingDirectory,
|
|
|
|
hasSubmodule,
|
|
|
|
diffResult,
|
|
|
|
submodulePaths
|
|
|
|
})
|
2023-06-14 18:45:32 +00:00
|
|
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
|
|
|
|
|
|
|
|
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
|
|
|
allDiffFiles,
|
|
|
|
filePatterns
|
|
|
|
})
|
|
|
|
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
|
|
|
|
|
|
|
|
const addedFiles = await getChangeTypeFiles({
|
|
|
|
inputs,
|
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Added]
|
|
|
|
})
|
2023-05-25 18:22:24 +00:00
|
|
|
core.debug(`Added files: ${addedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'added_files',
|
|
|
|
value: addedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const copiedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Copied]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Copied files: ${copiedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'copied_files',
|
|
|
|
value: copiedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const modifiedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Modified]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Modified files: ${modifiedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'modified_files',
|
|
|
|
value: modifiedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const renamedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Renamed]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Renamed files: ${renamedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'renamed_files',
|
|
|
|
value: renamedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const typeChangedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.TypeChanged]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Type changed files: ${typeChangedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'type_changed_files',
|
|
|
|
value: typeChangedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const unmergedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Unmerged]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Unmerged files: ${unmergedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'unmerged_files',
|
|
|
|
value: unmergedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const unknownFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Unknown]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Unknown files: ${unknownFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'unknown_files',
|
|
|
|
value: unknownFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allChangedAndModifiedFiles = await getAllChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`All changed and modified files: ${allChangedAndModifiedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'all_changed_and_modified_files',
|
|
|
|
value: allChangedAndModifiedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allChangedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed
|
|
|
|
]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`All changed files: ${allChangedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'all_changed_files',
|
|
|
|
value: allChangedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'any_changed',
|
|
|
|
value: allChangedFiles.length > 0 && filePatterns.length > 0,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allOtherChangedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed
|
|
|
|
]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`All other changed files: ${allOtherChangedFiles}`)
|
|
|
|
|
|
|
|
const otherChangedFiles = allOtherChangedFiles
|
2023-05-29 16:12:36 +00:00
|
|
|
.split(inputs.separator)
|
2023-05-25 18:22:24 +00:00
|
|
|
.filter(
|
2023-05-29 16:12:36 +00:00
|
|
|
filePath => !allChangedFiles.split(inputs.separator).includes(filePath)
|
2023-05-25 18:22:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const onlyChanged =
|
2023-06-07 22:56:42 +00:00
|
|
|
otherChangedFiles.length === 0 &&
|
|
|
|
allChangedFiles.length > 0 &&
|
|
|
|
filePatterns.length > 0
|
2023-05-25 18:22:24 +00:00
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'only_changed',
|
|
|
|
value: onlyChanged,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'other_changed_files',
|
2023-05-29 16:12:36 +00:00
|
|
|
value: otherChangedFiles.join(inputs.separator),
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allModifiedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed,
|
|
|
|
ChangeTypeEnum.Deleted
|
|
|
|
]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`All modified files: ${allModifiedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'all_modified_files',
|
|
|
|
value: allModifiedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'any_modified',
|
|
|
|
value: allModifiedFiles.length > 0 && filePatterns.length > 0,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allOtherModifiedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [
|
|
|
|
ChangeTypeEnum.Added,
|
|
|
|
ChangeTypeEnum.Copied,
|
|
|
|
ChangeTypeEnum.Modified,
|
|
|
|
ChangeTypeEnum.Renamed,
|
|
|
|
ChangeTypeEnum.Deleted
|
|
|
|
]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const otherModifiedFiles = allOtherModifiedFiles
|
2023-05-29 16:12:36 +00:00
|
|
|
.split(inputs.separator)
|
2023-05-25 18:22:24 +00:00
|
|
|
.filter(
|
2023-05-29 16:12:36 +00:00
|
|
|
filePath => !allModifiedFiles.split(inputs.separator).includes(filePath)
|
2023-05-25 18:22:24 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
const onlyModified =
|
2023-06-07 22:56:42 +00:00
|
|
|
otherModifiedFiles.length === 0 &&
|
|
|
|
allModifiedFiles.length > 0 &&
|
|
|
|
filePatterns.length > 0
|
2023-05-25 18:22:24 +00:00
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'only_modified',
|
|
|
|
value: onlyModified,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'other_modified_files',
|
2023-05-29 16:12:36 +00:00
|
|
|
value: otherModifiedFiles.join(inputs.separator),
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const deletedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allFilteredDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Deleted]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
core.debug(`Deleted files: ${deletedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'deleted_files',
|
|
|
|
value: deletedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'any_deleted',
|
|
|
|
value: deletedFiles.length > 0 && filePatterns.length > 0,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
2023-06-14 18:45:32 +00:00
|
|
|
const allOtherDeletedFiles = await getChangeTypeFiles({
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs,
|
2023-06-14 18:45:32 +00:00
|
|
|
changedFiles: allDiffFiles,
|
|
|
|
changeTypes: [ChangeTypeEnum.Deleted]
|
2023-05-25 18:22:24 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
const otherDeletedFiles = allOtherDeletedFiles
|
2023-05-29 16:12:36 +00:00
|
|
|
.split(inputs.separator)
|
2023-05-25 18:22:24 +00:00
|
|
|
.filter(
|
2023-05-29 16:12:36 +00:00
|
|
|
filePath => !deletedFiles.split(inputs.separator).includes(filePath)
|
2023-05-25 18:22:24 +00:00
|
|
|
)
|
|
|
|
|
2023-06-07 22:56:42 +00:00
|
|
|
const onlyDeleted =
|
|
|
|
otherDeletedFiles.length === 0 &&
|
|
|
|
deletedFiles.length > 0 &&
|
|
|
|
filePatterns.length > 0
|
2023-05-25 18:22:24 +00:00
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'only_deleted',
|
|
|
|
value: onlyDeleted,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
await setOutput({
|
|
|
|
key: 'other_deleted_files',
|
2023-05-29 16:12:36 +00:00
|
|
|
value: otherDeletedFiles.join(inputs.separator),
|
2023-05-25 18:22:24 +00:00
|
|
|
inputs
|
|
|
|
})
|
|
|
|
|
|
|
|
if (inputs.includeAllOldNewRenamedFiles) {
|
|
|
|
const allOldNewRenamedFiles = await getRenamedFiles({
|
|
|
|
inputs,
|
|
|
|
workingDirectory,
|
|
|
|
hasSubmodule,
|
|
|
|
diffResult,
|
|
|
|
submodulePaths
|
|
|
|
})
|
|
|
|
core.debug(`All old new renamed files: ${allOldNewRenamedFiles}`)
|
|
|
|
await setOutput({
|
|
|
|
key: 'all_old_new_renamed_files',
|
|
|
|
value: allOldNewRenamedFiles,
|
|
|
|
inputs
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
core.info('All Done!')
|
|
|
|
|
|
|
|
core.endGroup()
|
|
|
|
}
|
|
|
|
|
|
|
|
/* istanbul ignore if */
|
|
|
|
if (!process.env.TESTING) {
|
|
|
|
// eslint-disable-next-line github/no-then
|
|
|
|
run().catch(e => {
|
|
|
|
core.setFailed(e.message || e)
|
|
|
|
})
|
|
|
|
}
|