From 682d643fa866eccdbd778c04d794a99ac9755fb7 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 20 Dec 2019 17:36:30 -0500 Subject: [PATCH 1/4] Clean Excludes --- README.md | 3 ++- lib/constants.js | 3 ++- lib/git.js | 15 ++++++++++++++- src/constants.ts | 3 ++- src/git.ts | 4 +++- 5 files changed, 23 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 40d1706b..355f23a1 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This [GitHub action](https://github.com/features/actions) will handle the deploy process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production-ready code into any branch you'd like, including `gh-pages` and `docs`. ## Getting Started :airplane: -You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout@v1` step before this workflow runs in order for the deployment to work. +You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work. You can view an example of this below. @@ -110,6 +110,7 @@ Below you'll find a description of what each option does. | `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `with` | **No** | | `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | | `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** | +| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array string: `CLEAN_EXLUDE: '["filename.js", "./folderpath"]'` | `with` | **No** | With the action correctly configured you should see the workflow trigger the deployment under the configured conditions. diff --git a/lib/constants.js b/lib/constants.js index 34cce3d4..c1d49666 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -34,7 +34,8 @@ exports.action = { ? pusher.email : `${process.env.GITHUB_ACTOR || "github-pages-deploy-action"}@users.noreply.github.com`, - clean: core.getInput("CLEAN") + clean: core.getInput("CLEAN"), + cleanExclude: core.getInput("CLEAN_EXCLUDE") }; // Repository path used for commits/pushes. exports.repositoryPath = `https://${exports.action.accessToken || diff --git a/lib/git.js b/lib/git.js index bda7eb38..83a240d0 100644 --- a/lib/git.js +++ b/lib/git.js @@ -88,13 +88,26 @@ function deploy() { yield util_1.execute(`git checkout ${constants_1.action.baseBranch || "master"}`, constants_1.workspace); yield util_1.execute(`git fetch ${constants_1.repositoryPath}`, constants_1.workspace); yield util_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace); + // Ensures that items that need to be excluded from the clean job get parsed. + let excludes = ""; + if (constants_1.action.clean && constants_1.action.cleanExclude) { + try { + const excludedItems = JSON.parse(constants_1.action.cleanExclude); + excludedItems.forEach((item) => (excludes += `--exclude ${item} `)); + } + catch (_a) { + console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details."); + } + } /* Pushes all of the build files into the deployment directory. Allows the user to specify the root if '.' is provided. rysync is used to prevent file duplication. */ yield util_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${constants_1.action.targetFolder ? `${temporaryDeploymentDirectory}/${constants_1.action.targetFolder}` - : temporaryDeploymentDirectory} ${constants_1.action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace); + : temporaryDeploymentDirectory} ${constants_1.action.clean + ? `--delete ${excludes} --exclude CNAME --exclude .nojekyll` + : ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace); const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory); if (!hasFilesToCommit && !constants_1.isTest) { console.log("There is nothing to commit. Exiting..."); diff --git a/src/constants.ts b/src/constants.ts index 5a39e3fc..68a67116 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -31,7 +31,8 @@ export const action = { ? pusher.email : `${process.env.GITHUB_ACTOR || "github-pages-deploy-action"}@users.noreply.github.com`, - clean: core.getInput("CLEAN") + clean: core.getInput("CLEAN"), + cleanExclude: core.getInput("CLEAN_EXCLUDE") }; // Repository path used for commits/pushes. diff --git a/src/git.ts b/src/git.ts index 5ad6c964..4419a41a 100644 --- a/src/git.ts +++ b/src/git.ts @@ -92,7 +92,9 @@ export async function deploy(): Promise { ? `${temporaryDeploymentDirectory}/${action.targetFolder}` : temporaryDeploymentDirectory } ${ - action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : "" + action.clean + ? `--delete ${excludes} --exclude CNAME --exclude .nojekyll` + : "" } --exclude .git --exclude .github ${ action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : "" }`, From 08b281c798e8c81177d3edc3253eafe104132db8 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 20 Dec 2019 17:36:35 -0500 Subject: [PATCH 2/4] Update git.ts --- src/git.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/git.ts b/src/git.ts index 4419a41a..cf6fe4f3 100644 --- a/src/git.ts +++ b/src/git.ts @@ -82,6 +82,21 @@ export async function deploy(): Promise { workspace ); + // Ensures that items that need to be excluded from the clean job get parsed. + let excludes = ""; + if (action.clean && action.cleanExclude) { + try { + const excludedItems = JSON.parse(action.cleanExclude); + excludedItems.forEach( + (item: string) => (excludes += `--exclude ${item} `) + ); + } catch { + console.log( + "There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details." + ); + } + } + /* Pushes all of the build files into the deployment directory. Allows the user to specify the root if '.' is provided. From a8c729ac5997e7b7c9a9811525b7467b27827a76 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 20 Dec 2019 17:45:30 -0500 Subject: [PATCH 3/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 355f23a1..d8d5ffe5 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ This [GitHub action](https://github.com/features/actions) will handle the deploy process of your project to [GitHub Pages](https://pages.github.com/). It can be configured to upload your production-ready code into any branch you'd like, including `gh-pages` and `docs`. ## Getting Started :airplane: -You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout` step before this workflow runs in order for the deployment to work. +You can include the action in your workflow to trigger on any event that [GitHub actions supports](https://help.github.com/en/articles/events-that-trigger-workflows). If the remote branch that you wish to deploy to doesn't already exist the action will create it for you. Your workflow will also need to include the `actions/checkout@v1` step before this workflow runs in order for the deployment to work. You can view an example of this below. From bb288e9f68c8612d7e7ff9c5515add56f1853fe1 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 20 Dec 2019 17:46:18 -0500 Subject: [PATCH 4/4] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d8d5ffe5..7c153aed 100644 --- a/README.md +++ b/README.md @@ -110,7 +110,7 @@ Below you'll find a description of what each option does. | `BASE_BRANCH` | The base branch of your repository which you'd like to checkout prior to deploying. This defaults to `master`. | `with` | **No** | | `TARGET_FOLDER` | If you'd like to push the contents of the deployment folder into a specific directory on the deployment branch you can specify it here. | `with` | **No** | | `CLEAN` | If your project generates hashed files on build you can use this option to automatically delete them from the deployment branch with each deploy. This option can be toggled on by setting it to `true`. | `with` | **No** | -| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array string: `CLEAN_EXLUDE: '["filename.js", "./folderpath"]'` | `with` | **No** | +| `CLEAN_EXCLUDE` | If you need to use `CLEAN` but you'd like to preserve certain files or folders you can use this option. This should be formatted as an array but stored as a string. For example: `'["filename.js", "./folderpath"]'` | `with` | **No** | With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.