Skip to content

Commit

Permalink
feat: move deleted file recovery to leverage filter (#1272)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Jun 17, 2023
1 parent 480e87d commit c3c3db7
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 24 deletions.
67 changes: 67 additions & 0 deletions .github/workflows/test.yml
Expand Up @@ -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
Expand Down
26 changes: 16 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.

14 changes: 13 additions & 1 deletion src/changedFilesOutput.ts
Expand Up @@ -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
Expand All @@ -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({
Expand All @@ -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,
Expand Down
22 changes: 10 additions & 12 deletions src/main.ts
@@ -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,
Expand All @@ -14,7 +14,6 @@ import {
getSubmodulePath,
getYamlFilePatterns,
isRepoShallow,
recoverDeletedFiles,
setOutput,
submoduleExists,
updateGitGlobalConfig,
Expand Down Expand Up @@ -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
Expand All @@ -137,7 +129,9 @@ export async function run(): Promise<void> {
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
Expand All @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit c3c3db7

Please sign in to comment.