Skip to content

Commit

Permalink
v1.15 release
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed Jan 10, 2025
1 parent 5c79e28 commit 43061c6
Show file tree
Hide file tree
Showing 146 changed files with 3,949 additions and 4,319 deletions.
6 changes: 4 additions & 2 deletions lib/src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@ var ActionInputs;
ActionInputs["RebaselineImages"] = "rebaseline-images";
ActionInputs["SetStaticBaseline"] = "set-static-baseline";
ActionInputs["Uri"] = "uri";
})(ActionInputs = exports.ActionInputs || (exports.ActionInputs = {}));
ActionInputs["UrlApi"] = "api-url";
ActionInputs["UrlApp"] = "app-url";
})(ActionInputs || (exports.ActionInputs = ActionInputs = {}));
var ActionOutputs;
(function (ActionOutputs) {
ActionOutputs["DeploymentId"] = "mabl-deployment-id";
Expand All @@ -25,4 +27,4 @@ var ActionOutputs;
ActionOutputs["TestsRun"] = "tests_run";
ActionOutputs["TestsPassed"] = "tests_passed";
ActionOutputs["TestsFailed"] = "tests_failed";
})(ActionOutputs = exports.ActionOutputs || (exports.ActionOutputs = {}));
})(ActionOutputs || (exports.ActionOutputs = ActionOutputs = {}));
49 changes: 34 additions & 15 deletions lib/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,39 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.run = exports.booleanInput = exports.optionalInput = exports.optionalArrayInput = void 0;
exports.optionalArrayInput = optionalArrayInput;
exports.optionalInput = optionalInput;
exports.booleanInput = booleanInput;
exports.run = run;
const axios_1 = __importDefault(require("axios"));
const mablApiClient_1 = require("./mablApiClient");
const table_1 = require("./table");
const core = __importStar(require("@actions/core"));
const github = __importStar(require("@actions/github"));
const constants_1 = require("./constants");
const DEFAULT_MABL_APP_URL = 'https://app.mabl.com';
const EXECUTION_POLL_INTERVAL_MILLIS = 10000;
const EXECUTION_POLL_INTERVAL_MILLIS = 10_000;
const EXECUTION_COMPLETED_STATUSES = [
'succeeded',
'failed',
Expand All @@ -52,7 +65,6 @@ function optionalArrayInput(name) {
.filter((item) => item.length)
.map((item) => item.trim());
}
exports.optionalArrayInput = optionalArrayInput;
function optionalInput(name) {
const rawValue = core.getInput(name, {
required: false,
Expand All @@ -62,15 +74,13 @@ function optionalInput(name) {
}
return;
}
exports.optionalInput = optionalInput;
function booleanInput(name) {
return (core
.getInput(name, {
required: false,
})
.toLowerCase() === 'true');
}
exports.booleanInput = booleanInput;
async function run(enableFailureExitCodes = true) {
const wrappedFailed = (message) => {
if (enableFailureExitCodes) {
Expand All @@ -90,13 +100,22 @@ async function run(enableFailureExitCodes = true) {
const browserTypes = optionalArrayInput(constants_1.ActionInputs.BrowserTypes);
const httpHeaders = optionalArrayInput(constants_1.ActionInputs.HttpHeaders);
const uri = optionalInput(constants_1.ActionInputs.Uri);
const apiUrl = optionalInput(constants_1.ActionInputs.UrlApi);
const appUrl = optionalInput(constants_1.ActionInputs.UrlApp);
const mablBranch = optionalInput(constants_1.ActionInputs.MablBranch);
const rebaselineImages = booleanInput(constants_1.ActionInputs.RebaselineImages);
const setStaticBaseline = booleanInput(constants_1.ActionInputs.SetStaticBaseline);
const continueOnPlanFailure = booleanInput(constants_1.ActionInputs.ContinueOnFailure);
const pullRequest = await getRelatedPullRequest();
const eventTimeString = optionalInput(constants_1.ActionInputs.EventTime);
const eventTime = eventTimeString ? parseInt(eventTimeString) : Date.now();
if (uri) {
core.warning(`[${constants_1.ActionInputs.Uri}] has been deprecated. Please use [${constants_1.ActionInputs.UrlApp}] instead.`);
}
if (uri && appUrl) {
core.warning(`Both [${constants_1.ActionInputs.Uri}] and [${constants_1.ActionInputs.UrlApp}] were set. The value for [${constants_1.ActionInputs.UrlApp}] will be used`);
}
const effectiveAppUrl = appUrl ?? uri;
let properties = {
triggering_event_name: process.env.GITHUB_EVENT_NAME,
repository_commit_username: process.env.GITHUB_ACTOR,
Expand Down Expand Up @@ -127,7 +146,7 @@ async function run(enableFailureExitCodes = true) {
core.endGroup();
core.startGroup('Creating deployment event');
const apiClient = new mablApiClient_1.MablApiClient(apiKey);
const deployment = await apiClient.postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch);
const deployment = await apiClient.postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, effectiveAppUrl, apiUrl, revision, mablBranch);
core.setOutput(constants_1.ActionOutputs.DeploymentId, deployment.id);
let appOrEnv;
if (applicationId) {
Expand All @@ -140,7 +159,8 @@ async function run(enableFailureExitCodes = true) {
wrappedFailed('Invalid configuration. Valid "application-id" or "environment-id" must be set. No tests started.');
return;
}
const outputLink = `${baseAppUrl}/workspaces/${appOrEnv.organization_id}/events/${deployment.id}`;
const effectiveWorkspaceId = appOrEnv.workspace_id ?? appOrEnv.organization_id;
const outputLink = `${baseAppUrl}/workspaces/${effectiveWorkspaceId}/events/${deployment.id}`;
core.info(`Deployment triggered. View output at: ${outputLink}`);
core.startGroup('Await completion of tests');
let executionComplete = false;
Expand Down Expand Up @@ -185,7 +205,6 @@ async function run(enableFailureExitCodes = true) {
wrappedFailed(`mabl deployment task failed for the following reason: ${err}`);
}
}
exports.run = run;
function sleep(milliseconds) {
return new Promise((resolve, reject) => {
try {
Expand Down
17 changes: 10 additions & 7 deletions lib/src/mablApiClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ exports.MablApiClient = void 0;
const async_retry_1 = __importDefault(require("async-retry"));
const axios_1 = __importDefault(require("axios"));
const constants_1 = require("./constants");
const GET_REQUEST_TIMEOUT_MILLIS = 600000;
const POST_REQUEST_TIMEOUT_MILLIS = 900000;
const GET_REQUEST_TIMEOUT_MILLIS = 600_000;
const POST_REQUEST_TIMEOUT_MILLIS = 900_000;
class MablApiClient {
constructor(apiKey) {
this.baseUrl = process.env.MABL_REST_API_URL ?? 'https://api.mabl.com';
Expand Down Expand Up @@ -85,16 +85,16 @@ class MablApiClient {
throw new Error(`failed to get mabl execution results for event ${eventId} from the API ${error}`);
}
}
async postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch) {
async postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, appUrl, apiUrl, revision, mablBranch) {
try {
const requestBody = this.buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch);
const requestBody = this.buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, appUrl, apiUrl, revision, mablBranch);
return await this.makePostRequest(`${this.baseUrl}/events/deployment/`, requestBody);
}
catch (e) {
throw new Error(`failed to create deployment through mabl API ${e}`);
}
}
buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch) {
buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, appUrl, apiUrl, revision, mablBranch) {
const requestBody = {};
if (environmentId) {
requestBody.environment_id = environmentId;
Expand All @@ -109,8 +109,11 @@ class MablApiClient {
if (browserTypes.length) {
planOverrides.browser_types = browserTypes;
}
if (uri) {
planOverrides.uri = uri;
if (appUrl) {
planOverrides.web_url = appUrl;
}
if (apiUrl) {
planOverrides.api_url = apiUrl;
}
if (httpHeaders.length) {
planOverrides.http_headers = httpHeaders.map((header) => {
Expand Down
27 changes: 18 additions & 9 deletions lib/src/table.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __importStar = (this && this.__importStar) || (function () {
var ownKeys = function(o) {
ownKeys = Object.getOwnPropertyNames || function (o) {
var ar = [];
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
return ar;
};
return ownKeys(o);
};
return function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
__setModuleDefault(result, mod);
return result;
};
})();
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.prettyFormatExecution = void 0;
exports.prettyFormatExecution = prettyFormatExecution;
const cli_table3_1 = __importDefault(require("cli-table3"));
const moment = __importStar(require("moment"));
function prettyFormatExecution(execution) {
Expand Down Expand Up @@ -76,7 +86,6 @@ function prettyFormatExecution(execution) {
outputString += outputTable(testTable);
return outputString;
}
exports.prettyFormatExecution = prettyFormatExecution;
function outputTable(table) {
return table.toString().replace(/[\r\n]+/, '\n ');
}
67 changes: 59 additions & 8 deletions lib/test/suite.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ describe('GitHub Action tests', () => {
expect((0, src_1.optionalArrayInput)(constants_1.ActionInputs.BrowserTypes)).toEqual(['chrome']);
setGithubInput(constants_1.ActionInputs.BrowserTypes, 'chrome, firefox ');
expect((0, src_1.optionalArrayInput)(constants_1.ActionInputs.BrowserTypes)).toEqual(['chrome', 'firefox']);
setGithubInput(constants_1.ActionInputs.BrowserTypes, 'chrome\nfirefox\nsafari ');
expect((0, src_1.optionalArrayInput)(constants_1.ActionInputs.BrowserTypes)).toEqual(['chrome', 'firefox', 'safari']);
setGithubInput(constants_1.ActionInputs.BrowserTypes, 'chrome\nfirefox\nwebkit\nedge ');
expect((0, src_1.optionalArrayInput)(constants_1.ActionInputs.BrowserTypes)).toEqual(['chrome', 'firefox', 'webkit', 'edge']);
});
it('parses boolean inputs', () => {
setGithubInput(constants_1.ActionInputs.RebaselineImages, '');
Expand Down Expand Up @@ -99,8 +99,9 @@ describe('GitHub Action tests', () => {
environment_id: 'env',
application_id: 'app',
plan_overrides: {
browser_types: ['firefox', 'chrome', 'internet_explorer'],
uri: 'uri',
browser_types: ['firefox', 'chrome', 'edge'],
web_url: 'fake-app-url',
api_url: 'fake-api-url',
},
actions: { rebaseline_images: true, set_static_baseline: true },
revision: 'abcs',
Expand All @@ -119,7 +120,7 @@ describe('GitHub Action tests', () => {
},
};
const apiClient = new mablApiClient_1.MablApiClient('test');
const requestBody = apiClient.buildRequestBody(['firefox', 'chrome', 'internet_explorer'], [], [], true, true, 0, {
const requestBody = apiClient.buildRequestBody(['firefox', 'chrome', 'edge'], [], [], true, true, 0, {
repository_branch_name: 'master',
repository_commit_username: 'gcooney',
repository_action: 'mabl-tests',
Expand All @@ -131,15 +132,15 @@ describe('GitHub Action tests', () => {
repository_pull_request_title: 'good pr',
repository_pull_request_merged_at: '2019',
repository_pull_request_created_at: '2019',
}, 'app', 'env', 'uri', 'abcs');
}, 'app', 'env', 'fake-app-url', 'fake-api-url', 'abcs');
expect(expected).toStrictEqual(requestBody);
});
it('builds the request correctly with some options', () => {
const expected = {
application_id: 'app',
plan_labels: ['alpha', 'beta'],
plan_overrides: {
uri: 'uri',
web_url: 'fake-app-url',
browser_types: ['chrome', 'firefox'],
http_headers: [{
name: 'Header-Uno',
Expand Down Expand Up @@ -181,7 +182,57 @@ describe('GitHub Action tests', () => {
repository_pull_request_title: 'good pr',
repository_pull_request_merged_at: '2019',
repository_pull_request_created_at: '2019',
}, 'app', '', 'uri', 'abcs');
}, 'app', '', 'fake-app-url', undefined, 'abcs');
expect(expected).toStrictEqual(requestBody);
});
it('builds the request correctly with some options API test override', () => {
const expected = {
application_id: 'app',
plan_labels: ['alpha', 'beta'],
plan_overrides: {
api_url: 'fake-api-url',
browser_types: ['chrome', 'firefox'],
http_headers: [{
name: 'Header-Uno',
value: 'value-uno',
log_header_value: false,
}, {
name: 'Header-Dos',
value: 'value-dos',
log_header_value: false,
}],
http_headers_required: true
},
actions: {},
revision: 'abcs',
properties: {
repository_branch_name: 'master',
repository_commit_username: 'gcooney',
repository_action: 'mabl-tests',
repository_name: 'github-mabl-actions',
repository_url: '[email protected]:mablhq/github-mabl-actions.git',
triggering_event_name: 'push',
repository_pull_request_url: 'https://github.com/mablhq/repo/pr/1',
repository_pull_request_number: 5,
repository_pull_request_title: 'good pr',
repository_pull_request_merged_at: '2019',
repository_pull_request_created_at: '2019',
},
};
const apiClient = new mablApiClient_1.MablApiClient('test');
const requestBody = apiClient.buildRequestBody(['chrome', 'firefox'], ['alpha', 'beta'], ['Header-Uno:value-uno', 'Header-Dos:value-dos'], false, false, 0, {
repository_branch_name: 'master',
repository_commit_username: 'gcooney',
repository_action: 'mabl-tests',
repository_name: 'github-mabl-actions',
repository_url: '[email protected]:mablhq/github-mabl-actions.git',
triggering_event_name: 'push',
repository_pull_request_url: 'https://github.com/mablhq/repo/pr/1',
repository_pull_request_number: 5,
repository_pull_request_title: 'good pr',
repository_pull_request_merged_at: '2019',
repository_pull_request_created_at: '2019',
}, 'app', '', undefined, 'fake-api-url', 'abcs');
expect(expected).toStrictEqual(requestBody);
});
});
Loading

0 comments on commit 43061c6

Please sign in to comment.