diff --git a/lib/git.js b/lib/git.js index 91aa953..d0bf535 100644 --- a/lib/git.js +++ b/lib/git.js @@ -19,6 +19,7 @@ const utils_1 = require("./utils"); const once_1 = __importDefault(require("lodash/once")); const io_1 = require("@actions/io"); const fs_extra_1 = __importDefault(require("fs-extra")); +const path_1 = __importDefault(require("path")); const authorName = 'filestorage-action'; const authorEmail = 'filestorage-action@users.noreply.github.com'; const gitAuthor = `${authorName} <${authorEmail}>`; @@ -52,11 +53,17 @@ function checkout(options) { return constants_1.Status.SKIPPED; } yield generateWorktree(options, branchExists); - yield fs_extra_1.default.copy(`${options.workspace}/${temporaryStorageDirectory}/${options.path}`, `${options.workspace}/${options.path}`, { - overwrite: true, - recursive: true, - }); - return constants_1.Status.SUCCESS; + try { + yield fs_extra_1.default.copy(path_1.default.resolve(options.workspace, temporaryStorageDirectory, `./${options.path}`), path_1.default.resolve(options.workspace, `./${options.path}`), { + overwrite: true, + recursive: true, + }); + return constants_1.Status.SUCCESS; + } + catch (err) { + console.error(err); + return constants_1.Status.SKIPPED; + } }); } exports.checkout = checkout; @@ -68,7 +75,7 @@ function save(options) { yield init(options); const branchExists = yield checkTargetBranchExist(options); yield generateWorktree(options, branchExists); - yield fs_extra_1.default.copy(`${options.workspace}/${options.path}`, `${options.workspace}/${temporaryStorageDirectory}/${options.path}`, { + yield fs_extra_1.default.copy(path_1.default.resolve(options.workspace, `./${options.path}`), path_1.default.resolve(options.workspace, temporaryStorageDirectory, `./${options.path}`), { overwrite: true, recursive: true, }); diff --git a/src/git.ts b/src/git.ts index af242ce..e29f982 100644 --- a/src/git.ts +++ b/src/git.ts @@ -56,16 +56,24 @@ export async function checkout(options: ActionInterface): Promise { await generateWorktree(options, branchExists); - await fs.copy( - `${options.workspace}/${temporaryStorageDirectory}/${options.path}`, - `${options.workspace}/${options.path}`, - { - overwrite: true, - recursive: true, - } - ); - - return Status.SUCCESS; + try { + await fs.copy( + path.resolve( + options.workspace, + temporaryStorageDirectory, + `./${options.path}` + ), + path.resolve(options.workspace, `./${options.path}`), + { + overwrite: true, + recursive: true, + } + ); + return Status.SUCCESS; + } catch (err) { + console.error(err); + return Status.SKIPPED; + } } /** @@ -79,8 +87,12 @@ export async function save(options: ActionInterface): Promise { await generateWorktree(options, branchExists); await fs.copy( - `${options.workspace}/${options.path}`, - `${options.workspace}/${temporaryStorageDirectory}/${options.path}`, + path.resolve(options.workspace, `./${options.path}`), + path.resolve( + options.workspace, + temporaryStorageDirectory, + `./${options.path}` + ), { overwrite: true, recursive: true,