Skip to content

Commit

Permalink
feat: add option to skip file replacement
Browse files Browse the repository at this point in the history
resolves #20
  • Loading branch information
adrianjost committed Jan 2, 2021
1 parent f0b864d commit 38b2731
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ You need more? Let me know by [opening an issue here](https://github.com/adrianj

Will omit all delete operations for matching files present in `TARGET_REPO` but not existant in `SRC_REPO` if set to `true`. Defaults to `false`.

### `SKIP_REPLACE`

Will omit all write operations for matching files present in `SRC_REPO` and `TARGET_REPO` if set to `true`. Defaults to `false`.

### `TEMP_DIR`

The working directory where all sync operations will be done. Defaults to `tmp-${Date.now().toString()}`
Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ inputs:
description: |
Will omit all delete operations for matching files present in `TARGET_REPO` but not existant in `SRC_REPO` if set to `true`. Defaults to `false`.
required: false
SKIP_REPLACE:
description: |
Will omit all write operations for matching files present in `SRC_REPO` and `TARGET_REPO` if set to `true`. Defaults to `false`.
required: false
SKIP_CLEANUP:
description: |
If set to true or 1, the cleanup step to remove the temporary workding directory at the end will be skipped. Usefull for debugging purposes.
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/context.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ const context = {
SKIP_DELETE: ["1", "true"].includes(
core.getInput("SKIP_DELETE", { required: false }).toLowerCase()
),
SKIP_REPLACE: ["1", "true"].includes(
core.getInput("SKIP_REPLACE", { required: false }).toLowerCase()
),
SRC_REPO:
core.getInput("SRC_REPO", { required: false }) ||
process.env.GITHUB_REPOSITORY,
Expand Down
16 changes: 15 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ const {
FILE_PATTERNS,
DRY_RUN,
SKIP_DELETE,
SKIP_REPLACE,
SRC_REPO,
SRC_ROOT,
TARGET_ROOT,
Expand Down Expand Up @@ -64,7 +65,20 @@ const init = (repoFullname) => {
};

const copyFile = async (from, to) => {
// TODO [#20]: add option to skip replacement of files
const targetExists = await fs
.access(to)
.then(() => true)
.catch(() => false);
if (SKIP_REPLACE && targetExists) {
logger.info(
"skip copying",
from.replace(/\\/g, "/").replace(/^\//, ""),
"to",
to.replace(/\\/g, "/").replace(/^\//, ""),
"because SKIP_REPLACE = true"
);
return;
}
logger.info(
"copy",
from.replace(/\\/g, "/").replace(/^\//, ""),
Expand Down

0 comments on commit 38b2731

Please sign in to comment.