Turning on no-unsafe-finally

This commit is contained in:
JamesIves 2020-02-15 14:15:43 -05:00
parent 5c0227e8ca
commit 4f2055e4f9
4 changed files with 18 additions and 28 deletions

View File

@ -35,9 +35,8 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(execute).toBeCalledTimes(6); expect(execute).toBeCalledTimes(6);
expect(call).toBe("Initialization step complete...");
}); });
it("should execute commands if an Access Token is provided", async () => { it("should execute commands if an Access Token is provided", async () => {
@ -51,10 +50,8 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(execute).toBeCalledTimes(6); expect(execute).toBeCalledTimes(6);
expect(call).toBe("Initialization step complete...");
}); });
it("should execute commands if SSH is true", async () => { it("should execute commands if SSH is true", async () => {
@ -68,10 +65,9 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(execute).toBeCalledTimes(6); expect(execute).toBeCalledTimes(6);
expect(call).toBe("Initialization step complete...");
}); });
it("should fail if there is no provided GitHub Token, Access Token or SSH bool", async () => { it("should fail if there is no provided GitHub Token, Access Token or SSH bool", async () => {
@ -87,10 +83,9 @@ describe("git", () => {
ssh: null ssh: null
}); });
const call = await init(); await init();
expect(setFailed).toBeCalledTimes(1); expect(setFailed).toBeCalledTimes(1);
expect(execute).toBeCalledTimes(0); expect(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
}); });
it("should fail if the build folder begins with a /", async () => { it("should fail if the build folder begins with a /", async () => {
@ -104,11 +99,10 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(setFailed).toBeCalledTimes(1); expect(setFailed).toBeCalledTimes(1);
expect(execute).toBeCalledTimes(0); expect(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
}); });
it("should fail if the build folder begins with a ./", async () => { it("should fail if the build folder begins with a ./", async () => {
@ -122,10 +116,9 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(setFailed).toBeCalledTimes(1); expect(setFailed).toBeCalledTimes(1);
expect(execute).toBeCalledTimes(0); expect(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
}); });
it("should not fail if root is used", async () => { it("should not fail if root is used", async () => {
@ -139,10 +132,9 @@ describe("git", () => {
} }
}); });
const call = await init(); await init();
expect(execute).toBeCalledTimes(6); expect(execute).toBeCalledTimes(6);
expect(call).toBe("Initialization step complete...");
}); });
}); });
@ -158,9 +150,8 @@ describe("git", () => {
} }
}); });
const call = await generateBranch(); await generateBranch();
expect(execute).toBeCalledTimes(6); expect(execute).toBeCalledTimes(6);
expect(call).toBe("Deployment branch creation step complete... ✅");
}); });
it("should fail if there is no branch", async () => { it("should fail if there is no branch", async () => {
@ -174,10 +165,9 @@ describe("git", () => {
} }
}); });
const call = await generateBranch(); await generateBranch();
expect(execute).toBeCalledTimes(0); expect(execute).toBeCalledTimes(0);
expect(setFailed).toBeCalledTimes(1); expect(setFailed).toBeCalledTimes(1);
expect(call).toBe("Deployment branch creation step complete... ✅");
}); });
}); });

View File

@ -12,7 +12,7 @@ import { isNullOrUndefined } from "./util";
/** Generates the branch if it doesn't exist on the remote. /** Generates the branch if it doesn't exist on the remote.
* @returns {Promise} * @returns {Promise}
*/ */
export async function init(): Promise<any> { export async function init(): Promise<void> {
try { try {
if ( if (
isNullOrUndefined(action.accessToken) && isNullOrUndefined(action.accessToken) &&
@ -48,14 +48,14 @@ export async function init(): Promise<any> {
} catch (error) { } catch (error) {
console.log(`There was an error initializing the repository: ${error}`); console.log(`There was an error initializing the repository: ${error}`);
} finally { } finally {
return Promise.resolve("Initialization step complete..."); console.log("Initialization step complete...");
} }
} }
/** Switches to the base branch. /** Switches to the base branch.
* @returns {Promise} * @returns {Promise}
*/ */
export async function switchToBaseBranch(): Promise<any> { export async function switchToBaseBranch(): Promise<string> {
await execute( await execute(
`git checkout --progress --force ${ `git checkout --progress --force ${
action.baseBranch ? action.baseBranch : action.defaultBranch action.baseBranch ? action.baseBranch : action.defaultBranch
@ -69,7 +69,7 @@ export async function switchToBaseBranch(): Promise<any> {
/** Generates the branch if it doesn't exist on the remote. /** Generates the branch if it doesn't exist on the remote.
* @returns {Promise} * @returns {Promise}
*/ */
export async function generateBranch(): Promise<any> { export async function generateBranch(): Promise<void> {
try { try {
if (isNullOrUndefined(action.branch)) { if (isNullOrUndefined(action.branch)) {
throw Error("Branch is required."); throw Error("Branch is required.");
@ -88,14 +88,14 @@ export async function generateBranch(): Promise<any> {
} catch (error) { } catch (error) {
setFailed(`There was an error creating the deployment branch: ${error}`); setFailed(`There was an error creating the deployment branch: ${error}`);
} finally { } finally {
return Promise.resolve("Deployment branch creation step complete... ✅"); console.log("Deployment branch creation step complete... ✅");
} }
} }
/** Runs the necessary steps to make the deployment. /** Runs the necessary steps to make the deployment.
* @returns {Promise} * @returns {Promise}
*/ */
export async function deploy(): Promise<any> { export async function deploy(): Promise<string> {
const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder"; const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
const temporaryDeploymentBranch = "gh-action-temp-deployment-branch"; const temporaryDeploymentBranch = "gh-action-temp-deployment-branch";
/* /*
@ -160,7 +160,7 @@ export async function deploy(): Promise<any> {
if (!hasFilesToCommit && !action.isTest) { if (!hasFilesToCommit && !action.isTest) {
console.log("There is nothing to commit. Exiting... ✅"); console.log("There is nothing to commit. Exiting... ✅");
return Promise.resolve(); return Promise.resolve("Exiting early...");
} }
// Commits to GitHub. // Commits to GitHub.

View File

@ -2,7 +2,7 @@ import { setFailed } from "@actions/core";
import { init, deploy } from "./git"; import { init, deploy } from "./git";
/** Initializes and runs the action. */ /** Initializes and runs the action. */
export default async function main() { export default async function main(): Promise<void> {
try { try {
await init(); await init();
await deploy(); await deploy();

View File

@ -18,7 +18,7 @@
"no-implicit-dependencies": true, "no-implicit-dependencies": true,
"no-invalid-this": true, "no-invalid-this": true,
"no-string-throw": true, "no-string-throw": true,
"no-unsafe-finally": false, "no-unsafe-finally": true,
"no-use-before-declare": true, "no-use-before-declare": true,
"no-void-expression": [true, "ignore-arrow-function-shorthand"], "no-void-expression": [true, "ignore-arrow-function-shorthand"],
"no-duplicate-imports": true, "no-duplicate-imports": true,