3
0
Fork 0
mirror of https://github.com/tj-actions/changed-files synced 2025-02-19 15:23:42 +00:00

feat: add support for restricting recoverable deleted files via patterns (#1390)

Co-authored-by: GitHub Action <action@github.com>
This commit is contained in:
Tonye Jack 2023-07-19 01:50:59 -06:00 committed by GitHub
parent b60277dde9
commit 33288d37e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 292 additions and 208 deletions

View file

@ -152,6 +152,22 @@ inputs:
description: "Recover deleted files to a new destination directory, defaults to the original location."
required: false
default: ""
recover_files:
description: "File and directory patterns used to recover deleted files."
required: false
default: ""
recover_files_separator:
description: "Separator used to split the `recover_files` input"
default: "\n"
required: false
recover_files_ignore:
description: "File and directory patterns to ignore when recovering deleted files."
required: false
default: ""
recover_files_ignore_separator:
description: "Separator used to split the `recover_files_ignore` input"
default: "\n"
required: false
token:
description: "Github token used to fetch changed files from Github's API."
required: false

214
dist/index.js generated vendored
View file

@ -326,20 +326,12 @@ const utils_1 = __nccwpck_require__(918);
const getOutputKey = (key, outputPrefix) => {
return outputPrefix ? `${outputPrefix}_${key}` : key;
};
const setChangedFilesOutput = ({ allDiffFiles, inputs, workingDirectory, diffResult, filePatterns = [], outputPrefix = '' }) => __awaiter(void 0, void 0, void 0, function* () {
const setChangedFilesOutput = ({ allDiffFiles, inputs, 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)}`);
if (diffResult) {
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,
@ -1228,6 +1220,18 @@ const getInputs = () => {
required: false
});
const recoverDeletedFilesToDestination = core.getInput('recover_deleted_files_to_destination', { required: false });
const recoverFiles = core.getInput('recover_files', { required: false });
const recoverFilesSeparator = core.getInput('recover_files_separator', {
required: false,
trimWhitespace: false
});
const recoverFilesIgnore = core.getInput('recover_files_ignore', {
required: false
});
const recoverFilesIgnoreSeparator = core.getInput('recover_files_ignore_separator', {
required: false,
trimWhitespace: false
});
const token = core.getInput('token', { required: false });
const apiUrl = core.getInput('api_url', { required: false });
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
@ -1260,6 +1264,10 @@ const getInputs = () => {
sinceLastRemoteCommit,
recoverDeletedFiles,
recoverDeletedFilesToDestination,
recoverFiles,
recoverFilesSeparator,
recoverFilesIgnore,
recoverFilesIgnoreSeparator,
includeAllOldNewRenamedFiles,
oldNewSeparator,
oldNewFilesSeparator,
@ -1339,6 +1347,40 @@ const commitSha_1 = __nccwpck_require__(8613);
const env_1 = __nccwpck_require__(9763);
const inputs_1 = __nccwpck_require__(6180);
const utils_1 = __nccwpck_require__(918);
const changedFilesOutput = ({ filePatterns, allDiffFiles, inputs, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns,
inputs
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs
});
core.info('All Done!');
core.endGroup();
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs
});
core.info('All Done!');
core.endGroup();
}
});
const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
var _a, _b, _c;
yield (0, utils_1.verifyMinimumGitVersion)();
@ -1393,44 +1435,26 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!');
core.endGroup();
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns,
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory,
diffResult
});
core.info('All Done!');
core.endGroup();
if (inputs.recoverDeletedFiles) {
let recoverPatterns = (0, utils_1.getRecoverFilePatterns)({ inputs });
if (recoverPatterns.length > 0 && filePatterns.length > 0) {
core.info('No recover patterns found; defaulting to file patterns');
recoverPatterns = filePatterns;
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
yield (0, utils_1.recoverDeletedFiles)({
inputs,
workingDirectory,
diffResult
deletedFiles: allDiffFiles[changedFiles_1.ChangeTypeEnum.Deleted],
recoverPatterns,
sha: diffResult.previousSha
});
core.info('All Done!');
core.endGroup();
}
yield changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
});
if (inputs.includeAllOldNewRenamedFiles) {
core.startGroup('changed-files-all-old-new-renamed-files');
const allOldNewRenamedFiles = yield (0, changedFiles_1.getRenamedFiles)({
@ -1455,47 +1479,18 @@ const getChangedFilesFromLocalGit = ({ inputs, env, workingDirectory, filePatter
core.endGroup();
}
});
const getChangedFilesFromRESTAPI = ({ inputs, workingDirectory, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
const getChangedFilesFromRESTAPI = ({ inputs, filePatterns, yamlFilePatterns }) => __awaiter(void 0, void 0, void 0, function* () {
const allDiffFiles = yield (0, changedFiles_1.getChangedFilesFromGithubAPI)({
inputs
});
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`);
core.info('All Done!');
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns,
inputs,
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`);
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all');
yield (0, changedFilesOutput_1.setChangedFilesOutput)({
allDiffFiles,
inputs,
workingDirectory
});
core.info('All Done!');
core.endGroup();
}
yield changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
});
});
function run() {
var _a;
@ -1505,8 +1500,7 @@ function run() {
core.debug(`Env: ${JSON.stringify(env, null, 2)}`);
const inputs = (0, inputs_1.getInputs)();
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`);
const githubContext = github.context;
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`);
core.debug(`Github Context: ${JSON.stringify(github.context, null, 2)}`);
const workingDirectory = path_1.default.resolve(env.GITHUB_WORKSPACE || process.cwd(), inputs.path);
core.debug(`Working directory: ${workingDirectory}`);
const hasGitDirectory = yield (0, utils_1.hasLocalGitDirectory)({ workingDirectory });
@ -1542,7 +1536,6 @@ function run() {
}
yield getChangedFilesFromRESTAPI({
inputs,
workingDirectory,
filePatterns,
yamlFilePatterns
});
@ -1635,7 +1628,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getYamlFilePatterns = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
exports.hasLocalGitDirectory = exports.recoverDeletedFiles = exports.setOutput = exports.getRecoverFilePatterns = exports.getYamlFilePatterns = exports.getFilePatterns = exports.jsonOutput = exports.getDirnameMaxDepth = exports.canDiffCommits = exports.getPreviousGitTag = exports.verifyCommitSha = exports.getParentSha = exports.getRemoteBranchHeadSha = exports.isInsideWorkTree = exports.getHeadSha = exports.gitLog = exports.getFilteredChangedFiles = exports.getAllChangedFiles = exports.gitRenamedFiles = exports.gitSubmoduleDiffSHA = exports.getSubmodulePath = exports.gitFetchSubmodules = exports.gitFetch = exports.submoduleExists = exports.isRepoShallow = exports.updateGitGlobalConfig = exports.verifyMinimumGitVersion = void 0;
/*global AsyncIterableIterator*/
const core = __importStar(__nccwpck_require__(2186));
const exec = __importStar(__nccwpck_require__(1514));
@ -2303,6 +2296,23 @@ const getYamlFilePatterns = ({ inputs, workingDirectory }) => __awaiter(void 0,
return filePatterns;
});
exports.getYamlFilePatterns = getYamlFilePatterns;
const getRecoverFilePatterns = ({ inputs }) => {
let filePatterns = inputs.recoverFiles.split(inputs.recoverFilesSeparator);
if (inputs.recoverFilesIgnore) {
const ignoreFilePatterns = inputs.recoverFilesIgnore.split(inputs.recoverFilesSeparator);
filePatterns = filePatterns.concat(ignoreFilePatterns.map(p => {
if (p.startsWith('!')) {
return p;
}
else {
return `!${p}`;
}
}));
}
core.debug(`recover file patterns: ${filePatterns}`);
return filePatterns.filter(Boolean);
};
exports.getRecoverFilePatterns = getRecoverFilePatterns;
const setOutput = ({ key, value, inputs }) => __awaiter(void 0, void 0, void 0, function* () {
const cleanedValue = value.toString().trim();
core.setOutput(key, cleanedValue);
@ -2328,23 +2338,31 @@ const getDeletedFileContents = ({ cwd, filePath, sha }) => __awaiter(void 0, voi
}
return stdout;
});
const recoverDeletedFiles = ({ inputs, workingDirectory, deletedFiles, sha }) => __awaiter(void 0, void 0, void 0, function* () {
if (inputs.recoverDeletedFiles) {
for (const deletedFile of deletedFiles) {
let target = path.join(workingDirectory, deletedFile);
if (inputs.recoverDeletedFilesToDestination) {
target = path.join(workingDirectory, inputs.recoverDeletedFilesToDestination, deletedFile);
}
const deletedFileContents = yield getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
});
if (!(yield exists(path.dirname(target)))) {
yield fs_1.promises.mkdir(path.dirname(target), { recursive: true });
}
yield fs_1.promises.writeFile(target, deletedFileContents);
const recoverDeletedFiles = ({ inputs, workingDirectory, deletedFiles, recoverPatterns, sha }) => __awaiter(void 0, void 0, void 0, function* () {
let recoverableDeletedFiles = deletedFiles;
core.debug(`recoverable deleted files: ${recoverableDeletedFiles}`);
if (recoverPatterns.length > 0) {
recoverableDeletedFiles = (0, micromatch_1.default)(deletedFiles, recoverPatterns, {
dot: true,
windows: IS_WINDOWS,
noext: true
});
core.debug(`filtered recoverable deleted files: ${recoverableDeletedFiles}`);
}
for (const deletedFile of recoverableDeletedFiles) {
let target = path.join(workingDirectory, deletedFile);
if (inputs.recoverDeletedFilesToDestination) {
target = path.join(workingDirectory, inputs.recoverDeletedFilesToDestination, deletedFile);
}
const deletedFileContents = yield getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
});
if (!(yield exists(path.dirname(target)))) {
yield fs_1.promises.mkdir(path.dirname(target), { recursive: true });
}
yield fs_1.promises.writeFile(target, deletedFileContents);
}
});
exports.recoverDeletedFiles = recoverDeletedFiles;

2
dist/index.js.map generated vendored

File diff suppressed because one or more lines are too long

View file

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

View file

@ -38,6 +38,10 @@ export type Inputs = {
outputRenamedFilesAsDeletedAndAdded: boolean
recoverDeletedFiles: boolean
recoverDeletedFilesToDestination: string
recoverFiles: string
recoverFilesSeparator: string
recoverFilesIgnore: string
recoverFilesIgnoreSeparator: string
token: string
apiUrl: string
skipInitialFetch: boolean
@ -153,6 +157,21 @@ export const getInputs = (): Inputs => {
'recover_deleted_files_to_destination',
{required: false}
)
const recoverFiles = core.getInput('recover_files', {required: false})
const recoverFilesSeparator = core.getInput('recover_files_separator', {
required: false,
trimWhitespace: false
})
const recoverFilesIgnore = core.getInput('recover_files_ignore', {
required: false
})
const recoverFilesIgnoreSeparator = core.getInput(
'recover_files_ignore_separator',
{
required: false,
trimWhitespace: false
}
)
const token = core.getInput('token', {required: false})
const apiUrl = core.getInput('api_url', {required: false})
const skipInitialFetch = core.getBooleanInput('skip_initial_fetch', {
@ -186,6 +205,10 @@ export const getInputs = (): Inputs => {
sinceLastRemoteCommit,
recoverDeletedFiles,
recoverDeletedFilesToDestination,
recoverFiles,
recoverFilesSeparator,
recoverFilesIgnore,
recoverFilesIgnoreSeparator,
includeAllOldNewRenamedFiles,
oldNewSeparator,
oldNewFilesSeparator,

View file

@ -2,6 +2,8 @@ import * as core from '@actions/core'
import * as github from '@actions/github'
import path from 'path'
import {
ChangedFiles,
ChangeTypeEnum,
getAllDiffFiles,
getChangedFilesFromGithubAPI,
getRenamedFiles
@ -16,16 +18,65 @@ import {Env, getEnv} from './env'
import {getInputs, Inputs} from './inputs'
import {
getFilePatterns,
getRecoverFilePatterns,
getSubmodulePath,
getYamlFilePatterns,
hasLocalGitDirectory,
isRepoShallow,
recoverDeletedFiles,
setOutput,
submoduleExists,
updateGitGlobalConfig,
verifyMinimumGitVersion
} from './utils'
const changedFilesOutput = async ({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
}: {
filePatterns: string[]
allDiffFiles: ChangedFiles
inputs: Inputs
yamlFilePatterns: Record<string, string[]>
}): Promise<void> => {
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs
})
core.info('All Done!')
core.endGroup()
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`)
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs
})
core.info('All Done!')
core.endGroup()
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs
})
core.info('All Done!')
core.endGroup()
}
}
const getChangedFilesFromLocalGit = async ({
inputs,
env,
@ -125,47 +176,30 @@ const getChangedFilesFromLocalGit = async ({
core.info('All Done!')
core.endGroup()
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
}
if (inputs.recoverDeletedFiles) {
let recoverPatterns = getRecoverFilePatterns({inputs})
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`)
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory,
diffResult
})
core.info('All Done!')
core.endGroup()
if (recoverPatterns.length > 0 && filePatterns.length > 0) {
core.info('No recover patterns found; defaulting to file patterns')
recoverPatterns = filePatterns
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
await recoverDeletedFiles({
inputs,
workingDirectory,
diffResult
deletedFiles: allDiffFiles[ChangeTypeEnum.Deleted],
recoverPatterns,
sha: diffResult.previousSha
})
core.info('All Done!')
core.endGroup()
}
await changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
})
if (inputs.includeAllOldNewRenamedFiles) {
core.startGroup('changed-files-all-old-new-renamed-files')
const allOldNewRenamedFiles = await getRenamedFiles({
@ -193,12 +227,10 @@ const getChangedFilesFromLocalGit = async ({
const getChangedFilesFromRESTAPI = async ({
inputs,
workingDirectory,
filePatterns,
yamlFilePatterns
}: {
inputs: Inputs
workingDirectory: string
filePatterns: string[]
yamlFilePatterns: Record<string, string[]>
}): Promise<void> => {
@ -208,43 +240,12 @@ const getChangedFilesFromRESTAPI = async ({
core.debug(`All diff files: ${JSON.stringify(allDiffFiles)}`)
core.info('All Done!')
if (filePatterns.length > 0) {
core.startGroup('changed-files-patterns')
await setChangedFilesOutput({
allDiffFiles,
filePatterns,
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
if (Object.keys(yamlFilePatterns).length > 0) {
for (const key of Object.keys(yamlFilePatterns)) {
core.startGroup(`changed-files-yaml-${key}`)
await setChangedFilesOutput({
allDiffFiles,
filePatterns: yamlFilePatterns[key],
outputPrefix: key,
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
}
if (filePatterns.length === 0 && Object.keys(yamlFilePatterns).length === 0) {
core.startGroup('changed-files-all')
await setChangedFilesOutput({
allDiffFiles,
inputs,
workingDirectory
})
core.info('All Done!')
core.endGroup()
}
await changedFilesOutput({
filePatterns,
allDiffFiles,
inputs,
yamlFilePatterns
})
}
export async function run(): Promise<void> {
@ -256,8 +257,7 @@ export async function run(): Promise<void> {
const inputs = getInputs()
core.debug(`Inputs: ${JSON.stringify(inputs, null, 2)}`)
const githubContext = github.context
core.debug(`Github Context: ${JSON.stringify(githubContext, null, 2)}`)
core.debug(`Github Context: ${JSON.stringify(github.context, null, 2)}`)
const workingDirectory = path.resolve(
env.GITHUB_WORKSPACE || process.cwd(),
@ -306,7 +306,6 @@ export async function run(): Promise<void> {
}
await getChangedFilesFromRESTAPI({
inputs,
workingDirectory,
filePatterns,
yamlFilePatterns
})

View file

@ -1028,6 +1028,36 @@ export const getYamlFilePatterns = async ({
return filePatterns
}
export const getRecoverFilePatterns = ({
inputs
}: {
inputs: Inputs
}): string[] => {
let filePatterns: string[] = inputs.recoverFiles.split(
inputs.recoverFilesSeparator
)
if (inputs.recoverFilesIgnore) {
const ignoreFilePatterns = inputs.recoverFilesIgnore.split(
inputs.recoverFilesSeparator
)
filePatterns = filePatterns.concat(
ignoreFilePatterns.map(p => {
if (p.startsWith('!')) {
return p
} else {
return `!${p}`
}
})
)
}
core.debug(`recover file patterns: ${filePatterns}`)
return filePatterns.filter(Boolean)
}
export const setOutput = async ({
key,
value,
@ -1084,36 +1114,48 @@ export const recoverDeletedFiles = async ({
inputs,
workingDirectory,
deletedFiles,
recoverPatterns,
sha
}: {
inputs: Inputs
workingDirectory: string
deletedFiles: string[]
recoverPatterns: string[]
sha: string
}): Promise<void> => {
if (inputs.recoverDeletedFiles) {
for (const deletedFile of deletedFiles) {
let target = path.join(workingDirectory, deletedFile)
let recoverableDeletedFiles = deletedFiles
core.debug(`recoverable deleted files: ${recoverableDeletedFiles}`)
if (inputs.recoverDeletedFilesToDestination) {
target = path.join(
workingDirectory,
inputs.recoverDeletedFilesToDestination,
deletedFile
)
}
if (recoverPatterns.length > 0) {
recoverableDeletedFiles = mm(deletedFiles, recoverPatterns, {
dot: true,
windows: IS_WINDOWS,
noext: true
})
core.debug(`filtered recoverable deleted files: ${recoverableDeletedFiles}`)
}
const deletedFileContents = await getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
})
for (const deletedFile of recoverableDeletedFiles) {
let target = path.join(workingDirectory, deletedFile)
if (!(await exists(path.dirname(target)))) {
await fs.mkdir(path.dirname(target), {recursive: true})
}
await fs.writeFile(target, deletedFileContents)
if (inputs.recoverDeletedFilesToDestination) {
target = path.join(
workingDirectory,
inputs.recoverDeletedFilesToDestination,
deletedFile
)
}
const deletedFileContents = await getDeletedFileContents({
cwd: workingDirectory,
filePath: deletedFile,
sha
})
if (!(await exists(path.dirname(target)))) {
await fs.mkdir(path.dirname(target), {recursive: true})
}
await fs.writeFile(target, deletedFileContents)
}
}