Skip to content

Commit

Permalink
v1.6 release
Browse files Browse the repository at this point in the history
  • Loading branch information
twistedpair committed Oct 21, 2020
1 parent 4ba29cf commit 9e1a6f2
Show file tree
Hide file tree
Showing 2,031 changed files with 7,316 additions and 196,330 deletions.
128 changes: 68 additions & 60 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,39 @@
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : 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 __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
}
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result["default"] = mod;
return result;
}
};
Object.defineProperty(exports, "__esModule", { value: true });
const axios_1 = __importDefault(require("axios"));
const mablApiClient_1 = require("./mablApiClient");
const table_1 = require("./table");
const request_promise_native_1 = __importDefault(require("request-promise-native"));
const core = __importStar(require("@actions/core/lib/core"));
const DEFAULT_MABL_APP_URL = 'https://app.mabl.com';
const EXECUTION_POLL_INTERVAL_MILLIS = 10000;
Expand All @@ -33,8 +46,10 @@ const EXECUTION_COMPLETED_STATUSES = [
];
const GITHUB_BASE_URL = 'https://api.github.com';
function run() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
try {
core.startGroup('Gathering inputs');
const applicationId = core.getInput('application-id', {
required: false,
});
Expand All @@ -45,12 +60,10 @@ function run() {
if (!apiKey) {
core.setFailed('MABL_API_KEY required');
}
// plan override options
const browserTypes = core.getInput('browser-types', {
required: false,
});
const uri = core.getInput('uri', { required: false });
// deployment action options
const rebaselineImages = parseBoolean(core.getInput('rebaseline-images', {
required: false,
}));
Expand Down Expand Up @@ -80,39 +93,41 @@ function run() {
properties.repository_pull_request_merged_at = pullRequest.merged_at;
}
}
const baseApiUrl = process.env.APP_URL || DEFAULT_MABL_APP_URL;
// set up http client
let apiClient = new mablApiClient_1.mablApiClient(apiKey);
const baseApiUrl = (_a = process.env.APP_URL) !== null && _a !== void 0 ? _a : DEFAULT_MABL_APP_URL;
const revision = process.env.GITHUB_SHA;
// send the deployment
core.debug('Creating Deployment');
let deployment = yield apiClient.postDeploymentEvent(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, revision, eventTime, properties);
core.info(`Using git revision [${revision}]`);
core.endGroup();
core.startGroup('Creating deployment event');
const apiClient = new mablApiClient_1.MablApiClient(apiKey);
const deployment = yield apiClient.postDeploymentEvent(applicationId, environmentId, browserTypes, uri, rebaselineImages, setStaticBaseline, revision, eventTime, properties);
core.setOutput('mabl-deployment-id', deployment.id);
let outputLink = baseApiUrl;
if (applicationId) {
let application = yield apiClient.getApplication(applicationId);
const application = yield apiClient.getApplication(applicationId);
outputLink = `${baseApiUrl}/workspaces/${application.organization_id}/events/${deployment.id}`;
core.debug(`Deployment triggered. View output at: ${outputLink}`);
core.info(`Deployment triggered. View output at: ${outputLink}`);
}
// poll Execution result until complete
core.startGroup('Await completion of tests');
let executionComplete = false;
while (!executionComplete) {
yield new Promise(resolve => setTimeout(resolve, EXECUTION_POLL_INTERVAL_MILLIS));
let executionResult = yield apiClient.getExecutionResults(deployment.id);
if (executionResult && executionResult.executions) {
let pendingExecutions = getExecutionsStillPending(executionResult);
yield new Promise((resolve) => setTimeout(resolve, EXECUTION_POLL_INTERVAL_MILLIS));
const executionResult = yield apiClient.getExecutionResults(deployment.id);
if (executionResult === null || executionResult === void 0 ? void 0 : executionResult.executions) {
const pendingExecutions = getExecutionsStillPending(executionResult);
if (pendingExecutions.length === 0) {
executionComplete = true;
}
else {
core.debug(`${pendingExecutions.length} mabl plan(s) are still running`);
core.info(`${pendingExecutions.length} mabl plan(s) are still running`);
}
}
}
core.debug('mabl deployment runs have completed');
let finalExecutionResult = yield apiClient.getExecutionResults(deployment.id);
core.info('mabl deployment runs have completed');
core.endGroup();
core.startGroup('Fetch execution results');
const finalExecutionResult = yield apiClient.getExecutionResults(deployment.id);
finalExecutionResult.executions.forEach((execution) => {
table_1.prettyPrintExecution(execution);
core.info(table_1.prettyFormatExecution(execution));
});
core.setOutput('plans_run', '' + finalExecutionResult.plan_execution_metrics.total);
core.setOutput('plans_passed', '' + finalExecutionResult.plan_execution_metrics.passed);
Expand All @@ -125,19 +140,19 @@ function run() {
}
else if (continueOnPlanFailure) {
core.warning(`There were ${finalExecutionResult.journey_execution_metrics.failed} test failures but the continueOnPlanFailure flag is set so the task has been marked as passing`);
// core.setNeutral(); Todo Set neutral when support is added to actions v2
}
else {
core.setFailed(`${finalExecutionResult.journey_execution_metrics.failed} mabl test(s) failed`);
}
core.endGroup();
}
catch (err) {
core.setFailed(`mabl deployment task failed for the following reason: ${err}`);
}
});
}
function parseBoolean(toParse) {
return !!(toParse && toParse.toLowerCase() == 'true');
return (toParse === null || toParse === void 0 ? void 0 : toParse.toLowerCase()) === 'true';
}
function getExecutionsStillPending(executionResult) {
return executionResult.executions.filter((execution) => {
Expand All @@ -146,39 +161,32 @@ function getExecutionsStillPending(executionResult) {
});
}
function getRelatedPullRequest() {
const targetUrl = `${GITHUB_BASE_URL}/repos/${process.env.GITHUB_REPOSITORY}/commits/${process.env.GITHUB_SHA}/pulls`;
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
return Promise.resolve();
}
const postOptions = {
method: 'GET',
url: targetUrl,
headers: {
Authorization: `token ${githubToken}`,
Accept: 'application/vnd.github.groot-preview+json',
'Content-Type': 'application/json',
'User-Agent': 'mabl-action',
},
json: true,
};
return request_promise_native_1.default(postOptions)
.then(response => {
if (!response || !response.length) {
var _a;
return __awaiter(this, void 0, void 0, function* () {
const targetUrl = `${GITHUB_BASE_URL}/repos/${process.env.GITHUB_REPOSITORY}/commits/${process.env.GITHUB_SHA}/pulls`;
const githubToken = process.env.GITHUB_TOKEN;
if (!githubToken) {
return;
}
return {
title: response[0].title,
number: response[0].number,
created_at: response[0].created_at,
merged_at: response[0].merged_at,
url: response[0].url,
const config = {
headers: {
Authorization: `token ${githubToken}`,
Accept: 'application/vnd.github.groot-preview+json',
'Content-Type': 'application/json',
'User-Agent': 'mabl-action',
},
};
})
.catch(error => {
if (error.status != 404) {
core.warning(error.message);
const client = axios_1.default.create(config);
try {
const response = yield client.get(targetUrl, config);
return (_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a[0];
}
catch (error) {
if (error.status !== 404) {
core.warning(error.message);
}
}
return;
});
}
run();
File renamed without changes.
Loading

0 comments on commit 9e1a6f2

Please sign in to comment.