Some more simplification

This commit is contained in:
James Ives 2019-11-10 14:03:17 -05:00
parent f81e60d8ad
commit 8e95d27a60
2 changed files with 48 additions and 24 deletions

View File

@ -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.
@ -32,9 +31,9 @@ function init() {
if (constants_1.action.build.startsWith("/") || constants_1.action.build.startsWith("./")) { 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.`); 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.action.build);
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.pusher.name}`, constants_1.action.build);
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.pusher.email}`, constants_1.action.build);
} }
catch (error) { catch (error) {
core.setFailed(`There was an error initializing the repository: ${error}`); core.setFailed(`There was an error initializing the repository: ${error}`);
@ -86,21 +85,36 @@ function deploy() {
// Checks out the base branch to begin the deployment process. // Checks out the base branch to begin the deployment process.
yield util_1.execute(`git switch ${constants_1.action.baseBranch || "master"}`, constants_1.workspace); yield util_1.execute(`git switch ${constants_1.action.baseBranch || "master"}`, constants_1.workspace);
yield util_1.execute(`git fetch origin`, 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); yield util_1.execute(`git add --all .`, constants_1.action.build);
// Removes the git folder prior to moving. yield util_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, constants_1.action.build);
yield io_1.rmRF(`${constants_1.action.build}/.git`); yield util_1.execute(`git push --force ${constants_1.repositoryPath} ${constants_1.action.baseBranch}:${constants_1.action.branch}`, constants_1.action.build);
/*
await execute(
`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`,
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.
yield io_1.cp(`${constants_1.action.build}/.`, temporaryDeploymentDirectory, { await cp(`${action.build}/.`, temporaryDeploymentDirectory, {
recursive: true, recursive: true,
force: true force: true
}); });
// Commits to GitHub. // Commits to GitHub.
yield util_1.execute(`git add --all .`, temporaryDeploymentDirectory); await execute(`git add --all .`, temporaryDeploymentDirectory);
yield util_1.execute(`git switch -c ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory); await execute(
yield util_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, temporaryDeploymentDirectory); `git switch -c ${temporaryDeploymentBranch}`,
yield util_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory); temporaryDeploymentDirectory
);
await execute(
`git commit -m "Deploying to ${action.branch} from ${action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`,
temporaryDeploymentDirectory
);
await execute(
`git push --force ${repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`,
temporaryDeploymentDirectory
);*/
return Promise.resolve("Commit step complete..."); return Promise.resolve("Commit step complete...");
}); });
} }

View File

@ -20,9 +20,9 @@ export async function init(): Promise<any> {
); );
} }
await execute(`git init`, workspace); await execute(`git init`, action.build);
await execute(`git config user.name ${action.pusher.name}`, workspace); await execute(`git config user.name ${action.pusher.name}`, action.build);
await execute(`git config user.email ${action.pusher.email}`, workspace); await execute(`git config user.email ${action.pusher.email}`, action.build);
} 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 {
@ -76,17 +76,26 @@ export async function deploy(): Promise<any> {
// Checks out the base branch to begin the deployment process. // Checks out the base branch to begin the deployment process.
await execute(`git switch ${action.baseBranch || "master"}`, workspace); await execute(`git switch ${action.baseBranch || "master"}`, workspace);
await execute(`git fetch origin`, workspace); await execute(`git fetch origin`, workspace);
await execute(`git add --all .`, action.build);
await execute( await execute(
`git worktree add --checkout ${temporaryDeploymentDirectory} origin/${action.branch}`, `git commit -m "Deploying to ${action.branch} from ${action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`,
workspace action.build
); );
// Removes the git folder prior to moving. await execute(
await rmRF(`${action.build}/.git`) `git push --force ${repositoryPath} ${action.baseBranch}:${action.branch}`,
action.build
);
/*
await execute(
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.
await cp(`${action.build}/.`, temporaryDeploymentDirectory, { await cp(`${action.build}/.`, temporaryDeploymentDirectory, {
recursive: true, recursive: true,
force: true force: true
@ -105,7 +114,8 @@ export async function deploy(): Promise<any> {
await execute( await execute(
`git push --force ${repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`, `git push --force ${repositoryPath} ${temporaryDeploymentBranch}:${action.branch}`,
temporaryDeploymentDirectory temporaryDeploymentDirectory
); );*/
return Promise.resolve("Commit step complete..."); return Promise.resolve("Commit step complete...");
} }