Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: tj-actions/changed-files
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v36.2.0
Choose a base ref
...
head repository: tj-actions/changed-files
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v36.2.1
Choose a head ref
  • 4 commits
  • 11 files changed
  • 5 contributors

Commits on Jun 14, 2023

  1. chore: rename git fetch arguments (#1259)

    Co-authored-by: GitHub Action <action@github.com>
    jackton1 and actions-user authored Jun 14, 2023
    Copy the full SHA
    b9ea510 View commit details
  2. Upgraded to v36.2.0 (#1258)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com>
    3 people authored Jun 14, 2023
    Copy the full SHA
    c648759 View commit details
  3. feat: add support for outputting renamed files as deleted and added (#…

    …1260)
    
    Co-authored-by: GitHub Action <action@github.com>
    jackton1 and actions-user authored Jun 14, 2023
    Copy the full SHA
    90ef0b1 View commit details
  4. Updated README.md (#1261)

    Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
    tj-actions-bot and jackton1 authored Jun 14, 2023
    Copy the full SHA
    c912451 View commit details
Showing with 175 additions and 61 deletions.
  1. +35 −0 .github/workflows/test.yml
  2. +44 −0 HISTORY.md
  3. +1 −0 README.md
  4. +4 −0 action.yml
  5. +40 −30 dist/index.js
  6. +1 −1 dist/index.js.map
  7. +7 −3 src/changedFiles.ts
  8. +11 −16 src/commitSha.ts
  9. +7 −1 src/inputs.ts
  10. +12 −7 src/main.ts
  11. +13 −3 src/utils.ts
35 changes: 35 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -869,6 +869,41 @@ jobs:
exit 1
shell:
bash
- name: Run changed-files for old new filenames test rename 2 output as deleted and added
id: changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added
uses: ./
with:
base_sha: 4d04215
sha: fe238e6
fetch_depth: 60000
include_all_old_new_renamed_files: true
output_renamed_files_as_deleted_and_added: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs) }}'
shell:
bash
- name: Check all_old_new_renamed_files output
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.all_old_new_renamed_files, 'test/test rename 2.txt,test/test rename-2.txt')"
run: |
echo "Invalid output: Expected to include (test/test rename 2.txt test/test rename-2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.all_old_new_renamed_files }})"
exit 1
shell:
bash
- name: Check deleted_files output
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.deleted_files, 'test/test rename 2.txt')"
run: |
echo "Invalid output: Expected to include (test/test rename 2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.deleted_files }})"
exit 1
shell:
bash
- name: Check added_files output
if: "!contains(steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.added_files, 'test/test rename-2.txt')"
run: |
echo "Invalid output: Expected to include (test/test rename-2.txt) got (${{ steps.changed-files-all-old-new-renamed-files-2-output-as-deleted-and-added.outputs.added_files }})"
exit 1
shell:
bash
- name: Run changed-files with specific files
id: changed-files-specific
uses: ./
44 changes: 44 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,49 @@
# Changelog

# [36.2.0](https://github.com/tj-actions/changed-files/compare/v36.1.0...v36.2.0) - (2023-06-14)

## <!-- 0 -->🚀 Features

- Switch to use name status ([#1230](https://github.com/tj-actions/changed-files/issues/1230)) ([174a2a6](https://github.com/tj-actions/changed-files/commit/174a2a6360b54a2019877c254c4be78106efc94f)) - (Tonye Jack)

## <!-- 26 -->🔄 Update

- Updated README.md ([#1255](https://github.com/tj-actions/changed-files/issues/1255))

Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([2c6893c](https://github.com/tj-actions/changed-files/commit/2c6893c21a91f8238df9e0ed2f3e4488efc0629f)) - (tj-actions[bot])
- Update action.yml ([17ca5bb](https://github.com/tj-actions/changed-files/commit/17ca5bb3e554d4d9b631e09414186b64b6e64cd6)) - (Tonye Jack)
- Updated README.md ([#1249](https://github.com/tj-actions/changed-files/issues/1249))

Co-authored-by: jackton1 <jackton1@users.noreply.github.com> ([a625ca3](https://github.com/tj-actions/changed-files/commit/a625ca325f498d75648b0ec941834edc16e71a40)) - (tj-actions[bot])
- Updated README.md ([#1248](https://github.com/tj-actions/changed-files/issues/1248))

Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
Co-authored-by: Tonye Jack <jtonye@ymail.com> ([752970e](https://github.com/tj-actions/changed-files/commit/752970edd01e2a1b9e1a9ef37207bd59a34c90f4)) - (tj-actions[bot])
- Update action.yml ([7b64c76](https://github.com/tj-actions/changed-files/commit/7b64c76932d2ddd0a2be638832dc8f72eacec74c)) - (Tonye Jack)
- Updated README.md ([#1246](https://github.com/tj-actions/changed-files/issues/1246))

Co-authored-by: repo-ranger[bot] <repo-ranger[bot]@users.noreply.github.com> ([9333a5c](https://github.com/tj-actions/changed-files/commit/9333a5cf0c1a85e3dd5876284bb075ade076a9e0)) - (tj-actions[bot])

## <!-- 7 -->⚙️ Miscellaneous Tasks

- **deps:** Update peter-evans/create-pull-request action to v5.0.2 ([#1256](https://github.com/tj-actions/changed-files/issues/1256)) ([2d0b52f](https://github.com/tj-actions/changed-files/commit/2d0b52f4408b791c0c5c1eca405d8461b320dd01)) - (renovate[bot])
- **deps:** Update typescript-eslint monorepo to v5.59.11 ([#1253](https://github.com/tj-actions/changed-files/issues/1253)) ([d0e3a7c](https://github.com/tj-actions/changed-files/commit/d0e3a7c3aa15c15ace59f95a9fda1bcadf9ab3e2)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1252](https://github.com/tj-actions/changed-files/issues/1252)) ([61845c2](https://github.com/tj-actions/changed-files/commit/61845c2b19ec2ad7e3d79a6955e192e66d41cb80)) - (renovate[bot])
- **deps:** Update tj-actions/verify-changed-files action to v15 ([#1251](https://github.com/tj-actions/changed-files/issues/1251)) ([417f924](https://github.com/tj-actions/changed-files/commit/417f924dea3b9800ea861d576eee55162ab6607c)) - (renovate[bot])
- **deps:** Lock file maintenance ([#1250](https://github.com/tj-actions/changed-files/issues/1250)) ([c51a48d](https://github.com/tj-actions/changed-files/commit/c51a48d4f6bf95820aa0f9e3f3e6516bd427ae7a)) - (renovate[bot])
- Update README.md ([6d9ee62](https://github.com/tj-actions/changed-files/commit/6d9ee62035acb0c3942fba9757033c677246f2f4)) - (Tonye Jack)
- Update README.md ([b27dcc2](https://github.com/tj-actions/changed-files/commit/b27dcc252ada558d34ecd368bd253994df77acb1)) - (Tonye Jack)
- **deps:** Update dependency @types/uuid to v9.0.2 ([#1247](https://github.com/tj-actions/changed-files/issues/1247)) ([b60e479](https://github.com/tj-actions/changed-files/commit/b60e479ceab551d9a8f832d5a989eb3e492d4bf4)) - (renovate[bot])
- Update README.md ([#1237](https://github.com/tj-actions/changed-files/issues/1237)) ([8ec721e](https://github.com/tj-actions/changed-files/commit/8ec721eb3b7d57b7afc0d63748bd7242292989b1)) - (tj-actions[bot])
- Update README.md ([#1240](https://github.com/tj-actions/changed-files/issues/1240)) ([7d1d4d2](https://github.com/tj-actions/changed-files/commit/7d1d4d2cce628fd1797af3acb779dd1d26b61d31)) - (tj-actions[bot])

## <!-- 9 -->⬆️ Upgrades

- Upgraded to v36.1.0 ([#1245](https://github.com/tj-actions/changed-files/issues/1245))

Co-authored-by: jackton1 <jackton1@users.noreply.github.com>
Co-authored-by: repo-ranger[bot] <39074581+repo-ranger[bot]@users.noreply.github.com> ([ab84931](https://github.com/tj-actions/changed-files/commit/ab8493166b33b74edc5101f3e814b63cd87f05ab)) - (tj-actions[bot])

# [36.1.0](https://github.com/tj-actions/changed-files/compare/v36.0.18...v36.1.0) - (2023-06-08)

## <!-- 0 -->🚀 Features
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -225,6 +225,7 @@ Support this project with a :star:
| old\_new\_files\_separator | string | false | `" "` | Split character for old and <br>new renamed filename pairs. |
| old\_new\_separator | string | false | `","` | Split character for old and <br>new filename pairs. |
| output\_dir | string | false | `".github/outputs"` | Directory to store output files. |
| output\_renamed\_files\_as\_deleted\_and\_added | string | false | `"false"` | Output renamed files as deleted <br>and added files. |
| path | string | false | `"."` | Specify a relative path under <br>`$GITHUB_WORKSPACE` to locate the repository. |
| quotepath | string | false | `"true"` | Use non ascii characters to <br>match files and output the <br>filenames completely verbatim by setting <br>this to `false` |
| separator | string | false | `" "` | Split character for output strings |
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -117,6 +117,10 @@ inputs:
description: "Directory to store output files."
required: false
default: ".github/outputs"
output_renamed_files_as_deleted_and_added:
description: "Output renamed files as deleted and added files."
required: false
default: "false"

outputs:
added_files:
70 changes: 40 additions & 30 deletions dist/index.js
2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

10 changes: 7 additions & 3 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
@@ -88,18 +88,21 @@ export const getAllDiffFiles = async ({
workingDirectory,
hasSubmodule,
diffResult,
submodulePaths
submodulePaths,
outputRenamedFilesAsDeletedAndAdded
}: {
workingDirectory: string
hasSubmodule: boolean
diffResult: DiffResult
submodulePaths: string[]
outputRenamedFilesAsDeletedAndAdded: boolean
}): Promise<ChangedFiles> => {
const files = await getAllChangedFiles({
cwd: workingDirectory,
sha1: diffResult.previousSha,
sha2: diffResult.currentSha,
diff: diffResult.diff
diff: diffResult.diff,
outputRenamedFilesAsDeletedAndAdded
})

if (hasSubmodule) {
@@ -124,7 +127,8 @@ export const getAllDiffFiles = async ({
sha2: submoduleShaResult.currentSha,
diff: diffResult.diff,
isSubmodule: true,
parentDir: submodulePath
parentDir: submodulePath,
outputRenamedFilesAsDeletedAndAdded
})

for (const changeType of Object.keys(
27 changes: 11 additions & 16 deletions src/commitSha.ts
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@ export const getSHAForPushEvent = async (
workingDirectory: string,
isShallow: boolean,
hasSubmodule: boolean,
gitExtraArgs: string[],
gitFetchExtraArgs: string[],
isTag: boolean
): Promise<DiffResult> => {
let targetBranch = env.GITHUB_REF_NAME
@@ -102,7 +102,7 @@ export const getSHAForPushEvent = async (
await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`,
@@ -114,7 +114,7 @@ export const getSHAForPushEvent = async (
await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`,
@@ -128,7 +128,7 @@ export const getSHAForPushEvent = async (
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`
@@ -263,7 +263,7 @@ export const getSHAForPullRequestEvent = async (
workingDirectory: string,
isShallow: boolean,
hasSubmodule: boolean,
gitExtraArgs: string[]
gitFetchExtraArgs: string[]
): Promise<DiffResult> => {
let targetBranch = env.GITHUB_EVENT_PULL_REQUEST_BASE_REF
const currentBranch = env.GITHUB_EVENT_PULL_REQUEST_HEAD_REF
@@ -277,7 +277,7 @@ export const getSHAForPullRequestEvent = async (
let prFetchExitCode = await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
'origin',
@@ -289,7 +289,7 @@ export const getSHAForPullRequestEvent = async (
prFetchExitCode = await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`,
@@ -310,7 +310,7 @@ export const getSHAForPullRequestEvent = async (
await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`,
@@ -323,7 +323,7 @@ export const getSHAForPullRequestEvent = async (
await gitFetchSubmodules({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`
@@ -370,12 +370,7 @@ export const getSHAForPullRequestEvent = async (

if (!previousSha) {
if (inputs.sinceLastRemoteCommit) {
previousSha =
env.GITHUB_EVENT_BEFORE ||
(await getRemoteBranchHeadSha({
cwd: workingDirectory,
branch: currentBranch
}))
previousSha = env.GITHUB_EVENT_BEFORE

if (
!previousSha ||
@@ -415,7 +410,7 @@ export const getSHAForPullRequestEvent = async (
await gitFetch({
cwd: workingDirectory,
args: [
...gitExtraArgs,
...gitFetchExtraArgs,
'-u',
'--progress',
`--deepen=${inputs.fetchDepth}`,
8 changes: 7 additions & 1 deletion src/inputs.ts
Original file line number Diff line number Diff line change
@@ -30,6 +30,7 @@ export type Inputs = {
sinceLastRemoteCommit: boolean
writeOutputFiles: boolean
outputDir: string
outputRenamedFilesAsDeletedAndAdded: boolean
}

export const getInputs = (): Inputs => {
@@ -111,6 +112,10 @@ export const getInputs = (): Inputs => {
required: false
})
const outputDir = core.getInput('output_dir', {required: false})
const outputRenamedFilesAsDeletedAndAdded = core.getBooleanInput(
'output_renamed_files_as_deleted_and_added',
{required: false}
)

const inputs: Inputs = {
files,
@@ -139,7 +144,8 @@ export const getInputs = (): Inputs => {
escapeJson,
sinceLastRemoteCommit,
writeOutputFiles,
outputDir
outputDir,
outputRenamedFilesAsDeletedAndAdded
}

if (fetchDepth) {
19 changes: 12 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
@@ -59,16 +59,18 @@ export async function run(): Promise<void> {
)
const isShallow = await isRepoShallow({cwd: workingDirectory})
const hasSubmodule = await submoduleExists({cwd: workingDirectory})
let gitExtraArgs = ['--no-tags', '--prune', '--recurse-submodules']
let gitFetchExtraArgs = ['--no-tags', '--prune', '--recurse-submodules']
const isTag = env.GITHUB_REF?.startsWith('refs/tags/')
const outputRenamedFilesAsDeletedAndAdded =
inputs.outputRenamedFilesAsDeletedAndAdded
let submodulePaths: string[] = []

if (hasSubmodule) {
submodulePaths = await getSubmodulePath({cwd: workingDirectory})
}

if (isTag) {
gitExtraArgs = ['--prune', '--no-recurse-submodules']
gitFetchExtraArgs = ['--prune', '--no-recurse-submodules']
}

let diffResult: DiffResult
@@ -81,7 +83,7 @@ export async function run(): Promise<void> {
workingDirectory,
isShallow,
hasSubmodule,
gitExtraArgs,
gitFetchExtraArgs,
isTag
)
} else {
@@ -94,7 +96,7 @@ export async function run(): Promise<void> {
workingDirectory,
isShallow,
hasSubmodule,
gitExtraArgs
gitFetchExtraArgs
)
}

@@ -118,7 +120,8 @@ export async function run(): Promise<void> {
workingDirectory,
hasSubmodule,
diffResult,
submodulePaths
submodulePaths,
outputRenamedFilesAsDeletedAndAdded
})
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)

@@ -261,7 +264,8 @@ export async function run(): Promise<void> {
const otherChangedFiles = allOtherChangedFiles
.split(inputs.separator)
.filter(
filePath => !allChangedFiles.split(inputs.separator).includes(filePath)
(filePath: string) =>
!allChangedFiles.split(inputs.separator).includes(filePath)
)

const onlyChanged =
@@ -320,7 +324,8 @@ export async function run(): Promise<void> {
const otherModifiedFiles = allOtherModifiedFiles
.split(inputs.separator)
.filter(
filePath => !allModifiedFiles.split(inputs.separator).includes(filePath)
(filePath: string) =>
!allModifiedFiles.split(inputs.separator).includes(filePath)
)

const onlyModified =
16 changes: 13 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -410,14 +410,16 @@ export const getAllChangedFiles = async ({
sha2,
diff,
isSubmodule = false,
parentDir = ''
parentDir = '',
outputRenamedFilesAsDeletedAndAdded = false
}: {
cwd: string
sha1: string
sha2: string
diff: string
isSubmodule?: boolean
parentDir?: string
outputRenamedFilesAsDeletedAndAdded?: boolean
}): Promise<ChangedFiles> => {
const {exitCode, stdout, stderr} = await exec.getExecOutput(
'git',
@@ -466,13 +468,21 @@ export const getAllChangedFiles = async ({
const lines = stdout.split('\n').filter(Boolean)

for (const line of lines) {
const [changeType, filePath] = line.split('\t')
const [changeType, filePath, newPath = ''] = line.split('\t')
const normalizedFilePath = isSubmodule
? normalizePath(path.join(parentDir, filePath))
: normalizePath(filePath)
const normalizedNewPath = isSubmodule
? normalizePath(path.join(parentDir, newPath))
: normalizePath(newPath)

if (changeType.startsWith('R')) {
changedFiles[ChangeTypeEnum.Renamed].push(normalizedFilePath)
if (outputRenamedFilesAsDeletedAndAdded) {
changedFiles[ChangeTypeEnum.Deleted].push(normalizedFilePath)
changedFiles[ChangeTypeEnum.Added].push(normalizedNewPath)
} else {
changedFiles[ChangeTypeEnum.Renamed].push(normalizedFilePath)
}
} else {
changedFiles[changeType as ChangeTypeEnum].push(normalizedFilePath)
}