8000 Merge branch 'dev' into releases/v3 · cauu/github-pages-deploy-action@6844140 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6844140

Browse files
committed
Merge branch 'dev' into releases/v3
2 parents 4abcf78 + 247dcbb commit 6844140

File tree

5 files changed

+33
-14
lines changed

5 files changed

+33
-14
lines changed

__tests__/git.test.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Initial env variable setup for tests.
22
process.env["INPUT_FOLDER"] = "build";
3+
process.env["GITHUB_SHA"] = "123"
34

45
import { execute } from "../src/util";
56
import { init, generateBranch, deploy } from "../src/git";
@@ -114,7 +115,7 @@ describe("git", () => {
114115
it('should execute five commands', async () => {
115116
const call = await generateBranch();
116117
expect(execute).toBeCalledTimes(6);
117-
expect(call).toBe('Deployment branch creation step complete...')
118+
expect(call).toBe('Deployment branch creation step complete...')
118119
})
119120
})
120121

@@ -131,7 +132,7 @@ describe("git", () => {
131132
const call = await deploy();
132133

133134
// Includes the call to generateBranch
134-
expect(execute).toBeCalledTimes(16);
135+
expect(execute).toBeCalledTimes(18);
135136
expect(call).toBe('Commit step complete...')
136137
})
137138
})

lib/git.js

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ exports.init = init;
5050
function generateBranch() {
5151
return __awaiter(this, void 0, void 0, function* () {
5252
try {
53-
console.log(`Creating ${constants_1.action.branch} branch...`);
53+
console.log(`Creating ${constants_1.action.branch} branch... 🔧`);
5454
yield util_1.execute(`git switch ${constants_1.action.baseBranch || "master"}`, constants_1.workspace);
5555
yield util_1.execute(`git switch --orphan ${constants_1.action.branch}`, constants_1.workspace);
5656
yield util_1.execute(`git reset --hard`, constants_1.workspace);
@@ -60,10 +60,10 @@ function generateBranch() {
6060
yield util_1.execute(`git switch ${constants_1.action.baseBranch || "master"}`, constants_1.workspace);
6161
}
6262
catch (error) {
63-
core.setFailed(`There was an error creating the deployment branch: ${error}`);
63+
core.setFailed(`There was an error creating the deployment branch: ${error}`);
6464
}
6565
finally {
66-
return Promise.resolve("Deployment branch creation step complete...");
66+
return Promise.resolve("Deployment branch creation step complete...");
6767
}
6868
});
6969
}
@@ -96,7 +96,7 @@ function deploy() {
9696
excludedItems.forEach((item) => (excludes += `--exclude ${item} `));
9797
}
9898
catch (_a) {
99-
console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details.");
99+
console.log("There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details.");
100100
}
101101
}
102102
/*
@@ -110,14 +110,20 @@ function deploy() {
110110
: ""} --exclude .git --exclude .github ${constants_1.action.build === constants_1.root ? `--exclude ${temporaryDeploymentDirectory}` : ""}`, constants_1.workspace);
111111
const hasFilesToCommit = yield util_1.execute(`git status --porcelain`, temporaryDeploymentDirectory);
112112
if (!hasFilesToCommit && !constants_1.isTest) {
113-
console.log("There is nothing to commit. Exiting...");
113+
console.log("There is nothing to commit. Exiting...");
114114
return Promise.resolve();
115115
}
116116
// Commits to GitHub.
117117
yield util_1.execute(`git add --all .`, temporaryDeploymentDirectory);
118118
yield util_1.execute(`git switch -c ${temporaryDeploymentBranch}`, temporaryDeploymentDirectory);
119119
yield util_1.execute(`git commit -m "Deploying to ${constants_1.action.branch} from ${constants_1.action.baseBranch} ${process.env.GITHUB_SHA}" --quiet`, temporaryDeploymentDirectory);
120120
yield util_1.execute(`git push --force ${constants_1.repositoryPath} ${temporaryDeploymentBranch}:${constants_1.action.branch}`, temporaryDeploymentDirectory);
121+
// Cleans up temporary files/folders and restores the git state.
122+
if (process.env.GITHUB_SHA) {
123+
console.log("Running post deployment cleanup jobs... 🔧");
124+
yield util_1.execute(`rm -rf ${temporaryDeploymentDirectory}`, constants_1.workspace);
125+
yield util_1.execute(`git checkout --progress --force ${process.env.GITHUB_SHA}`, constants_1.workspace);
126+
}
121127
return Promise.resolve("Commit step complete...");
122128
});
123129
}

lib/main.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ const git_1 = require("./git");
2626
yield git_1.deploy();
2727
}
2828
catch (error) {
29+
console.log("The deployment encountered an error. ❌");
2930
core.setFailed(error.message);
3031
}
3132
finally {
32-
console.log("Completed Deployment");
33+
console.log("Completed Deployment");
3334
}
3435
});
3536
})();

src/git.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export async function init(): Promise<any> {
3434
*/
3535
export async function generateBranch(): Promise<any> {
3636
try {
37-
console.log(`Creating ${action.branch} branch...`);
37+
console.log(`Creating ${action.branch} branch... 🔧`);
3838
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
3939
await execute(`git switch --orphan ${action.branch}`, workspace);
4040
await execute(`git reset --hard`, workspace);
@@ -48,10 +48,10 @@ export async function generateBranch(): Promise<any> {
4848
await execute(`git switch ${action.baseBranch || "master"}`, workspace);
4949
} catch (error) {
5050
core.setFailed(
51-
`There was an error creating the deployment branch: ${error}`
51+
`There was an error creating the deployment branch: ${error}`
5252
);
5353
} finally {
54-
return Promise.resolve("Deployment branch creation step complete...");
54+
return Promise.resolve("Deployment branch creation step complete...");
5555
}
5656
}
5757

@@ -92,7 +92,7 @@ export async function deploy(): Promise<any> {
9292
);
9393
} catch {
9494
console.log(
95-
"There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details."
95+
"There was an error parsing your CLEAN_EXCLUDE items. Please refer to the README for more details."
9696
);
9797
}
9898
}
@@ -122,7 +122,7 @@ export async function deploy(): Promise<any> {
122122
);
123123

124124
if (!hasFilesToCommit && !isTest) {
125-
console.log("There is nothing to commit. Exiting...");
125+
console.log("There is nothing to commit. Exiting...");
126126
return Promise.resolve();
127127
}
128128

@@ -141,5 +141,15 @@ export async function deploy(): Promise<any> {
141141
temporaryDeploymentDirectory
142142
);
143143

144+
// Cleans up temporary files/folders and restores the git state.
145+
if (process.env.GITHUB_SHA) {
146+
console.log("Running post deployment cleanup jobs... 🔧");
147+
await execute(`rm -rf ${temporaryDeploymentDirectory}`, workspace);
148+
await execute(
149+
`git checkout --progress --force ${process.env.GITHUB_SHA}`,
150+
workspace
151+
);
152+
}
153+
144154
return Promise.resolve("Commit step complete...");
145155
}

src/main.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@ import { init, deploy } from "./git";
77
await init();
88
await deploy();
99
} catch (error) {
10+
console.log("The deployment encountered an error. ❌");
1011
core.setFailed(error.message);
1112
} finally {
12-
console.log("Completed Deployment");
13+
console.log("Completed Deployment");
1314
}
1415
})();

0 commit comments

Comments
 (0)
0