mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Clean Excludes
This commit is contained in:
parent
10687d9ed6
commit
682d643fa8
@ -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.
|
||||
|
||||
|
@ -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 ||
|
||||
|
15
lib/git.js
15
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...");
|
||||
|
@ -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.
|
||||
|
@ -92,7 +92,9 @@ export async function deploy(): Promise<any> {
|
||||
? `${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}` : ""
|
||||
}`,
|
||||
|
Loading…
Reference in New Issue
Block a user