diff --git a/README.md b/README.md index 53d6abab..40d1706b 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. @@ -108,6 +108,7 @@ Below you'll find a description of what each option does. | `BRANCH` | This is the branch you wish to deploy to, for example `gh-pages` or `docs`. | `with` | **Yes** | | `FOLDER` | The folder in your repository that you want to deploy. If your build script compiles into a directory named `build` you'd put it here. **Folder paths cannot have a leading `/` or `./`**. If you wish to deploy the root directory you can place a `.` here. | `with` | **Yes** | | `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** | 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 a08e2b12..34cce3d4 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -23,6 +23,7 @@ exports.action = { gitHubToken: core.getInput("GITHUB_TOKEN"), accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), + targetFolder: core.getInput("TARGET_FOLDER"), baseBranch: core.getInput("BASE_BRANCH") || "master", name: pusher && pusher.name ? pusher.name diff --git a/lib/git.js b/lib/git.js index bdce914f..bda7eb38 100644 --- a/lib/git.js +++ b/lib/git.js @@ -92,7 +92,9 @@ function deploy() { 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}/. ${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); + 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); 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/package.json b/package.json index 0b143380..d2b9a10d 100644 --- a/package.json +++ b/package.json @@ -33,18 +33,18 @@ "license": "MIT", "dependencies": { "@actions/core": "^1.2.0", - "@actions/exec": "^1.0.1", - "@actions/github": "^1.1.0" + "@actions/exec": "^1.0.2", + "@actions/github": "^2.0.0" }, "devDependencies": { "@types/jest": "^24.0.23", - "@types/node": "^12.12.14", + "@types/node": "^12.12.17", "jest": "^24.8.0", "jest-circus": "^24.7.1", "lodash": "^4.17.15", "prettier": "^1.19.1", "ts-jest": "^24.2.0", "tslint": "^5.20.0", - "typescript": "^3.7.2" + "typescript": "^3.7.3" } } diff --git a/src/constants.ts b/src/constants.ts index 1d448f06..5a39e3fc 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -18,6 +18,7 @@ export const action = { gitHubToken: core.getInput("GITHUB_TOKEN"), accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), + targetFolder: core.getInput("TARGET_FOLDER"), baseBranch: core.getInput("BASE_BRANCH") || "master", name: pusher && pusher.name diff --git a/src/git.ts b/src/git.ts index 21a4f543..5ad6c964 100644 --- a/src/git.ts +++ b/src/git.ts @@ -87,9 +87,11 @@ export async function deploy(): Promise { Allows the user to specify the root if '.' is provided. rysync is used to prevent file duplication. */ await execute( - `rsync -q -av --progress ${ - action.build - }/. ${temporaryDeploymentDirectory} ${ + `rsync -q -av --progress ${action.build}/. ${ + action.targetFolder + ? `${temporaryDeploymentDirectory}/${action.targetFolder}` + : temporaryDeploymentDirectory + } ${ action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : "" } --exclude .git --exclude .github ${ action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : "" diff --git a/yarn.lock b/yarn.lock index 9dd4768f..182df128 100644 --- a/yarn.lock +++ b/yarn.lock @@ -6,17 +6,23 @@ version "1.2.0" resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.0.tgz#aa5f52b26c362c821d41557e599371a42f6c0b3d" -"@actions/exec@^1.0.1": - version "1.0.1" - resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.0.1.tgz#1624b541165697e7008d7c87bc1f69f191263c6c" - -"@actions/github@^1.1.0": - version "1.1.0" - resolved "https://registry.yarnpkg.com/@actions/github/-/github-1.1.0.tgz#06f34e6b0cf07eb2b3641de3e680dbfae6bcd400" +"@actions/exec@^1.0.2": + version "1.0.2" + resolved "https://registry.yarnpkg.com/@actions/exec/-/exec-1.0.2.tgz#80ae9c2ea0bf5d0046a9f73d2a1b15bddfff0311" dependencies: - "@octokit/graphql" "^2.0.1" + "@actions/io" "^1.0.1" + +"@actions/github@^2.0.0": + version "2.0.0" + resolved "https://registry.yarnpkg.com/@actions/github/-/github-2.0.0.tgz#5b066b1a8747bbf48d47a058d9c241a2e37d5ee7" + dependencies: + "@octokit/graphql" "^4.3.1" "@octokit/rest" "^16.15.0" +"@actions/io@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@actions/io/-/io-1.0.1.tgz#81a9418fe2bbdef2d2717a8e9f85188b9c565aca" + "@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5": version "7.5.5" resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d" @@ -284,12 +290,13 @@ is-plain-object "^3.0.0" universal-user-agent "^4.0.0" -"@octokit/graphql@^2.0.1": - version "2.1.3" - resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-2.1.3.tgz#60c058a0ed5fa242eca6f938908d95fd1a2f4b92" +"@octokit/graphql@^4.3.1": + version "4.3.1" + resolved "https://registry.yarnpkg.com/@octokit/graphql/-/graphql-4.3.1.tgz#9ee840e04ed2906c7d6763807632de84cdecf418" dependencies: - "@octokit/request" "^5.0.0" - universal-user-agent "^2.0.3" + "@octokit/request" "^5.3.0" + "@octokit/types" "^2.0.0" + universal-user-agent "^4.0.0" "@octokit/request-error@^1.0.1", "@octokit/request-error@^1.0.2": version "1.2.0" @@ -299,7 +306,7 @@ deprecation "^2.0.0" once "^1.4.0" -"@octokit/request@^5.0.0", "@octokit/request@^5.2.0": +"@octokit/request@^5.2.0", "@octokit/request@^5.3.0": version "5.3.1" resolved "https://registry.yarnpkg.com/@octokit/request/-/request-5.3.1.tgz#3a1ace45e6f88b1be4749c5da963b3a3b4a2f120" dependencies: @@ -387,9 +394,9 @@ dependencies: jest-diff "^24.3.0" -"@types/node@>= 8", "@types/node@^12.12.14": - version "12.12.14" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.14.tgz#1c1d6e3c75dba466e0326948d56e8bd72a1903d2" +"@types/node@>= 8", "@types/node@^12.12.17": + version "12.12.17" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.17.tgz#191b71e7f4c325ee0fb23bc4a996477d92b8c39b" "@types/stack-utils@^1.0.1": version "1.0.1" @@ -2385,7 +2392,7 @@ os-homedir@^1.0.0: version "1.0.2" resolved "https://registry.yarnpkg.com/os-homedir/-/os-homedir-1.0.2.tgz#ffbc4988336e0e833de0c168c7ef152121aa7fb3" -os-name@^3.0.0, os-name@^3.1.0: +os-name@^3.1.0: version "3.1.0" resolved "https://registry.yarnpkg.com/os-name/-/os-name-3.1.0.tgz#dec19d966296e1cd62d701a5a66ee1ddeae70801" dependencies: @@ -3133,9 +3140,9 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -typescript@^3.7.2: - version "3.7.2" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" +typescript@^3.7.3: + version "3.7.3" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.3.tgz#b36840668a16458a7025b9eabfad11b66ab85c69" uglify-js@^3.1.4: version "3.6.8" @@ -3153,12 +3160,6 @@ union-value@^1.0.0: is-extendable "^0.1.1" set-value "^2.0.1" -universal-user-agent@^2.0.3: - version "2.1.0" - resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-2.1.0.tgz#5abfbcc036a1ba490cb941f8fd68c46d3669e8e4" - dependencies: - os-name "^3.0.0" - universal-user-agent@^4.0.0: version "4.0.0" resolved "https://registry.yarnpkg.com/universal-user-agent/-/universal-user-agent-4.0.0.tgz#27da2ec87e32769619f68a14996465ea1cb9df16"