mirror of
https://github.com/JamesIves/github-pages-deploy-action.git
synced 2023-12-15 20:03:39 +08:00
[Issue-89] Post Deployment Tasks (#90)
* cleanup * Changes * Post cleanup2 * Changes * Update git.test.ts
This commit is contained in:
parent
26a285d416
commit
247dcbb60f
@ -1,5 +1,6 @@
|
|||||||
// Initial env variable setup for tests.
|
// Initial env variable setup for tests.
|
||||||
process.env["INPUT_FOLDER"] = "build";
|
process.env["INPUT_FOLDER"] = "build";
|
||||||
|
process.env["GITHUB_SHA"] = "123"
|
||||||
|
|
||||||
import { execute } from "../src/util";
|
import { execute } from "../src/util";
|
||||||
import { init, generateBranch, deploy } from "../src/git";
|
import { init, generateBranch, deploy } from "../src/git";
|
||||||
@ -114,7 +115,7 @@ describe("git", () => {
|
|||||||
it('should execute five commands', async () => {
|
it('should execute five commands', async () => {
|
||||||
const call = await generateBranch();
|
const call = await generateBranch();
|
||||||
expect(execute).toBeCalledTimes(6);
|
expect(execute).toBeCalledTimes(6);
|
||||||
expect(call).toBe('Deployment branch creation step complete...')
|
expect(call).toBe('Deployment branch creation step complete... ✅')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -131,7 +132,7 @@ describe("git", () => {
|
|||||||
const call = await deploy();
|
const call = await deploy();
|
||||||
|
|
||||||
// Includes the call to generateBranch
|
// Includes the call to generateBranch
|
||||||
expect(execute).toBeCalledTimes(16);
|
expect(execute).toBeCalledTimes(18);
|
||||||
expect(call).toBe('Commit step complete...')
|
expect(call).toBe('Commit step complete...')
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
16
lib/git.js
16
lib/git.js
@ -50,7 +50,7 @@ exports.init = init;
|
|||||||
function generateBranch() {
|
function generateBranch() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
console.log(`Creating ${constants_1.action.branch} branch...`);
|
console.log(`Creating ${constants_1.action.branch} branch... 🔧`);
|
||||||
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 switch --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
yield util_1.execute(`git switch --orphan ${constants_1.action.branch}`, constants_1.workspace);
|
||||||
yield util_1.execute(`git reset --hard`, constants_1.workspace);
|
yield util_1.execute(`git reset --hard`, constants_1.workspace);
|
||||||
@ -60,10 +60,10 @@ function generateBranch() {
|
|||||||
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);
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
core.setFailed(`There was an error creating the deployment branch: ${error}`);
|
core.setFailed(`There was an error creating the deployment branch: ${error} ❌`);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
return Promise.resolve("Deployment branch creation step complete...");
|
return Promise.resolve("Deployment branch creation step complete... ✅");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -96,7 +96,7 @@ function deploy() {
|
|||||||
excludedItems.forEach((item) => (excludes += `--exclude ${item} `));
|
excludedItems.forEach((item) => (excludes += `--exclude ${item} `));
|
||||||
}
|
}
|
||||||
catch (_a) {
|
catch (_a) {
|
||||||
console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details.");
|
console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
/*
|
||||||
@ -110,7 +110,7 @@ function deploy() {
|
|||||||
: ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
|
: ""} --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);
|
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... ✅");
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
// Commits to GitHub.
|
// Commits to GitHub.
|
||||||
@ -118,6 +118,12 @@ function deploy() {
|
|||||||
yield util_1.execute(`git switch -c ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
|
yield util_1.execute(`git switch -c ${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 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 --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
|
yield util_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
|
||||||
|
// Cleans up temporary files/folders and restores the git state.
|
||||||
|
if (process.env.GITHUB_SHA) {
|
||||||
|
console.log("Running post deployment cleanup jobs... 🔧");
|
||||||
|
yield util_1.execute(`rm -rf ${temporaryDeploymentDirectory}`, constants_1.workspace);
|
||||||
|
yield util_1.execute(`git checkout --progress --force ${process.env.GITHUB_SHA}`, constants_1.workspace);
|
||||||
|
}
|
||||||
return Promise.resolve("Commit step complete...");
|
return Promise.resolve("Commit step complete...");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -26,10 +26,11 @@ const git_1 = require("./git");
|
|||||||
yield git_1.deploy();
|
yield git_1.deploy();
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
|
console.log("The deployment encountered an error. ❌");
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
console.log("Completed Deployment");
|
console.log("Completed Deployment ✅");
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
|
20
src/git.ts
20
src/git.ts
@ -34,7 +34,7 @@ export async function init(): Promise<any> {
|
|||||||
*/
|
*/
|
||||||
export async function generateBranch(): Promise<any> {
|
export async function generateBranch(): Promise<any> {
|
||||||
try {
|
try {
|
||||||
console.log(`Creating ${action.branch} branch...`);
|
console.log(`Creating ${action.branch} branch... 🔧`);
|
||||||
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
|
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
|
||||||
await execute(`git switch --orphan ${action.branch}`, workspace);
|
await execute(`git switch --orphan ${action.branch}`, workspace);
|
||||||
await execute(`git reset --hard`, workspace);
|
await execute(`git reset --hard`, workspace);
|
||||||
@ -48,10 +48,10 @@ export async function generateBranch(): Promise<any> {
|
|||||||
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
|
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
`There was an error creating the deployment branch: ${error}`
|
`There was an error creating the deployment branch: ${error} ❌`
|
||||||
);
|
);
|
||||||
} finally {
|
} finally {
|
||||||
return Promise.resolve("Deployment branch creation step complete...");
|
return Promise.resolve("Deployment branch creation step complete... ✅");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,7 +92,7 @@ export async function deploy(): Promise<any> {
|
|||||||
);
|
);
|
||||||
} catch {
|
} catch {
|
||||||
console.log(
|
console.log(
|
||||||
"There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details."
|
"There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details. ❌"
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,7 +122,7 @@ export async function deploy(): Promise<any> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (!hasFilesToCommit && !isTest) {
|
if (!hasFilesToCommit && !isTest) {
|
||||||
console.log("There is nothing to commit. Exiting...");
|
console.log("There is nothing to commit. Exiting... ✅");
|
||||||
return Promise.resolve();
|
return Promise.resolve();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -141,5 +141,15 @@ export async function deploy(): Promise<any> {
|
|||||||
temporaryDeploymentDirectory
|
temporaryDeploymentDirectory
|
||||||
);
|
);
|
||||||
|
|
||||||
|
// Cleans up temporary files/folders and restores the git state.
|
||||||
|
if (process.env.GITHUB_SHA) {
|
||||||
|
console.log("Running post deployment cleanup jobs... 🔧");
|
||||||
|
await execute(`rm -rf ${temporaryDeploymentDirectory}`, workspace);
|
||||||
|
await execute(
|
||||||
|
`git checkout --progress --force ${process.env.GITHUB_SHA}`,
|
||||||
|
workspace
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Promise.resolve("Commit step complete...");
|
return Promise.resolve("Commit step complete...");
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,9 @@ import { init, deploy } from "./git";
|
|||||||
await init();
|
await init();
|
||||||
await deploy();
|
await deploy();
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
console.log("The deployment encountered an error. ❌");
|
||||||
core.setFailed(error.message);
|
core.setFailed(error.message);
|
||||||
} finally {
|
} finally {
|
||||||
console.log("Completed Deployment");
|
console.log("Completed Deployment ✅");
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
Loading…
Reference in New Issue
Block a user