Fixes root deployment

This commit is contained in:
James Ives 2019-11-10 16:31:05 -05:00
parent ae89c8d79b
commit a4594d3404
5 changed files with 63 additions and 21 deletions

View File

@ -98,24 +98,64 @@ describe("git", () => {
expect(execute).toBeCalledTimes(0);
expect(call).toBe('Initialization step complete...')
})
it("should not fail if root is used", async () => {
Object.assign(action, {
accessToken: '123',
build: '.',
pusher: {
name: 'asd',
email: 'as@cat'
}})
const call = await init()
expect(execute).toBeCalledTimes(3);
expect(call).toBe('Initialization step complete...')
})
});
describe('generateBranch', () => {
it('should execute five commands', async () => {
const call = await generateBranch();
expect(execute).toBeCalledTimes(5);
expect(execute).toBeCalledTimes(6);
expect(call).toBe('Deployment branch creation step complete...')
})
})
describe('deploy', () => {
it('should execute five commands', async () => {
Object.assign(action, {
build: 'build',
gitHubToken: '123',
pusher: {
name: 'asd',
email: 'as@cat'
}})
const call = await deploy();
// Includes the call to generateBranch
expect(execute).toBeCalledTimes(13);
expect(execute).toBeCalledTimes(14);
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(15);
expect(cp).toBeCalledTimes(0)
expect(call).toBe('Commit step complete...')
})
})
});

View File

@ -12,6 +12,7 @@ const github = __importStar(require("@actions/github"));
const { pusher, repository } = github.context.payload;
exports.workspace = process.env.GITHUB_WORKSPACE;
exports.folder = core.getInput("FOLDER", { required: true });
exports.root = ".";
// Required action data.
exports.action = {
build: exports.folder,

View File

@ -29,11 +29,9 @@ function init() {
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 (action.build.startsWith("/") || action.build.startsWith("./")) {
return 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);
yield util_1.execute(`git config user.email ${constants_1.action.pusher.email}`, constants_1.workspace);
@ -76,8 +74,8 @@ exports.generateBranch = generateBranch;
*/
function deploy() {
return __awaiter(this, void 0, void 0, function* () {
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder';
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch';
const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
const temporaryDeploymentBranch = "gh-action-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.
@ -94,7 +92,8 @@ function deploy() {
/*
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 === '.') {
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 -av --progress ${constants_1.action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude ${temporaryDeploymentDirectory}`, constants_1.workspace);
}
else {

View File

@ -5,6 +5,7 @@ const { pusher, repository } = github.context.payload;
export const workspace: any = process.env.GITHUB_WORKSPACE;
export const folder = core.getInput("FOLDER", { required: true });
export const root = ".";
// Required action data.
export const action = {

View File

@ -1,7 +1,7 @@
import * as core from "@actions/core";
import { cp, rmRF } from "@actions/io";
import { cp } from "@actions/io";
import { execute } from "./util";
import { workspace, action, repositoryPath } from "./constants";
import { workspace, action, root, repositoryPath } from "./constants";
/** Generates the branch if it doesn't exist on the remote.
* @returns {Promise}
@ -14,11 +14,11 @@ export async function init(): Promise<any> {
);
}
/*if (action.build.startsWith("/") || action.build.startsWith("./")) {
if (action.build.startsWith("/") || action.build.startsWith("./")) {
return core.setFailed(
`The deployment folder cannot be prefixed with '/' or './'. Instead reference the folder name directly.`
);
}*/
}
await execute(`git init`, workspace);
await execute(`git config user.name ${action.pusher.name}`, workspace);
@ -60,8 +60,8 @@ export async function generateBranch(): Promise<any> {
* @returns {Promise}
*/
export async function deploy(): Promise<any> {
const temporaryDeploymentDirectory = 'gh-action-temp-deployment-folder'
const temporaryDeploymentBranch = 'gh-action-temp-deployment-branch'
const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
const temporaryDeploymentBranch = "gh-action-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.
@ -86,15 +86,17 @@ export async function deploy(): Promise<any> {
/*
Pushes all of the build files into the deployment directory.
Allows the user to specify the root if '.' is provided. */
if (action.build === '.') {
await execute(`rsync -av --progress ${action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude ${temporaryDeploymentDirectory}`, workspace)
if (action.build === root) {
// rsync is executed here so the .git and temporary deployment directories don't get duplicated.
await execute(
`rsync -av --progress ${action.build}/. ${temporaryDeploymentDirectory} --exclude .git --exclude ${temporaryDeploymentDirectory}`,
workspace
);
} else {
await cp(`${action.build}/.`, temporaryDeploymentDirectory, {
recursive: true,
force: true
});
}
// Commits to GitHub.
@ -112,6 +114,5 @@ export async function deploy(): Promise<any> {
temporaryDeploymentDirectory
);
return Promise.resolve("Commit step complete...");
}