mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
Merge branch 'dev' into releases/v3
This commit is contained in:
commit
5a75f19ce1
@ -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** |
|
| `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** |
|
| `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** |
|
| `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.
|
With the action correctly configured you should see the workflow trigger the deployment under the configured conditions.
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ process.env["INPUT_FOLDER"] = "build";
|
|||||||
import { execute } from "../src/util";
|
import { execute } from "../src/util";
|
||||||
import { init, generateBranch, deploy } from "../src/git";
|
import { init, generateBranch, deploy } from "../src/git";
|
||||||
import {action} from '../src/constants'
|
import {action} from '../src/constants'
|
||||||
import {cp} from '@actions/io';
|
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
const originalAction = _.cloneDeep(action);
|
const originalAction = _.cloneDeep(action);
|
||||||
@ -13,10 +12,6 @@ jest.mock("../src/util", () => ({
|
|||||||
execute: jest.fn()
|
execute: jest.fn()
|
||||||
}));
|
}));
|
||||||
|
|
||||||
jest.mock("@actions/io", () => ({
|
|
||||||
cp: jest.fn()
|
|
||||||
}));
|
|
||||||
|
|
||||||
describe("git", () => {
|
describe("git", () => {
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
_.assignIn(action, originalAction);
|
_.assignIn(action, originalAction);
|
||||||
@ -135,26 +130,8 @@ describe("git", () => {
|
|||||||
|
|
||||||
const call = await deploy();
|
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
|
// Includes the call to generateBranch
|
||||||
expect(execute).toBeCalledTimes(16);
|
expect(execute).toBeCalledTimes(16);
|
||||||
expect(cp).toBeCalledTimes(0)
|
|
||||||
expect(call).toBe('Commit step complete...')
|
expect(call).toBe('Commit step complete...')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -24,7 +24,16 @@ exports.action = {
|
|||||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||||
branch: core.getInput("BRANCH"),
|
branch: core.getInput("BRANCH"),
|
||||||
baseBranch: core.getInput("BASE_BRANCH") || "master",
|
baseBranch: core.getInput("BASE_BRANCH") || "master",
|
||||||
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.
|
// Repository path used for commits/pushes.
|
||||||
exports.repositoryPath = `https://${exports.action.accessToken ||
|
exports.repositoryPath = `https://${exports.action.accessToken ||
|
||||||
|
19
lib/git.js
19
lib/git.js
@ -17,7 +17,6 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|||||||
};
|
};
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const core = __importStar(require("@actions/core"));
|
const core = __importStar(require("@actions/core"));
|
||||||
const io_1 = require("@actions/io");
|
|
||||||
const util_1 = require("./util");
|
const util_1 = require("./util");
|
||||||
const constants_1 = require("./constants");
|
const constants_1 = require("./constants");
|
||||||
/** Generates the branch if it doesn't exist on the remote.
|
/** Generates the branch if it doesn't exist on the remote.
|
||||||
@ -33,8 +32,8 @@ function init() {
|
|||||||
return core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`);
|
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 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.name ${constants_1.action.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.email ${constants_1.action.email}`, constants_1.workspace);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(`There was an error initializing the repository: ${error}`);
|
core.setFailed(`There was an error initializing the repository: ${error}`);
|
||||||
@ -91,17 +90,9 @@ function deploy() {
|
|||||||
yield util_1.execute(`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${constants_1.action.branch}`, constants_1.workspace);
|
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.
|
Pushes all of the build files into the deployment directory.
|
||||||
Allows the user to specify the root if '.' is provided. */
|
Allows the user to specify the root if '.' is provided.
|
||||||
if (constants_1.action.build === constants_1.root) {
|
rysync is used to prevent file duplication. */
|
||||||
// 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} ${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}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`, constants_1.workspace);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
yield io_1.cp(`${constants_1.action.build}/.`, temporaryDeploymentDirectory, {
|
|
||||||
recursive: true,
|
|
||||||
force: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
|
const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
|
||||||
if (!hasFilesToCommit && !constants_1.isTest) {
|
if (!hasFilesToCommit && !constants_1.isTest) {
|
||||||
console.log("There is nothing to commit. Exiting...");
|
console.log("There is nothing to commit. Exiting...");
|
||||||
|
11
package.json
11
package.json
@ -32,20 +32,19 @@
|
|||||||
"author": "James Ives",
|
"author": "James Ives",
|
||||||
"license": "MIT",
|
"license": "MIT",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.0.0",
|
"@actions/core": "^1.2.0",
|
||||||
"@actions/exec": "^1.0.1",
|
"@actions/exec": "^1.0.1",
|
||||||
"@actions/github": "^1.1.0",
|
"@actions/github": "^1.1.0"
|
||||||
"@actions/io": "^1.0.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/jest": "^24.0.23",
|
"@types/jest": "^24.0.23",
|
||||||
"@types/node": "^12.12.9",
|
"@types/node": "^12.12.11",
|
||||||
"jest": "^24.8.0",
|
"jest": "^24.8.0",
|
||||||
"jest-circus": "^24.7.1",
|
"jest-circus": "^24.7.1",
|
||||||
"lodash": "^4.17.15",
|
"lodash": "^4.17.15",
|
||||||
"prettier": "^1.18.2",
|
"prettier": "^1.19.1",
|
||||||
"ts-jest": "^24.0.2",
|
"ts-jest": "^24.0.2",
|
||||||
"tslint": "^5.20.0",
|
"tslint": "^5.20.0",
|
||||||
"typescript": "^3.5.1"
|
"typescript": "^3.7.2"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,18 @@ export const action = {
|
|||||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||||
branch: core.getInput("BRANCH"),
|
branch: core.getInput("BRANCH"),
|
||||||
baseBranch: core.getInput("BASE_BRANCH") || "master",
|
baseBranch: core.getInput("BASE_BRANCH") || "master",
|
||||||
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.
|
// Repository path used for commits/pushes.
|
||||||
|
30
src/git.ts
30
src/git.ts
@ -1,5 +1,4 @@
|
|||||||
import * as core from "@actions/core";
|
import * as core from "@actions/core";
|
||||||
import { cp } from "@actions/io";
|
|
||||||
import { execute } from "./util";
|
import { execute } from "./util";
|
||||||
import { workspace, action, root, repositoryPath, isTest } from "./constants";
|
import { workspace, action, root, repositoryPath, isTest } from "./constants";
|
||||||
|
|
||||||
@ -21,8 +20,8 @@ export async function init(): Promise<any> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
await execute(`git init`, workspace);
|
await execute(`git init`, workspace);
|
||||||
await execute(`git config user.name ${action.pusher.name}`, workspace);
|
await execute(`git config user.name ${action.name}`, workspace);
|
||||||
await execute(`git config user.email ${action.pusher.email}`, workspace);
|
await execute(`git config user.email ${action.email}`, workspace);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(`There was an error initializing the repository: ${error}`);
|
core.setFailed(`There was an error initializing the repository: ${error}`);
|
||||||
} finally {
|
} finally {
|
||||||
@ -85,19 +84,18 @@ export async function deploy(): Promise<any> {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Pushes all of the build files into the deployment directory.
|
Pushes all of the build files into the deployment directory.
|
||||||
Allows the user to specify the root if '.' is provided. */
|
Allows the user to specify the root if '.' is provided.
|
||||||
if (action.build === root) {
|
rysync is used to prevent file duplication. */
|
||||||
// rsync is executed here so the .git and temporary deployment directories don't get duplicated.
|
await execute(
|
||||||
await execute(
|
`rsync -q -av --progress ${
|
||||||
`rsync -q -av --progress ${action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude .github --exclude ${temporaryDeploymentDirectory}`,
|
action.build
|
||||||
workspace
|
}/. ${temporaryDeploymentDirectory} ${
|
||||||
);
|
action.clean ? `--delete --exclude CNAME --exclude .nojekyll` : ""
|
||||||
} else {
|
} --exclude .git --exclude .github ${
|
||||||
await cp(`${action.build}/.`, temporaryDeploymentDirectory, {
|
action.build === root ? `--exclude ${temporaryDeploymentDirectory}` : ""
|
||||||
recursive: true,
|
}`,
|
||||||
force: true
|
workspace
|
||||||
});
|
);
|
||||||
}
|
|
||||||
|
|
||||||
const hasFilesToCommit = await execute(
|
const hasFilesToCommit = await execute(
|
||||||
`git status --porcelain`,
|
`git status --porcelain`,
|
||||||
|
28
yarn.lock
28
yarn.lock
@ -2,9 +2,9 @@
|
|||||||
# yarn lockfile v1
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
"@actions/core@^1.0.0":
|
"@actions/core@^1.2.0":
|
||||||
version "1.1.3"
|
version "1.2.0"
|
||||||
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.1.3.tgz#543b0e7ca0e53dccc5dca4811a4fac59c1b35f5c"
|
resolved "https://registry.yarnpkg.com/@actions/core/-/core-1.2.0.tgz#aa5f52b26c362c821d41557e599371a42f6c0b3d"
|
||||||
|
|
||||||
"@actions/exec@^1.0.1":
|
"@actions/exec@^1.0.1":
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
@ -17,10 +17,6 @@
|
|||||||
"@octokit/graphql" "^2.0.1"
|
"@octokit/graphql" "^2.0.1"
|
||||||
"@octokit/rest" "^16.15.0"
|
"@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":
|
"@babel/code-frame@^7.0.0", "@babel/code-frame@^7.5.5":
|
||||||
version "7.5.5"
|
version "7.5.5"
|
||||||
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
|
resolved "https://registry.yarnpkg.com/@babel/code-frame/-/code-frame-7.5.5.tgz#bc0782f6d69f7b7d49531219699b988f669a8f9d"
|
||||||
@ -391,9 +387,9 @@
|
|||||||
dependencies:
|
dependencies:
|
||||||
jest-diff "^24.3.0"
|
jest-diff "^24.3.0"
|
||||||
|
|
||||||
"@types/node@>= 8", "@types/node@^12.12.9":
|
"@types/node@>= 8", "@types/node@^12.12.11":
|
||||||
version "12.12.9"
|
version "12.12.11"
|
||||||
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.9.tgz#0b5ae05516b757cbff2e82c04500190aef986c7b"
|
resolved "https://registry.yarnpkg.com/@types/node/-/node-12.12.11.tgz#bec2961975888d964196bf0016a2f984d793d3ce"
|
||||||
|
|
||||||
"@types/stack-utils@^1.0.1":
|
"@types/stack-utils@^1.0.1":
|
||||||
version "1.0.1"
|
version "1.0.1"
|
||||||
@ -2510,9 +2506,9 @@ prelude-ls@~1.1.2:
|
|||||||
version "1.1.2"
|
version "1.1.2"
|
||||||
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
resolved "https://registry.yarnpkg.com/prelude-ls/-/prelude-ls-1.1.2.tgz#21932a549f5e52ffd9a827f570e04be62a97da54"
|
||||||
|
|
||||||
prettier@^1.18.2:
|
prettier@^1.19.1:
|
||||||
version "1.18.2"
|
version "1.19.1"
|
||||||
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.18.2.tgz#6823e7c5900017b4bd3acf46fe9ac4b4d7bda9ea"
|
resolved "https://registry.yarnpkg.com/prettier/-/prettier-1.19.1.tgz#f7d7f5ff8a9cd872a7be4ca142095956a60797cb"
|
||||||
|
|
||||||
pretty-format@^24.9.0:
|
pretty-format@^24.9.0:
|
||||||
version "24.9.0"
|
version "24.9.0"
|
||||||
@ -3137,9 +3133,9 @@ type-check@~0.3.2:
|
|||||||
dependencies:
|
dependencies:
|
||||||
prelude-ls "~1.1.2"
|
prelude-ls "~1.1.2"
|
||||||
|
|
||||||
typescript@^3.5.1:
|
typescript@^3.7.2:
|
||||||
version "3.6.4"
|
version "3.7.2"
|
||||||
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.6.4.tgz#b18752bb3792bc1a0281335f7f6ebf1bbfc5b91d"
|
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.7.2.tgz#27e489b95fa5909445e9fef5ee48d81697ad18fb"
|
||||||
|
|
||||||
uglify-js@^3.1.4:
|
uglify-js@^3.1.4:
|
||||||
version "3.6.8"
|
version "3.6.8"
|
||||||
|
Loading…
Reference in New Issue
Block a user