Content-Length: 927813 | pFad | http://github.com/mablhq/github-run-tests-action/commit/407223b0f2373e53f8cf8612051cf55f82b31b16

5A v1.10 release · mablhq/github-run-tests-action@407223b · GitHub
Skip to content

Commit 407223b

Browse files
committed
v1.10 release
1 parent f647a86 commit 407223b

File tree

5 files changed

+210
-51
lines changed

5 files changed

+210
-51
lines changed

lib/src/constants.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });
3+
exports.ActionOutputs = exports.ActionInputs = exports.USER_AGENT = void 0;
4+
exports.USER_AGENT = 'mabl-github-run-tests-action';
5+
var ActionInputs;
6+
(function (ActionInputs) {
7+
ActionInputs["ApplicationId"] = "application-id";
8+
ActionInputs["BrowserTypes"] = "browser-types";
9+
ActionInputs["ContinueOnFailure"] = "continue-on-failure";
10+
ActionInputs["EnvironmentId"] = "environment-id";
11+
ActionInputs["EventTime"] = "event-time";
12+
ActionInputs["HttpHeaders"] = "http-headers";
13+
ActionInputs["MablBranch"] = "mabl-branch";
14+
ActionInputs["PlanLabels"] = "plan-labels";
15+
ActionInputs["RebaselineImages"] = "rebaseline-images";
16+
ActionInputs["SetStaticBaseline"] = "set-static-baseline";
17+
ActionInputs["Uri"] = "uri";
18+
})(ActionInputs = exports.ActionInputs || (exports.ActionInputs = {}));
19+
var ActionOutputs;
20+
(function (ActionOutputs) {
21+
ActionOutputs["DeploymentId"] = "mabl-deployment-id";
22+
ActionOutputs["PlansRun"] = "plans_run";
23+
ActionOutputs["PlansPassed"] = "plans_passed";
24+
ActionOutputs["PlansFailed"] = "plans_failed";
25+
ActionOutputs["TestsRun"] = "tests_run";
26+
ActionOutputs["TestsPassed"] = "tests_passed";
27+
ActionOutputs["TestsFailed"] = "tests_failed";
28+
})(ActionOutputs = exports.ActionOutputs || (exports.ActionOutputs = {}));

lib/src/entities/Environment.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
"use strict";
2+
Object.defineProperty(exports, "__esModule", { value: true });

lib/src/index.js

Lines changed: 68 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3131
return (mod && mod.__esModule) ? mod : { "default": mod };
3232
};
3333
Object.defineProperty(exports, "__esModule", { value: true });
34+
exports.run = exports.booleanInput = exports.optionalInput = exports.optionalArrayInput = void 0;
3435
const axios_1 = __importDefault(require("axios"));
3536
const mablApiClient_1 = require("./mablApiClient");
3637
const table_1 = require("./table");
3738
const core = __importStar(require("@actions/core"));
3839
const github = __importStar(require("@actions/github"));
40+
const constants_1 = require("./constants");
3941
const DEFAULT_MABL_APP_URL = 'https://app.mabl.com';
4042
const EXECUTION_POLL_INTERVAL_MILLIS = 10000;
4143
const EXECUTION_COMPLETED_STATUSES = [
@@ -46,34 +48,56 @@ const EXECUTION_COMPLETED_STATUSES = [
4648
'terminated',
4749
];
4850
const GITHUB_BASE_URL = 'https://api.github.com';
51+
function optionalArrayInput(name) {
52+
return core
53+
.getInput(name, {
54+
required: false,
55+
})
56+
.split(/[,\n]/)
57+
.filter((item) => item.length)
58+
.map((item) => item.trim());
59+
}
60+
exports.optionalArrayInput = optionalArrayInput;
61+
function optionalInput(name) {
62+
const rawValue = core.getInput(name, {
63+
required: false,
64+
});
65+
if (rawValue.length > 0) {
66+
return rawValue;
67+
}
68+
return;
69+
}
70+
exports.optionalInput = optionalInput;
71+
function booleanInput(name) {
72+
return (core
73+
.getInput(name, {
74+
required: false,
75+
})
76+
.toLowerCase() === 'true');
77+
}
78+
exports.booleanInput = booleanInput;
4979
function run() {
5080
var _a, _b, _c;
5181
return __awaiter(this, void 0, void 0, function* () {
5282
try {
5383
core.startGroup('Gathering inputs');
54-
const applicationId = core.getInput('application-id', {
55-
required: false,
56-
});
57-
const environmentId = core.getInput('environment-id', {
58-
required: false,
59-
});
60-
const apiKey = process.env.MABL_API_KEY || '';
84+
const applicationId = optionalInput(constants_1.ActionInputs.ApplicationId);
85+
const environmentId = optionalInput(constants_1.ActionInputs.EnvironmentId);
86+
const apiKey = process.env.MABL_API_KEY;
6187
if (!apiKey) {
62-
core.setFailed('MABL_API_KEY required');
88+
core.setFailed('env var MABL_API_KEY required');
89+
return;
6390
}
64-
const browserTypes = core.getInput('browser-types', {
65-
required: false,
66-
});
67-
const uri = core.getInput('uri', { required: false });
68-
const rebaselineImages = parseBoolean(core.getInput('rebaseline-images', {
69-
required: false,
70-
}));
71-
const setStaticBaseline = parseBoolean(core.getInput('set-static-baseline', {
72-
required: false,
73-
}));
74-
const continueOnPlanFailure = parseBoolean(core.getInput('continue-on-failure', { required: false }));
91+
const planLabels = optionalArrayInput(constants_1.ActionInputs.PlanLabels);
92+
const browserTypes = optionalArrayInput(constants_1.ActionInputs.BrowserTypes);
93+
const httpHeaders = optionalArrayInput(constants_1.ActionInputs.HttpHeaders);
94+
const uri = optionalInput(constants_1.ActionInputs.Uri);
95+
const mablBranch = optionalInput(constants_1.ActionInputs.MablBranch);
96+
const rebaselineImages = booleanInput(constants_1.ActionInputs.RebaselineImages);
97+
const setStaticBaseline = booleanInput(constants_1.ActionInputs.SetStaticBaseline);
98+
const continueOnPlanFailure = booleanInput(constants_1.ActionInputs.ContinueOnFailure);
7599
const pullRequest = yield getRelatedPullRequest();
76-
const eventTimeString = core.getInput('event-time', { required: false });
100+
const eventTimeString = optionalInput(constants_1.ActionInputs.EventTime);
77101
const eventTime = eventTimeString ? parseInt(eventTimeString) : Date.now();
78102
let properties = {
79103
triggering_event_name: process.env.GITHUB_EVENT_NAME,
@@ -98,18 +122,28 @@ function run() {
98122
const revision = process.env.GITHUB_EVENT_NAME === 'pull_request'
99123
? (_c = (_b = github.context.payload.pull_request) === null || _b === void 0 ? void 0 : _b.head) === null || _c === void 0 ? void 0 : _c.sha
100124
: process.env.GITHUB_SHA;
125+
if (mablBranch) {
126+
core.info(`Using mabl branch [${mablBranch}]`);
127+
}
101128
core.info(`Using git revision [${revision}]`);
102129
core.endGroup();
103130
core.startGroup('Creating deployment event');
104131
const apiClient = new mablApiClient_1.MablApiClient(apiKey);
105-
const deployment = yield apiClient.postDeploymentEvent(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, revision, eventTime, properties);
106-
core.setOutput('mabl-deployment-id', deployment.id);
107-
let outputLink = baseApiUrl;
132+
const deployment = yield apiClient.postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch);
133+
core.setOutput(constants_1.ActionOutputs.DeploymentId, deployment.id);
134+
let appOrEnv;
108135
if (applicationId) {
109-
const application = yield apiClient.getApplication(applicationId);
110-
outputLink = `${baseApiUrl}/workspaces/${application.organization_id}/events/${deployment.id}`;
111-
core.info(`Deployment triggered. View output at: ${outputLink}`);
136+
appOrEnv = yield apiClient.getApplication(applicationId);
137+
}
138+
else if (environmentId) {
139+
appOrEnv = yield apiClient.getEnvironment(environmentId);
112140
}
141+
if (!appOrEnv) {
142+
core.setFailed('Invalid configuration. Valid "application-id" or "environment-id" must be set. No tests started.');
143+
return;
144+
}
145+
const outputLink = `${baseApiUrl}/workspaces/${appOrEnv.organization_id}/events/${deployment.id}`;
146+
core.info(`Deployment triggered. View output at: ${outputLink}`);
113147
core.startGroup('Await completion of tests');
114148
let executionComplete = false;
115149
while (!executionComplete) {
@@ -132,12 +166,12 @@ function run() {
132166
finalExecutionResult.executions.forEach((execution) => {
133167
core.info(table_1.prettyFormatExecution(execution));
134168
});
135-
core.setOutput('plans_run', '' + finalExecutionResult.plan_execution_metrics.total);
136-
core.setOutput('plans_passed', '' + finalExecutionResult.plan_execution_metrics.passed);
137-
core.setOutput('plans_failed', '' + finalExecutionResult.plan_execution_metrics.failed);
138-
core.setOutput('tests_run', '' + finalExecutionResult.journey_execution_metrics.total);
139-
core.setOutput('tests_passed', '' + finalExecutionResult.journey_execution_metrics.passed);
140-
core.setOutput('tests_failed', '' + finalExecutionResult.journey_execution_metrics.failed);
169+
core.setOutput(constants_1.ActionOutputs.PlansRun, '' + finalExecutionResult.plan_execution_metrics.total);
170+
core.setOutput(constants_1.ActionOutputs.PlansPassed, '' + finalExecutionResult.plan_execution_metrics.passed);
171+
core.setOutput(constants_1.ActionOutputs.PlansFailed, '' + finalExecutionResult.plan_execution_metrics.failed);
172+
core.setOutput(constants_1.ActionOutputs.TestsRun, '' + finalExecutionResult.journey_execution_metrics.total);
173+
core.setOutput(constants_1.ActionOutputs.TestsPassed, '' + finalExecutionResult.journey_execution_metrics.passed);
174+
core.setOutput(constants_1.ActionOutputs.TestsFailed, '' + finalExecutionResult.journey_execution_metrics.failed);
141175
if (finalExecutionResult.journey_execution_metrics.failed === 0) {
142176
core.debug('Deployment plans passed');
143177
}
@@ -154,9 +188,7 @@ function run() {
154188
}
155189
});
156190
}
157-
function parseBoolean(toParse) {
158-
return (toParse === null || toParse === void 0 ? void 0 : toParse.toLowerCase()) === 'true';
159-
}
191+
exports.run = run;
160192
function getExecutionsStillPending(executionResult) {
161193
return executionResult.executions.filter((execution) => {
162194
return !(EXECUTION_COMPLETED_STATUSES.includes(execution.status) &&
@@ -176,7 +208,7 @@ function getRelatedPullRequest() {
176208
Authorization: `token ${githubToken}`,
177209
Accept: 'application/vnd.github.groot-preview+json',
178210
'Content-Type': 'application/json',
179-
'User-Agent': 'mabl-action',
211+
'User-Agent': constants_1.USER_AGENT,
180212
},
181213
};
182214
const client = axios_1.default.create(config);

lib/src/mablApiClient.js

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
1515
exports.MablApiClient = void 0;
1616
const async_retry_1 = __importDefault(require("async-retry"));
1717
const axios_1 = __importDefault(require("axios"));
18+
const constants_1 = require("./constants");
1819
class MablApiClient {
1920
constructor(apiKey) {
2021
var _a;
2122
this.baseUrl = (_a = process.env.APP_URL) !== null && _a !== void 0 ? _a : 'https://api.mabl.com';
2223
const config = {
2324
headers: {
24-
'User-Agent': 'github-run-tests-action',
25+
'User-Agent': constants_1.USER_AGENT,
2526
Accept: 'application/json',
2627
'Content-Type': 'application/json',
2728
},
@@ -60,13 +61,23 @@ class MablApiClient {
6061
});
6162
});
6263
}
63-
getApplication(applicationId) {
64+
getApplication(id) {
6465
return __awaiter(this, void 0, void 0, function* () {
6566
try {
66-
return yield this.makeGetRequest(`${this.baseUrl}/v1/applications/${applicationId}`);
67+
return yield this.makeGetRequest(`${this.baseUrl}/v1/applications/${id}`);
6768
}
6869
catch (error) {
69-
throw new Error(`failed to get mabl application ($applicationId) from the API ${error}`);
70+
throw new Error(`failed to get mabl application (${id}) from the API ${error}`);
71+
}
72+
});
73+
}
74+
getEnvironment(id) {
75+
return __awaiter(this, void 0, void 0, function* () {
76+
try {
77+
return yield this.makeGetRequest(`${this.baseUrl}/v1/environments/${id}`);
78+
}
79+
catch (error) {
80+
throw new Error(`failed to get mabl environment (${id}) from the API ${error}`);
7081
}
7182
});
7283
}
@@ -80,33 +91,50 @@ class MablApiClient {
8091
}
8192
});
8293
}
83-
postDeploymentEvent(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, revision, eventTime, properties) {
94+
postDeploymentEvent(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch) {
8495
return __awaiter(this, void 0, void 0, function* () {
8596
try {
86-
const requestBody = this.buildRequestBody(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, eventTime, properties, revision);
97+
const requestBody = this.buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, eventTime, properties, applicationId, environmentId, uri, revision, mablBranch);
8798
return yield this.makePostRequest(`${this.baseUrl}/events/deployment/`, requestBody);
8899
}
89100
catch (e) {
90101
throw new Error(`failed to create deployment through mabl API ${e}`);
91102
}
92103
});
93104
}
94-
buildRequestBody(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, event_time, properties, revision) {
105+
buildRequestBody(browserTypes, planLabels, httpHeaders, rebaselineImages, setStaticBaseline, event_time, properties, applicationId, environmentId, uri, revision, mablBranch) {
95106
const requestBody = {};
96107
if (environmentId) {
97108
requestBody.environment_id = environmentId;
98109
}
99110
if (applicationId) {
100111
requestBody.application_id = applicationId;
101112
}
113+
if (mablBranch) {
114+
requestBody.source_control_tag = mablBranch;
115+
}
102116
const planOverrides = {};
103-
if (browserTypes) {
104-
planOverrides.browser_types = browserTypes.split(',');
117+
if (browserTypes.length) {
118+
planOverrides.browser_types = browserTypes;
105119
}
106120
if (uri) {
107121
planOverrides.uri = uri;
108122
}
123+
if (httpHeaders.length) {
124+
planOverrides.http_headers = httpHeaders.map((header) => {
125+
const parts = header.split(':', 2);
126+
return {
127+
name: parts[0],
128+
value: parts[1],
129+
log_header_value: false,
130+
};
131+
});
132+
planOverrides.http_headers_required = true;
133+
}
109134
requestBody.plan_overrides = planOverrides;
135+
if (planLabels.length) {
136+
requestBody.plan_labels = planLabels;
137+
}
110138
if (revision) {
111139
requestBody.revision = revision;
112140
}

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/mablhq/github-run-tests-action/commit/407223b0f2373e53f8cf8612051cf55f82b31b16

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy