From b140db85a6e865cf4887296bf9a794f920788584 Mon Sep 17 00:00:00 2001 From: James Ives Date: Thu, 21 Nov 2019 09:33:53 -0500 Subject: [PATCH 1/8] Update integration.yml --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index f6473b03..5ede122b 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,7 +1,7 @@ name: integration-tests on: schedule: - - cron: 0 2 * * 0-6 + - cron: 30 9 * * 0-6 jobs: integration-test: runs-on: ubuntu-latest From 3d79fb5ce119be8de708898768bf2ada77bf3e5a Mon Sep 17 00:00:00 2001 From: James Ives Date: Thu, 21 Nov 2019 09:34:12 -0500 Subject: [PATCH 2/8] Update integration.yml --- .github/workflows/integration.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/integration.yml b/.github/workflows/integration.yml index 5ede122b..6edbf117 100644 --- a/.github/workflows/integration.yml +++ b/.github/workflows/integration.yml @@ -1,7 +1,7 @@ name: integration-tests on: schedule: - - cron: 30 9 * * 0-6 + - cron: 0 10 * * 0-6 jobs: integration-test: runs-on: ubuntu-latest From 1c579cbd85f718e391dd1e112b20468ecc9d4cb1 Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 22 Nov 2019 09:58:00 -0500 Subject: [PATCH 3/8] Automatically remove hashed files (#63) * Adding a CLEAN option * Summary * Clean * Tests etc * Update git.js --- README.md | 1 + __tests__/git.test.ts | 23 ----------------------- lib/constants.js | 1 + lib/git.js | 15 +++------------ package.json | 3 +-- src/constants.ts | 1 + src/git.ts | 26 ++++++++++++-------------- yarn.lock | 4 ---- 8 files changed, 19 insertions(+), 55 deletions(-) diff --git a/README.md b/README.md index 5e67ab70..468f095a 100644 --- a/README.md +++ b/README.md @@ -50,6 +50,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** | +| `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/__tests__/git.test.ts b/__tests__/git.test.ts index 4b00a934..552ed902 100644 --- a/__tests__/git.test.ts +++ b/__tests__/git.test.ts @@ -4,7 +4,6 @@ process.env["INPUT_FOLDER"] = "build"; import { execute } from "../src/util"; import { init, generateBranch, deploy } from "../src/git"; import {action} from '../src/constants' -import {cp} from '@actions/io'; import _ from 'lodash'; const originalAction = _.cloneDeep(action); @@ -13,10 +12,6 @@ jest.mock("../src/util", () => ({ execute: jest.fn() })); -jest.mock("@actions/io", () => ({ - cp: jest.fn() -})); - describe("git", () => { afterEach(() => { _.assignIn(action, originalAction); @@ -135,26 +130,8 @@ describe("git", () => { const call = await deploy(); - // Includes the call to generateBranch - expect(execute).toBeCalledTimes(15); - expect(cp).toBeCalledTimes(1) - expect(call).toBe('Commit step complete...') - }) - - it('should execute six commands if root is used', async () => { - Object.assign(action, { - build: '.', - gitHubToken: '123', - pusher: { - name: 'asd', - email: 'as@cat' - }}) - - const call = await deploy(); - // Includes the call to generateBranch expect(execute).toBeCalledTimes(16); - expect(cp).toBeCalledTimes(0) expect(call).toBe('Commit step complete...') }) }) diff --git a/lib/constants.js b/lib/constants.js index a38706db..7f56fb64 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -24,6 +24,7 @@ exports.action = { accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), baseBranch: core.getInput("BASE_BRANCH") || "master", + clean: core.getInput("CLEAN"), pusher }; // Repository path used for commits/pushes. diff --git a/lib/git.js b/lib/git.js index faa894fd..984c7c13 100644 --- a/lib/git.js +++ b/lib/git.js @@ -17,7 +17,6 @@ var __importStar = (this && this.__importStar) || function (mod) { }; Object.defineProperty(exports, "__esModule", { value: true }); const core = __importStar(require("@actions/core")); -const io_1 = require("@actions/io"); const util_1 = require("./util"); const constants_1 = require("./constants"); /** Generates the branch if it doesn't exist on the remote. @@ -91,17 +90,9 @@ function deploy() { yield util_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace); /* Pushes all of the build files into the deployment directory. - Allows the user to specify the root if '.' is provided. */ - if (constants_1.action.build === constants_1.root) { - // rsync is executed here so the .git and temporary deployment directories don't get duplicated. - yield util_1.execute(`rsync -q -av --progress ${constants_1.action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`, constants_1.workspace); - } - else { - yield io_1.cp(`${constants_1.action.build}/.`, temporaryDeploymentDirectory, { - recursive: true, - force: true - }); - } + 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); 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 b862a333..466ab7db 100644 --- a/package.json +++ b/package.json @@ -34,8 +34,7 @@ "dependencies": { "@actions/core": "^1.0.0", "@actions/exec": "^1.0.1", - "@actions/github": "^1.1.0", - "@actions/io": "^1.0.1" + "@actions/github": "^1.1.0" }, "devDependencies": { "@types/jest": "^24.0.23", diff --git a/src/constants.ts b/src/constants.ts index 8d546be5..9d10dc12 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,6 +19,7 @@ export const action = { accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), baseBranch: core.getInput("BASE_BRANCH") || "master", + clean: core.getInput("CLEAN"), pusher }; diff --git a/src/git.ts b/src/git.ts index 4d94d58f..f3fa36dc 100644 --- a/src/git.ts +++ b/src/git.ts @@ -1,5 +1,4 @@ import * as core from "@actions/core"; -import { cp } from "@actions/io"; import { execute } from "./util"; import { workspace, action, root, repositoryPath, isTest } from "./constants"; @@ -85,19 +84,18 @@ export async function deploy(): Promise { /* Pushes all of the build files into the deployment directory. - Allows the user to specify the root if '.' is provided. */ - if (action.build === root) { - // rsync is executed here so the .git and temporary deployment directories don't get duplicated. - await execute( - `rsync -q -av --progress ${action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`, - workspace - ); - } else { - await cp(`${action.build}/.`, temporaryDeploymentDirectory, { - recursive: true, - force: true - }); - } + 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} ${ + action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : "" + } --exclude .git --exclude .github ${ + action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : "" + }`, + workspace + ); const hasFilesToCommit = await execute( `git status --porcelain`, diff --git a/yarn.lock b/yarn.lock index ac70f604..176b65c0 100644 --- a/yarn.lock +++ b/yarn.lock @@ -17,10 +17,6 @@ "@octokit/graphql" "^2.0.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" From c4cfbc80af945d2f04eb79eab00a41a493c30ecb Mon Sep 17 00:00:00 2001 From: James Ives Date: Fri, 22 Nov 2019 10:01:06 -0500 Subject: [PATCH 4/8] Pusher is undefined in scheduled jobs (#62) * Fallback for name and email * Build --- lib/constants.js | 12 ++++++++++-- lib/git.js | 4 ++-- src/constants.ts | 14 ++++++++++++-- src/git.ts | 4 ++-- 4 files changed, 26 insertions(+), 8 deletions(-) diff --git a/lib/constants.js b/lib/constants.js index 7f56fb64..a08e2b12 100644 --- a/lib/constants.js +++ b/lib/constants.js @@ -24,8 +24,16 @@ exports.action = { accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), baseBranch: core.getInput("BASE_BRANCH") || "master", - clean: core.getInput("CLEAN"), - pusher + name: pusher && pusher.name + ? pusher.name + : process.env.GITHUB_ACTOR + ? process.env.GITHUB_ACTOR + : "GitHub Pages Deploy Action", + email: pusher && pusher.email + ? pusher.email + : `${process.env.GITHUB_ACTOR || + "github-pages-deploy-action"}@users.noreply.github.com`, + clean: core.getInput("CLEAN") }; // Repository path used for commits/pushes. exports.repositoryPath = `https://${exports.action.accessToken || diff --git a/lib/git.js b/lib/git.js index 984c7c13..81fbe162 100644 --- a/lib/git.js +++ b/lib/git.js @@ -32,8 +32,8 @@ function init() { return core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`); } yield util_1.execute(`git init`, constants_1.workspace); - yield util_1.execute(`git config user.name ${constants_1.action.pusher.name}`, constants_1.workspace); - yield util_1.execute(`git config user.email ${constants_1.action.pusher.email}`, constants_1.workspace); + yield util_1.execute(`git config user.name ${constants_1.action.name}`, constants_1.workspace); + yield util_1.execute(`git config user.email ${constants_1.action.email}`, constants_1.workspace); } catch (error) { core.setFailed(`There was an error initializing the repository: ${error}`); diff --git a/src/constants.ts b/src/constants.ts index 9d10dc12..1d448f06 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -19,8 +19,18 @@ export const action = { accessToken: core.getInput("ACCESS_TOKEN"), branch: core.getInput("BRANCH"), baseBranch: core.getInput("BASE_BRANCH") || "master", - clean: core.getInput("CLEAN"), - pusher + name: + pusher && pusher.name + ? pusher.name + : process.env.GITHUB_ACTOR + ? process.env.GITHUB_ACTOR + : "GitHub Pages Deploy Action", + email: + pusher && pusher.email + ? pusher.email + : `${process.env.GITHUB_ACTOR || + "github-pages-deploy-action"}@users.noreply.github.com`, + clean: core.getInput("CLEAN") }; // Repository path used for commits/pushes. diff --git a/src/git.ts b/src/git.ts index f3fa36dc..62aaa867 100644 --- a/src/git.ts +++ b/src/git.ts @@ -20,8 +20,8 @@ export async function init(): Promise { } await execute(`git init`, workspace); - await execute(`git config user.name ${action.pusher.name}`, workspace); - await execute(`git config user.email ${action.pusher.email}`, workspace); + await execute(`git config user.name ${action.name}`, workspace); + await execute(`git config user.email ${action.email}`, workspace); } catch (error) { core.setFailed(`There was an error initializing the repository: ${error}`); } finally { From f23e0621a6d8cdadac36431a8b0091f9190e93e1 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2019 10:01:17 -0500 Subject: [PATCH 5/8] Bump @actions/core from 1.1.3 to 1.2.0 (#49) Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.1.3 to 1.2.0. - [Release notes](https://github.com/actions/toolkit/releases) - [Changelog](https://github.com/actions/toolkit/blob/master/packages/core/RELEASES.md) - [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 466ab7db..02001c7e 100644 --- a/package.json +++ b/package.json @@ -32,7 +32,7 @@ "author": "James Ives", "license": "MIT", "dependencies": { - "@actions/core": "^1.0.0", + "@actions/core": "^1.2.0", "@actions/exec": "^1.0.1", "@actions/github": "^1.1.0" }, diff --git a/yarn.lock b/yarn.lock index 176b65c0..6418de44 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,9 +2,9 @@ # yarn lockfile v1 -"@actions/core@^1.0.0": - version "1.1.3" - resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.1.3.tgz#543b0e7ca0e53dccc5dca4811a4fac59c1b35f5c" +"@actions/core@^1.2.0": + 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" From 1f581c7e5610030309aa5a48b42f6790aa11868a Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2019 10:01:34 -0500 Subject: [PATCH 6/8] Bump prettier from 1.18.2 to 1.19.1 (#50) Bumps [prettier](https://github.com/prettier/prettier) from 1.18.2 to 1.19.1. - [Release notes](https://github.com/prettier/prettier/releases) - [Changelog](https://github.com/prettier/prettier/blob/master/CHANGELOG.md) - [Commits](https://github.com/prettier/prettier/compare/1.18.2...1.19.1) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 02001c7e..8b091e88 100644 --- a/package.json +++ b/package.json @@ -42,7 +42,7 @@ "jest": "^24.8.0", "jest-circus": "^24.7.1", "lodash": "^4.17.15", - "prettier": "^1.18.2", + "prettier": "^1.19.1", "ts-jest": "^24.0.2", "tslint": "^5.20.0", "typescript": "^3.5.1" diff --git a/yarn.lock b/yarn.lock index 6418de44..b2aeea8c 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2506,9 +2506,9 @@ prelude-ls@~1.1.2: version "1.1.2" resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54" -prettier@^1.18.2: - version "1.18.2" - resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea" +prettier@^1.19.1: + version "1.19.1" + resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb" pretty-format@^24.9.0: version "24.9.0" From bbe900e6c8cfe329c22db9d28c1114c77a1fc6e2 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2019 10:01:45 -0500 Subject: [PATCH 7/8] Bump typescript from 3.6.4 to 3.7.2 (#52) Bumps [typescript](https://github.com/Microsoft/TypeScript) from 3.6.4 to 3.7.2. - [Release notes](https://github.com/Microsoft/TypeScript/releases) - [Commits](https://github.com/Microsoft/TypeScript/compare/v3.6.4...v3.7.2) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 8b091e88..7ec4c65a 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,6 @@ "prettier": "^1.19.1", "ts-jest": "^24.0.2", "tslint": "^5.20.0", - "typescript": "^3.5.1" + "typescript": "^3.7.2" } } diff --git a/yarn.lock b/yarn.lock index b2aeea8c..42a07ce8 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3133,9 +3133,9 @@ type-check@~0.3.2: dependencies: prelude-ls "~1.1.2" -typescript@^3.5.1: - version "3.6.4" - resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d" +typescript@^3.7.2: + version "3.7.2" + resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb" uglify-js@^3.1.4: version "3.6.8" From a657e347566dc848ed9271689ce0fa3d55398c53 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Fri, 22 Nov 2019 10:01:56 -0500 Subject: [PATCH 8/8] Bump @types/node from 12.12.9 to 12.12.11 (#57) Bumps [@types/node](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/node) from 12.12.9 to 12.12.11. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/node) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- yarn.lock | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 7ec4c65a..b8c732d5 100644 --- a/package.json +++ b/package.json @@ -38,7 +38,7 @@ }, "devDependencies": { "@types/jest": "^24.0.23", - "@types/node": "^12.12.9", + "@types/node": "^12.12.11", "jest": "^24.8.0", "jest-circus": "^24.7.1", "lodash": "^4.17.15", diff --git a/yarn.lock b/yarn.lock index 42a07ce8..fcdca3a2 100644 --- a/yarn.lock +++ b/yarn.lock @@ -387,9 +387,9 @@ dependencies: jest-diff "^24.3.0" -"@types/node@>= 8", "@types/node@^12.12.9": - version "12.12.9" - resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.9.tgz#0b5ae05516b757cbff2e82c04500190aef986c7b" +"@types/node@>= 8", "@types/node@^12.12.11": + version "12.12.11" + resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.11.tgz#bec2961975888d964196bf0016a2f984d793d3ce" "@types/stack-utils@^1.0.1": version "1.0.1"