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
6844140a38
@ -1,5 +1,6 @@
|
||||
// Initial env variable setup for tests.
|
||||
process.env["INPUT_FOLDER"] = "build";
|
||||
process.env["GITHUB_SHA"] = "123"
|
||||
|
||||
import { execute } from "../src/util";
|
||||
import { init, generateBranch, deploy } from "../src/git";
|
||||
@ -114,7 +115,7 @@ describe("git", () => {
|
||||
it('should execute five commands', async () => {
|
||||
const call = await generateBranch();
|
||||
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();
|
||||
|
||||
// Includes the call to generateBranch
|
||||
expect(execute).toBeCalledTimes(16);
|
||||
expect(execute).toBeCalledTimes(18);
|
||||
expect(call).toBe('Commit step complete...')
|
||||
})
|
||||
})
|
||||
|
16
lib/git.js
16
lib/git.js
@ -50,7 +50,7 @@ exports.init = init;
|
||||
function generateBranch() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
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 --orphan ${constants_1.action.branch}`, 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);
|
||||
}
|
||||
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 {
|
||||
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} `));
|
||||
}
|
||||
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);
|
||||
const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
|
||||
if (!hasFilesToCommit && !constants_1.isTest) {
|
||||
console.log("There is nothing to commit. Exiting...");
|
||||
console.log("There is nothing to commit. Exiting... ✅");
|
||||
return Promise.resolve();
|
||||
}
|
||||
// Commits to GitHub.
|
||||
@ -118,6 +118,12 @@ function deploy() {
|
||||
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 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...");
|
||||
});
|
||||
}
|
||||
|
@ -26,10 +26,11 @@ const git_1 = require("./git");
|
||||
yield git_1.deploy();
|
||||
}
|
||||
catch (error) {
|
||||
console.log("The deployment encountered an error. ❌");
|
||||
core.setFailed(error.message);
|
||||
}
|
||||
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> {
|
||||
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 --orphan ${action.branch}`, 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);
|
||||
} catch (error) {
|
||||
core.setFailed(
|
||||
`There was an error creating the deployment branch: ${error}`
|
||||
`There was an error creating the deployment branch: ${error} ❌`
|
||||
);
|
||||
} 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 {
|
||||
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) {
|
||||
console.log("There is nothing to commit. Exiting...");
|
||||
console.log("There is nothing to commit. Exiting... ✅");
|
||||
return Promise.resolve();
|
||||
}
|
||||
|
||||
@ -141,5 +141,15 @@ export async function deploy(): Promise<any> {
|
||||
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...");
|
||||
}
|
||||
|
@ -7,8 +7,9 @@ import { init, deploy } from "./git";
|
||||
await init();
|
||||
await deploy();
|
||||
} catch (error) {
|
||||
console.log("The deployment encountered an error. ❌");
|
||||
core.setFailed(error.message);
|
||||
} finally {
|
||||
console.log("Completed Deployment");
|
||||
console.log("Completed Deployment ✅");
|
||||
}
|
||||
})();
|
||||
|
Loading…
Reference in New Issue
Block a user