mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
no guess
This commit is contained in:
parent
28ed73f2fd
commit
8a6a3ab51b
@ -11,10 +11,9 @@ const core = __importStar(require("@actions/core"));
|
||||
const github = __importStar(require("@actions/github"));
|
||||
const { pusher, repository } = github.context.payload;
|
||||
exports.workspace = process.env.GITHUB_WORKSPACE;
|
||||
// The build folder that stores the deployment data.
|
||||
exports.build = core.getInput("FOLDER", { required: true });
|
||||
// Required action data.
|
||||
exports.action = {
|
||||
build: core.getInput("FOLDER", { required: true }),
|
||||
gitHubRepository: repository ? repository.full_name : "",
|
||||
gitHubToken: core.getInput("GITHUB_TOKEN"),
|
||||
accessToken: core.getInput("ACCESS_TOKEN"),
|
||||
|
53
lib/git.js
53
lib/git.js
@ -20,17 +20,17 @@ 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. */
|
||||
/** Generates the branch if it doesn't exist on the remote.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function init() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
const accessToken = core.getInput("ACCESS_TOKEN");
|
||||
const gitHubToken = core.getInput("GITHUB_TOKEN");
|
||||
if (!accessToken && !gitHubToken) {
|
||||
core.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy.");
|
||||
if (!constants_1.action.accessToken && !constants_1.action.gitHubToken) {
|
||||
return core.setFailed("You must provide the action with either a Personal Access Token or the GitHub Token secret in order to deploy.");
|
||||
}
|
||||
if (constants_1.build.startsWith("/") || constants_1.build.startsWith("./")) {
|
||||
core.setFailed(`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`);
|
||||
if (constants_1.action.build.startsWith("/") || constants_1.action.build.startsWith("./")) {
|
||||
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);
|
||||
@ -40,18 +40,20 @@ function init() {
|
||||
core.setFailed(`There was an error initializing the repository: ${error}`);
|
||||
}
|
||||
finally {
|
||||
Promise.resolve("Initializion Step Complete...");
|
||||
return Promise.resolve("Initialization step complete...");
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.init = init;
|
||||
/** Generates the branch if it doesn't exist on the remote. */
|
||||
/** Generates the branch if it doesn't exist on the remote.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function generateBranch() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
console.log(`Creating ${constants_1.action.branch} branch...`);
|
||||
yield util_1.execute(`git checkout ${constants_1.action.baseBranch || "master"}`, constants_1.workspace);
|
||||
yield util_1.execute(`git checkout --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
||||
yield util_1.execute(`git checkout ${constants_1.action.baseBranch || "master"} ---`, constants_1.workspace);
|
||||
yield util_1.execute(`git checkout --orphan ${constants_1.action.branch} ---`, constants_1.workspace);
|
||||
yield util_1.execute(`git reset --hard`, constants_1.workspace);
|
||||
yield util_1.execute(`git commit --allow-empty -m "Initial ${constants_1.action.branch} commit."`, constants_1.workspace);
|
||||
yield util_1.execute(`git push ${constants_1.repositoryPath} ${constants_1.action.branch}`, constants_1.workspace);
|
||||
@ -60,39 +62,44 @@ function generateBranch() {
|
||||
core.setFailed(`There was an error creating the deployment branch: ${error}`);
|
||||
}
|
||||
finally {
|
||||
Promise.resolve("Deployment branch creation step complete...");
|
||||
return Promise.resolve("Deployment branch creation step complete...");
|
||||
}
|
||||
});
|
||||
}
|
||||
exports.generateBranch = generateBranch;
|
||||
/** Runs the neccersary steps to make the deployment. */
|
||||
/** Runs the necessary steps to make the deployment.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
function deploy() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
const temporaryDeploymentDirectory = 'temp-deployment-folder';
|
||||
const temporaryDeploymentBranch = 'temp-deployment-branch';
|
||||
const temporaryDeploymentDirectory = "temp-deployment-folder";
|
||||
const temporaryDeploymentBranch = "temp-deployment-branch";
|
||||
/*
|
||||
Checks to see if the remote exists prior to deploying.
|
||||
If the branch doesn't exist it gets created here as an orphan.
|
||||
*/
|
||||
Checks to see if the remote exists prior to deploying.
|
||||
If the branch doesn't exist it gets created here as an orphan.
|
||||
*/
|
||||
const branchExists = yield util_1.execute(`git ls-remote --heads ${constants_1.repositoryPath} ${constants_1.action.branch} | wc -l`, constants_1.workspace);
|
||||
if (!branchExists) {
|
||||
console.log('Deployment branch does not exist. Creating....');
|
||||
console.log("Deployment branch does not exist. Creating....");
|
||||
yield generateBranch();
|
||||
}
|
||||
// Checks out the base branch to begin the deployment process.
|
||||
yield util_1.execute(`git checkout ${constants_1.action.baseBranch || 'master'}`, constants_1.workspace);
|
||||
yield util_1.execute(`git checkout ${constants_1.action.baseBranch || "master"} ---`, constants_1.workspace);
|
||||
yield util_1.execute(`git fetch origin`, 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.
|
||||
Allows the user to specify the root if '.' is provided. */
|
||||
yield io_1.cp(`${constants_1.build}/.`, temporaryDeploymentDirectory, { recursive: true, force: true });
|
||||
yield io_1.cp(`${constants_1.action.build}/.`, temporaryDeploymentDirectory, {
|
||||
recursive: true,
|
||||
force: true
|
||||
});
|
||||
// Commits to GitHub.
|
||||
yield util_1.execute(`git add --all .`, temporaryDeploymentDirectory);
|
||||
yield util_1.execute(`git checkout -b ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
|
||||
yield util_1.execute(`git checkout -b ${temporaryDeploymentBranch} ---`, temporaryDeploymentDirectory);
|
||||
yield util_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, temporaryDeploymentDirectory);
|
||||
yield util_1.execute(`git push ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
|
||||
return Promise.resolve('Files commit step complete...');
|
||||
return Promise.resolve("Commit step complete...");
|
||||
});
|
||||
}
|
||||
exports.deploy = deploy;
|
||||
|
@ -18,13 +18,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const core = __importStar(require("@actions/core"));
|
||||
const git_1 = require("./git");
|
||||
/** Initializes and runs the action.
|
||||
* @returns {Promise}
|
||||
*/
|
||||
/** Initializes and runs the action. */
|
||||
(function () {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
// Initializes the action.
|
||||
yield git_1.init();
|
||||
yield git_1.deploy();
|
||||
}
|
||||
@ -32,7 +29,7 @@ const git_1 = require("./git");
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
finally {
|
||||
console.log("Deployment Successful!");
|
||||
console.log("Completed Deployment");
|
||||
}
|
||||
});
|
||||
})();
|
||||
|
@ -18,13 +18,13 @@ const exec_1 = require("@actions/exec");
|
||||
*/
|
||||
function execute(cmd, cwd) {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
let output = '';
|
||||
let output = "";
|
||||
yield exec_1.exec(cmd, [], {
|
||||
cwd,
|
||||
listeners: {
|
||||
stdout: (data) => {
|
||||
output += data.toString().trim();
|
||||
},
|
||||
}
|
||||
}
|
||||
});
|
||||
return Promise.resolve(output);
|
||||
|
@ -36,8 +36,8 @@ export async function init(): Promise<any> {
|
||||
export async function generateBranch(): Promise<any> {
|
||||
try {
|
||||
console.log(`Creating ${action.branch} branch...`);
|
||||
await execute(`git checkout ${action.baseBranch || "master"}`, workspace);
|
||||
await execute(`git checkout --orphan ${action.branch}`, workspace);
|
||||
await execute(`git checkout ${action.baseBranch || "master"} ---`, workspace);
|
||||
await execute(`git checkout --orphan ${action.branch} ---`, workspace);
|
||||
await execute(`git reset --hard`, workspace);
|
||||
await execute(
|
||||
`git commit --allow-empty -m "Initial ${action.branch} commit."`,
|
||||
@ -74,7 +74,7 @@ export async function deploy(): Promise<any> {
|
||||
}
|
||||
|
||||
// Checks out the base branch to begin the deployment process.
|
||||
await execute(`git checkout ${action.baseBranch || "master"}`, workspace);
|
||||
await execute(`git checkout ${action.baseBranch || "master"} ---`, workspace);
|
||||
await execute(`git fetch origin`, workspace);
|
||||
await execute(
|
||||
`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`,
|
||||
@ -92,7 +92,7 @@ export async function deploy(): Promise<any> {
|
||||
// Commits to GitHub.
|
||||
await execute(`git add --all .`, temporaryDeploymentDirectory);
|
||||
await execute(
|
||||
`git checkout -b ${temporaryDeploymentBranch}`,
|
||||
`git checkout -b ${temporaryDeploymentBranch} ---`,
|
||||
temporaryDeploymentDirectory
|
||||
);
|
||||
await execute(
|
||||
|
Loading…
Reference in New Issue
Block a user