feat: move deleted file recovery to leverage filter (#1272)
This commit is contained in:
parent
480e87dd66
commit
c3c3db7fee
67
.github/workflows/test.yml
vendored
67
.github/workflows/test.yml
vendored
@ -651,6 +651,73 @@ jobs:
|
|||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
cat "test/test deleted.txt"
|
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
|
fi
|
||||||
|
|
||||||
- name: Run changed-files with recover_deleted_files and recover_deleted_files_to_destination
|
- name: Run changed-files with recover_deleted_files and recover_deleted_files_to_destination
|
||||||
|
26
dist/index.js
generated
vendored
26
dist/index.js
generated
vendored
@ -235,12 +235,18 @@ const utils_1 = __nccwpck_require__(918);
|
|||||||
const getOutputKey = (key, outputPrefix) => {
|
const getOutputKey = (key, outputPrefix) => {
|
||||||
return outputPrefix ? `${outputPrefix}_${key}` : key;
|
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)({
|
const allFilteredDiffFiles = yield (0, utils_1.getFilteredChangedFiles)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns
|
filePatterns
|
||||||
});
|
});
|
||||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`);
|
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)({
|
const addedFiles = yield (0, changedFiles_1.getChangeTypeFiles)({
|
||||||
inputs,
|
inputs,
|
||||||
changedFiles: allFilteredDiffFiles,
|
changedFiles: allFilteredDiffFiles,
|
||||||
@ -1239,12 +1245,6 @@ function run() {
|
|||||||
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
core.endGroup();
|
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)({
|
const filePatterns = yield (0, utils_1.getFilePatterns)({
|
||||||
inputs,
|
inputs,
|
||||||
workingDirectory
|
workingDirectory
|
||||||
@ -1255,7 +1255,9 @@ function run() {
|
|||||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns,
|
filePatterns,
|
||||||
inputs
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
});
|
});
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
@ -1271,8 +1273,10 @@ function run() {
|
|||||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns: yamlFilePatterns[key],
|
filePatterns: yamlFilePatterns[key],
|
||||||
|
outputPrefix: key,
|
||||||
inputs,
|
inputs,
|
||||||
outputPrefix: key
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
});
|
});
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
@ -1282,7 +1286,9 @@ function run() {
|
|||||||
core.startGroup('changed-files-all');
|
core.startGroup('changed-files-all');
|
||||||
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
});
|
});
|
||||||
core.info('All Done!');
|
core.info('All Done!');
|
||||||
core.endGroup();
|
core.endGroup();
|
||||||
|
2
dist/index.js.map
generated
vendored
2
dist/index.js.map
generated
vendored
File diff suppressed because one or more lines are too long
@ -5,8 +5,9 @@ import {
|
|||||||
getAllChangeTypeFiles,
|
getAllChangeTypeFiles,
|
||||||
getChangeTypeFiles
|
getChangeTypeFiles
|
||||||
} from './changedFiles'
|
} from './changedFiles'
|
||||||
|
import {DiffResult} from './commitSha'
|
||||||
import {Inputs} from './inputs'
|
import {Inputs} from './inputs'
|
||||||
import {getFilteredChangedFiles, setOutput} from './utils'
|
import {getFilteredChangedFiles, recoverDeletedFiles, setOutput} from './utils'
|
||||||
|
|
||||||
const getOutputKey = (key: string, outputPrefix: string): string => {
|
const getOutputKey = (key: string, outputPrefix: string): string => {
|
||||||
return outputPrefix ? `${outputPrefix}_${key}` : key
|
return outputPrefix ? `${outputPrefix}_${key}` : key
|
||||||
@ -15,12 +16,16 @@ const getOutputKey = (key: string, outputPrefix: string): string => {
|
|||||||
export const setChangedFilesOutput = async ({
|
export const setChangedFilesOutput = async ({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs,
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
diffResult,
|
||||||
filePatterns = [],
|
filePatterns = [],
|
||||||
outputPrefix = ''
|
outputPrefix = ''
|
||||||
}: {
|
}: {
|
||||||
allDiffFiles: ChangedFiles
|
allDiffFiles: ChangedFiles
|
||||||
filePatterns?: string[]
|
filePatterns?: string[]
|
||||||
inputs: Inputs
|
inputs: Inputs
|
||||||
|
workingDirectory: string
|
||||||
|
diffResult: DiffResult
|
||||||
outputPrefix?: string
|
outputPrefix?: string
|
||||||
}): Promise<void> => {
|
}): Promise<void> => {
|
||||||
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
const allFilteredDiffFiles = await getFilteredChangedFiles({
|
||||||
@ -29,6 +34,13 @@ export const setChangedFilesOutput = async ({
|
|||||||
})
|
})
|
||||||
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
|
core.debug(`All filtered diff files: ${JSON.stringify(allFilteredDiffFiles)}`)
|
||||||
|
|
||||||
|
await recoverDeletedFiles({
|
||||||
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
deletedFiles: allFilteredDiffFiles[ChangeTypeEnum.Deleted],
|
||||||
|
sha: diffResult.previousSha
|
||||||
|
})
|
||||||
|
|
||||||
const addedFiles = await getChangeTypeFiles({
|
const addedFiles = await getChangeTypeFiles({
|
||||||
inputs,
|
inputs,
|
||||||
changedFiles: allFilteredDiffFiles,
|
changedFiles: allFilteredDiffFiles,
|
||||||
|
22
src/main.ts
22
src/main.ts
@ -1,6 +1,6 @@
|
|||||||
import * as core from '@actions/core'
|
import * as core from '@actions/core'
|
||||||
import path from 'path'
|
import path from 'path'
|
||||||
import {ChangeTypeEnum, getAllDiffFiles, getRenamedFiles} from './changedFiles'
|
import {getAllDiffFiles, getRenamedFiles} from './changedFiles'
|
||||||
import {setChangedFilesOutput} from './changedFilesOutput'
|
import {setChangedFilesOutput} from './changedFilesOutput'
|
||||||
import {
|
import {
|
||||||
DiffResult,
|
DiffResult,
|
||||||
@ -14,7 +14,6 @@ import {
|
|||||||
getSubmodulePath,
|
getSubmodulePath,
|
||||||
getYamlFilePatterns,
|
getYamlFilePatterns,
|
||||||
isRepoShallow,
|
isRepoShallow,
|
||||||
recoverDeletedFiles,
|
|
||||||
setOutput,
|
setOutput,
|
||||||
submoduleExists,
|
submoduleExists,
|
||||||
updateGitGlobalConfig,
|
updateGitGlobalConfig,
|
||||||
@ -119,13 +118,6 @@ export async function run(): Promise<void> {
|
|||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
|
||||||
await recoverDeletedFiles({
|
|
||||||
inputs,
|
|
||||||
workingDirectory,
|
|
||||||
deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
|
|
||||||
sha: diffResult.previousSha
|
|
||||||
})
|
|
||||||
|
|
||||||
const filePatterns = await getFilePatterns({
|
const filePatterns = await getFilePatterns({
|
||||||
inputs,
|
inputs,
|
||||||
workingDirectory
|
workingDirectory
|
||||||
@ -137,7 +129,9 @@ export async function run(): Promise<void> {
|
|||||||
await setChangedFilesOutput({
|
await setChangedFilesOutput({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns,
|
filePatterns,
|
||||||
inputs
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
})
|
})
|
||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
@ -155,8 +149,10 @@ export async function run(): Promise<void> {
|
|||||||
await setChangedFilesOutput({
|
await setChangedFilesOutput({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
filePatterns: yamlFilePatterns[key],
|
filePatterns: yamlFilePatterns[key],
|
||||||
|
outputPrefix: key,
|
||||||
inputs,
|
inputs,
|
||||||
outputPrefix: key
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
})
|
})
|
||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
@ -167,7 +163,9 @@ export async function run(): Promise<void> {
|
|||||||
core.startGroup('changed-files-all')
|
core.startGroup('changed-files-all')
|
||||||
await setChangedFilesOutput({
|
await setChangedFilesOutput({
|
||||||
allDiffFiles,
|
allDiffFiles,
|
||||||
inputs
|
inputs,
|
||||||
|
workingDirectory,
|
||||||
|
diffResult
|
||||||
})
|
})
|
||||||
core.info('All Done!')
|
core.info('All Done!')
|
||||||
core.endGroup()
|
core.endGroup()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user