Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for restricting the deleted files output to only deleted directories #1601

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
e6ce728
feat: add support for restricting the deleted files output to only de…
jackton1 Sep 22, 2023
2325baa
Added missing changes and modified dist assets.
actions-user Sep 22, 2023
1be4200
Updated action.yml
jackton1 Sep 22, 2023
543c1a2
Updated use of deletedFilesPaths
jackton1 Sep 22, 2023
ff65504
Added missing changes and modified dist assets.
actions-user Sep 22, 2023
060b3b9
Removed unused code
jackton1 Sep 22, 2023
2398551
Added missing changes and modified dist assets.
actions-user Sep 22, 2023
c98e6d2
Removed unused code
jackton1 Sep 22, 2023
0ad71b9
Merge c98e6d20fc234e1f4b0047cd43af2a37f8f38f44 into 0b947ed818f8a396b…
jackton1 Sep 22, 2023
8296c33
Added missing changes and modified dist assets.
actions-user Sep 22, 2023
cd35eac
Updated description
jackton1 Sep 22, 2023
08906b3
Updated the test
jackton1 Sep 22, 2023
920856c
Added a test files
jackton1 Sep 22, 2023
a52f862
Deleted a single test file
jackton1 Sep 22, 2023
cd1e384
Deleted the test3 directory
jackton1 Sep 22, 2023
ef42e5a
Update test
jackton1 Sep 22, 2023
62a23f8
Updated debug message
jackton1 Sep 22, 2023
a351a30
Merge 62a23f82b163be6455968457151fa0094ec92a63 into 0b947ed818f8a396b…
jackton1 Sep 22, 2023
8af3110
Added missing changes and modified dist assets.
actions-user Sep 22, 2023
a721d00
Fixed the test
jackton1 Sep 22, 2023
e94da5a
Fixed test for windows
jackton1 Sep 22, 2023
e3cc088
Merge branch 'main' into feat/add-support-for-restricting-the-deleted…
repo-ranger[bot] Sep 22, 2023
e7fd9e5
Updated test
jackton1 Sep 22, 2023
d2486b4
Update test
jackton1 Sep 22, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
80 changes: 77 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -811,7 +811,81 @@ jobs:
else
cat "deleted_files/test/test deleted.txt"
fi


test-dir-names-deleted-files-include-only-deleted-dirs-single-file:
name: Test dir names deleted files include only deleted dirs single file
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: a52f8621d26d5d9f54b80f74bda2d9eedff94693
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: 2
- name: Run changed-files with dir_names and dir_names_deleted_files_include_only_deleted_dirs with a single file deleted withing the test directory
id: changed-files-dir-names-deleted-files-include-only-deleted-dirs-single-file
uses: ./
with:
base_sha: 920856cfdd4b4be17810e34b197596397473adf6
sha: a52f8621d26d5d9f54b80f74bda2d9eedff94693
dir_names: true
dir_names_deleted_files_include_only_deleted_dirs: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-single-file.outputs) }}'
shell:
bash
- name: Check deleted_files output
if: steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-single-file.outputs.deleted_files != ''
run: |
echo "Invalid output: Expected '' got (${{ steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-single-file.outputs.deleted_files }})"
exit 1
shell:
bash
test-dir-names-deleted-files-include-only-deleted-dirs-directory:
name: Test dir names deleted files include only deleted dirs
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.files_changed != 'true'
steps:
- name: Checkout branch
uses: actions/checkout@v4
with:
ref: cd1e384723e4d1a184568182ac2b27c53ebf017f
repository: ${{ github.event.pull_request.head.repo.full_name }}
submodules: true
fetch-depth: 2
- name: Run changed-files with dir_names and dir_names_deleted_files_include_only_deleted_dirs with the test directory deleted
id: changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory
uses: ./
with:
base_sha: a52f8621d26d5d9f54b80f74bda2d9eedff94693
sha: cd1e384723e4d1a184568182ac2b27c53ebf017f
dir_names: true
dir_names_deleted_files_include_only_deleted_dirs: true
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory.outputs) }}'
shell:
bash
- name: Check deleted_files output on non windows platform
if: steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory.outputs.deleted_files != 'test/test3' && runner.os != 'Windows'
run: |
echo "Invalid output: Expected (test/test3) got (${{ steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory.outputs.deleted_files }})"
exit 1
shell:
bash
- name: Check deleted_files output on windows platform
if: "!contains(steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory.outputs.deleted_files, 'test\\test3') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected (test\\test3) got (${{ steps.changed-files-dir-names-deleted-files-include-only-deleted-dirs-directory.outputs.deleted_files }})"
exit 1
shell:
bash

test-since-last-remote-commit:
name: Test changed-files since last remote commit
runs-on: ubuntu-latest
Expand Down Expand Up @@ -1423,14 +1497,14 @@ jobs:
fi
shell:
bash
- name: Check if a excluded file is not included in any_deleted on non windows platform
- name: Check if an excluded file is included in deleted_files output on non windows platform
if: "contains(steps.changed-files-specific.outputs.deleted_files, 'test/test/test.txt') && runner.os != 'Windows'"
run: |
echo "Invalid output: Expected not to include (test/test/test.txt) got (${{ steps.changed-files-specific.outputs.deleted_files }})"
exit 1
shell:
bash
- name: Check if a excluded file is not included in any_deleted on windows platform
- name: Check if an excluded file is included in deleted_files output on windows platform
if: "contains(steps.changed-files-specific.outputs.deleted_files, 'test\\test\\test.txt') && runner.os == 'Windows'"
run: |
echo "Invalid output: Expected not to include (test\\test\\test.txt) got (${{ steps.changed-files-specific.outputs.deleted_files }})"
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,10 @@ inputs:
description: "Separator used to split the `dir_names_include_files` input"
default: "\n"
required: false
dir_names_deleted_files_include_only_deleted_dirs:
description: "Include only directories that have been deleted as opposed to directory names of files that have been deleted in the `deleted_files` output when `dir_names` is set to `true`."
required: false
default: "false"
json:
description: "Output list of changed files in a JSON formatted string which can be used for matrix jobs. [Example](https://github.com/tj-actions/changed-files/blob/main/.github/workflows/matrix-test.yml)"
required: false
Expand Down
51 changes: 41 additions & 10 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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

Large diffs are not rendered by default.

13 changes: 9 additions & 4 deletions src/changedFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ export const processChangedFiles = async ({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
yamlFilePatterns,
workingDirectory
}: {
filePatterns: string[]
allDiffFiles: ChangedFiles
inputs: Inputs
yamlFilePatterns: Record<string, string[]>
workingDirectory?: string
}): Promise<void> => {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
Expand All @@ -44,7 +46,8 @@ export const processChangedFiles = async ({
allDiffFiles,
allFilteredDiffFiles,
inputs,
filePatterns
filePatterns,
workingDirectory
})
core.info('All Done!')
core.endGroup()
Expand All @@ -71,7 +74,8 @@ export const processChangedFiles = async ({
allFilteredDiffFiles,
inputs,
filePatterns: yamlFilePatterns[key],
outputPrefix: key
outputPrefix: key,
workingDirectory
})
if (anyModified) {
modifiedKeys.push(key)
Expand Down Expand Up @@ -106,7 +110,8 @@ export const processChangedFiles = async ({
await setOutputsAndGetModifiedAndChangedFilesStatus({
allDiffFiles,
allFilteredDiffFiles: allDiffFiles,
inputs
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
Expand Down
29 changes: 27 additions & 2 deletions src/changedFilesOutput.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import * as core from '@actions/core'
import path from 'path'
import {
ChangedFiles,
ChangeTypeEnum,
getAllChangeTypeFiles,
getChangeTypeFiles
} from './changedFiles'
import {Inputs} from './inputs'
import {getOutputKey, setArrayOutput, setOutput} from './utils'
import {getOutputKey, setArrayOutput, setOutput, exists} from './utils'

const getArrayFromPaths = (
paths: string | string[],
Expand All @@ -20,13 +21,15 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
allFilteredDiffFiles,
inputs,
filePatterns = [],
outputPrefix = ''
outputPrefix = '',
workingDirectory
}: {
allDiffFiles: ChangedFiles
allFilteredDiffFiles: ChangedFiles
inputs: Inputs
filePatterns?: string[]
outputPrefix?: string
workingDirectory?: string
}): Promise<{anyModified: boolean; anyChanged: boolean}> => {
const addedFiles = await getChangeTypeFiles({
inputs,
Expand Down Expand Up @@ -388,6 +391,28 @@ export const setOutputsAndGetModifiedAndChangedFilesStatus = async ({
changeTypes: [ChangeTypeEnum.Deleted]
})
core.debug(`Deleted files: ${JSON.stringify(deletedFiles)}`)

if (
inputs.dirNamesDeletedFilesIncludeOnlyDeletedDirs &&
inputs.dirNames &&
workingDirectory
) {
const newDeletedFilesPaths: string[] = []
for (const deletedPath of getArrayFromPaths(deletedFiles.paths, inputs)) {
const dirPath = path.join(workingDirectory, deletedPath)
core.debug(`Checking if directory exists: ${dirPath}`)
if (!(await exists(dirPath))) {
core.debug(`Directory not found: ${dirPath}`)
newDeletedFilesPaths.push(deletedPath)
}
}
deletedFiles.paths = inputs.json
? newDeletedFilesPaths
: newDeletedFilesPaths.join(inputs.separator)
deletedFiles.count = newDeletedFilesPaths.length.toString()
core.debug(`New deleted files: ${JSON.stringify(deletedFiles)}`)
}

await setOutput({
key: getOutputKey('deleted_files', outputPrefix),
value: deletedFiles.paths,
Expand Down