Skip to content

Commit

Permalink
Separate entrypoint
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed May 21, 2024
1 parent 1ddde9e commit ff5f05f
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -76,4 +76,4 @@ outputs:

runs:
using: "node20"
main: "lib/src/index.js"
main: "lib/src/entrypoint.js"
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "mabl-github-deployments-action",
"version": "1.13.1",
"description": "mabl github action for GitHub pipelines integration",
"main": "lib/src/index.js",
"main": "lib/src/entrypoint.js",
"scripts": {
"test": "jest",
"build": "tsc",
Expand Down
5 changes: 5 additions & 0 deletions src/entrypoint.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import {run} from './index';

// This exists in a separate file, so that we don't implicitly invoke it during unit tests, allowing for overrides
// eslint-disable-next-line
run();
10 changes: 3 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,12 @@ export function booleanInput(name: string): boolean {
);
}

export async function run(): Promise<void> {
export async function run(enableFailureExitCodes = true): Promise<void> {
const wrappedFailed = (message: string): void => {
// Allow disabling, otherwise units will always fail in workflow builds w/ process exit code 1
if (process.env.DISABLE_FAILURE_EXIT_CODES !== 'true') {
// core.setFailed(message);
if (enableFailureExitCodes) {
core.setFailed(message);
}
console.log(message);
};

try {
Expand Down Expand Up @@ -300,6 +299,3 @@ async function getRelatedPullRequest(): Promise<Option<PullRequest>> {

return;
}

// eslint-disable-next-line
run();
4 changes: 2 additions & 2 deletions test/suite.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ describe('GitHub Action tests', () => {
}

function assertExitCodeNot(expected: number): void {
expect(process.exitCode).not.toEqual(expected);
expect(process.exitCode).not.toBe(expected);
}

it('handles invalid application/environment ids', async () => {
setGithubInput(ActionInputs.ApplicationId, '');
setGithubInput(ActionInputs.EnvironmentId, '');
await run();
await run(false);
assertExitCodeNot(1); // We'd normally seek '1', but that will break the CI/CD test harness
});

Expand Down

0 comments on commit ff5f05f

Please sign in to comment.