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(call).toBe("Initialization step complete...");
});
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(call).toBe("Initialization step complete...");
});
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(call).toBe("Initialization step complete...");
});
it("should fail if there is no provided GitHub Token, Access Token or SSH bool", async () => {
@ -87,10 +83,9 @@ describe("git", () => {
ssh: null
});
const call = await init();
await init();
expect(setFailed).toBeCalledTimes(1);
expect(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
});
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(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
});
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(execute).toBeCalledTimes(0);
expect(call).toBe("Initialization step complete...");
});
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(call).toBe("Initialization step complete...");
});
});
@ -158,9 +150,8 @@ describe("git", () => {
}
});
const call = await generateBranch();
await generateBranch();
expect(execute).toBeCalledTimes(6);
expect(call).toBe("Deployment branch creation step complete... ✅");
});
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(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.
* @returns {Promise}
*/
export async function init(): Promise<any> {
export async function init(): Promise<void> {
try {
if (
isNullOrUndefined(action.accessToken) &&
@ -48,14 +48,14 @@ export async function init(): Promise<any> {
} catch (error) {
console.log(`There was an error initializing the repository: ${error}`);
} finally {
return Promise.resolve("Initialization step complete...");
console.log("Initialization step complete...");
}
}
/** Switches to the base branch.
* @returns {Promise}
*/
export async function switchToBaseBranch(): Promise<any> {
export async function switchToBaseBranch(): Promise<string> {
await execute(
`git checkout --progress --force ${
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.
* @returns {Promise}
*/
export async function generateBranch(): Promise<any> {
export async function generateBranch(): Promise<void> {
try {
if (isNullOrUndefined(action.branch)) {
throw Error("Branch is required.");
@ -88,14 +88,14 @@ export async function generateBranch(): Promise<any> {
} catch (error) {
setFailed(`There was an error creating the deployment branch: ${error}`);
} finally {
return Promise.resolve("Deployment branch creation step complete... ✅");
console.log("Deployment branch creation step complete... ✅");
}
}
/** Runs the necessary steps to make the deployment.
* @returns {Promise}
*/
export async function deploy(): Promise<any> {
export async function deploy(): Promise<string> {
const temporaryDeploymentDirectory = "gh-action-temp-deployment-folder";
const temporaryDeploymentBranch = "gh-action-temp-deployment-branch";
/*
@ -160,7 +160,7 @@ export async function deploy(): Promise<any> {
if (!hasFilesToCommit && !action.isTest) {
console.log("There is nothing to commit. Exiting... ✅");
return Promise.resolve();
return Promise.resolve("Exiting early...");
}
// Commits to GitHub.

View File

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

View File

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