feat: move deleted file recovery to leverage filter (#1272)

This commit is contained in:
Tonye Jack 2023-06-16 20:33:42 -06:00 committed by GitHub
parent 480e87dd66
commit c3c3db7fee
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 107 additions and 24 deletions

View File

@ -651,6 +651,73 @@ jobs:
exit 1
else
cat "test/test deleted.txt"
rm "test/test deleted.txt"
fi
- name: Run changed-files with recover_deleted_files and files input
id: changed-files-recover-deleted-files-with-files
uses: ./
with:
base_sha: "fcdeb5b3d797752d95f6dbe98552a95c29dad338"
sha: "432e0c810c60ef1332850a971c5ec39022034b4c"
files: |
test
recover_deleted_files: true
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-recover-deleted-files-with-files.outputs) }}"
shell:
bash
- name: Verify deleted files
if: steps.changed-files-recover-deleted-files-with-files.outputs.deleted_files != 'test/test deleted.txt'
run: |
echo "Expected: (test/test deleted.txt) got ${{ steps.changed-files-recover-deleted-files-with-files.outputs.deleted_files }}"
exit 1
- name: Verify that test/test deleted.txt is restored
run: |
if [ ! -f "test/test deleted.txt" ]; then
echo "Expected: (test/test deleted.txt) to exist"
exit 1
else
cat "test/test deleted.txt"
rm "test/test deleted.txt"
fi
- name: Run changed-files with recover_deleted_files and files_yaml input
id: changed-files-recover-deleted-files-with-files-yaml
uses: ./
with:
base_sha: "fcdeb5b3d797752d95f6dbe98552a95c29dad338"
sha: "432e0c810c60ef1332850a971c5ec39022034b4c"
files_yaml: |
test:
- test/**.txt
- test/**.md
recover_deleted_files: true
- name: Show output
run: |
echo "${{ toJSON(steps.changed-files-recover-deleted-files-with-files-yaml.outputs) }}"
shell:
bash
- name: Verify deleted files
if: steps.changed-files-recover-deleted-files-with-files-yaml.outputs.test_deleted_files != 'test/test deleted.txt'
run: |
echo "Expected: (test/test deleted.txt) got ${{ steps.changed-files-recover-deleted-files-with-files-yaml.outputs.test_deleted_files }}"
exit 1
- name: Verify that test/test deleted.txt is restored
run: |
if [ ! -f "test/test deleted.txt" ]; then
echo "Expected: (test/test deleted.txt) to exist"
exit 1
else
cat "test/test deleted.txt"
rm "test/test deleted.txt"
fi
- name: Run changed-files with recover_deleted_files and recover_deleted_files_to_destination

26
dist/index.js generated vendored
View File

@ -235,12 +235,18 @@ const utils_1 = __nccwpck_require__(918);
const getOutputKey = (key, outputPrefix) => {
return outputPrefix ? `${outputPrefix}_${key}` : key;
};
const setChangedFilesOutput = ({ allDiffFiles, inputs, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffResult, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
allDiffFiles,
filePatterns
});
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
yield (0, utils_1.recoverDeletedFiles)({
inputs,
workingDirectory,
deletedFiles: allFilteredDiffFiles[changedFiles_1.ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
});
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
inputs,
changedFiles: allFilteredDiffFiles,
@ -1239,12 +1245,6 @@ function run() {
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!');
core.endGroup();
yield (0, utils_1.recoverDeletedFiles)({
inputs,
workingDirectory,
deletedFiles: allDiffFiles[changedFiles_1.ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
});
const filePatterns = yield (0, utils_1.getFilePatterns)({
inputs,
workingDirectory
@ -1255,7 +1255,9 @@ function run() {
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns,
inputs
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
@ -1271,8 +1273,10 @@ function run() {
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
outputPrefix: key
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
@ -1282,7 +1286,9 @@ function run() {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View File

@ -5,8 +5,9 @@ import {
getAllChangeTypeFiles,
getChangeTypeFiles
} from './changedFiles'
import {DiffResult} from './commitSha'
import {Inputs} from './inputs'
import {getFilteredChangedFiles, setOutput} from './utils'
import {getFilteredChangedFiles, recoverDeletedFiles, setOutput} from './utils'
const getOutputKey = (key: string, outputPrefix: string): string => {
return outputPrefix ? `${outputPrefix}_${key}` : key
@ -15,12 +16,16 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
export const setChangedFilesOutput = async ({
allDiffFiles,
inputs,
workingDirectory,
diffResult,
filePatterns = [],
outputPrefix = ''
}: {
allDiffFiles: ChangedFiles
filePatterns?: string[]
inputs: Inputs
workingDirectory: string
diffResult: DiffResult
outputPrefix?: string
}): Promise<void> => {
const allFilteredDiffFiles = await getFilteredChangedFiles({
@ -29,6 +34,13 @@ export const setChangedFilesOutput = async ({
})
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
await recoverDeletedFiles({
inputs,
workingDirectory,
deletedFiles: allFilteredDiffFiles[ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
})
const addedFiles = await getChangeTypeFiles({
inputs,
changedFiles: allFilteredDiffFiles,

View File

@ -1,6 +1,6 @@
import * as core from '@actions/core'
import path from 'path'
import {ChangeTypeEnum, getAllDiffFiles, getRenamedFiles} from './changedFiles'
import {getAllDiffFiles, getRenamedFiles} from './changedFiles'
import {setChangedFilesOutput} from './changedFilesOutput'
import {
DiffResult,
@ -14,7 +14,6 @@ import {
getSubmodulePath,
getYamlFilePatterns,
isRepoShallow,
recoverDeletedFiles,
setOutput,
submoduleExists,
updateGitGlobalConfig,
@ -119,13 +118,6 @@ export async function run(): Promise<void> {
core.info('All Done!')
core.endGroup()
await recoverDeletedFiles({
inputs,
workingDirectory,
deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
sha: diffResult.previousSha
})
const filePatterns = await getFilePatterns({
inputs,
workingDirectory
@ -137,7 +129,9 @@ export async function run(): Promise<void> {
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
@ -155,8 +149,10 @@ export async function run(): Promise<void> {
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
outputPrefix: key
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
@ -167,7 +163,9 @@ export async function run(): Promise<void> {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()