diff --git a/lib/src/constants.js b/lib/src/constants.js index 5baf2673..c654ee25 100644 --- a/lib/src/constants.js +++ b/lib/src/constants.js @@ -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"; @@ -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 = {})); diff --git a/lib/src/index.js b/lib/src/index.js index 64be4fb9..28a91e14 100644 --- a/lib/src/index.js +++ b/lib/src/index.js @@ -15,18 +15,31 @@ 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"); @@ -34,7 +47,7 @@ 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', @@ -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, @@ -62,7 +74,6 @@ function optionalInput(name) { } return; } -exports.optionalInput = optionalInput; function booleanInput(name) { return (core .getInput(name, { @@ -70,7 +81,6 @@ function booleanInput(name) { }) .toLowerCase() === 'true'); } -exports.booleanInput = booleanInput; async function run(enableFailureExitCodes = true) { const wrappedFailed = (message) => { if (enableFailureExitCodes) { @@ -90,6 +100,8 @@ 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); @@ -97,6 +109,13 @@ async function run(enableFailureExitCodes = true) { 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, @@ -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) { @@ -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; @@ -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 { diff --git a/lib/src/mablApiClient.js b/lib/src/mablApiClient.js index 8479caa9..dc107595 100644 --- a/lib/src/mablApiClient.js +++ b/lib/src/mablApiClient.js @@ -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'; @@ -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; @@ -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) => { diff --git a/lib/src/table.js b/lib/src/table.js index e06e264f..ae33fd62 100644 --- a/lib/src/table.js +++ b/lib/src/table.js @@ -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) { @@ -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 '); } diff --git a/lib/test/suite.test.js b/lib/test/suite.test.js index c8c51b51..e60419d9 100644 --- a/lib/test/suite.test.js +++ b/lib/test/suite.test.js @@ -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, ''); @@ -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', @@ -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', @@ -131,7 +132,7 @@ 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', () => { @@ -139,7 +140,7 @@ describe('GitHub Action tests', () => { 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', @@ -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: 'git@github.com: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: 'git@github.com: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); }); }); diff --git a/node_modules/@actions/core/README.md b/node_modules/@actions/core/README.md index 8a471430..ac8ced92 100644 --- a/node_modules/@actions/core/README.md +++ b/node_modules/@actions/core/README.md @@ -333,3 +333,154 @@ toPlatformPath('/foo/bar') // => \foo\bar // On a Linux runner. toPlatformPath('\\foo\\bar') // => /foo/bar ``` + +#### Platform helper + +Provides shorthands for getting information about platform action is running on. + +```js +import { platform } from '@actions/core' + +/* equals to a call of os.platform() */ +platform.platform // 'win32' | 'darwin' | 'linux' | 'freebsd' | 'openbsd' | 'android' | 'cygwin' | 'sunos' + +/* equals to a call of os.arch() */ +platform.arch // 'x64' | 'arm' | 'arm64' | 'ia32' | 'mips' | 'mipsel' | 'ppc' | 'ppc64' | 'riscv64' | 's390' | 's390x' + +/* common shorthands for platform-specific logic */ +platform.isWindows // true +platform.isMacOS // false +platform.isLinux // false + +/* run platform-specific script to get more details about the exact platform, works on Windows, MacOS and Linux */ +const { + name, // Microsoft Windows 11 Enterprise + version, // 10.0.22621 +} = await platform.getDetails() +``` + +#### Populating job summary + +These methods can be used to populate a [job summary](https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#adding-a-job-summary). A job summary is a buffer that can be added to throughout your job via `core.summary` methods. + +Job summaries when complete must be written to the summary buffer file via the `core.summary.write()` method. + +All methods except `addRaw()` utilize the `addRaw()` method to append to the buffer, followed by an EOL using the `addEOL()` method. + +```typescript + +// Write raw text, optionally add an EOL after the content, defaults to false +core.summary.addRaw('Some content here :speech_balloon:', true) +// Output: Some content here :speech_balloon:\n + +// Add an operating system-specific end-of-line marker +core.summary.addEOL() +// Output (POSIX): \n +// Output (Windows): \r\n + +// Add a codeblock with an optional language for syntax highlighting +core.summary.addCodeBlock('console.log(\'hello world\')', 'javascript') +// Output:
console.log('hello world')
+
+// Add a list, second parameter indicates if list is ordered, defaults to false
+core.summary.addList(['item1','item2','item3'], true)
+// Output: To be or not to be+ +// Add an HTML anchor tag +core.summary.addLink('click here', 'https://github.com') +// Output: click here + +``` + +Tables are added using the `addTable()` method, and an array of `SummaryTableRow`. + +```typescript + +export type SummaryTableRow = (SummaryTableCell | string)[] + +export interface SummaryTableCell { + /** + * Cell content + */ + data: string + /** + * Render cell as header + * (optional) default: false + */ + header?: boolean + /** + * Number of columns the cell extends + * (optional) default: '1' + */ + colspan?: string + /** + * Number of rows the cell extends + * (optional) default: '1' + */ + rowspan?: string +} + +``` + +For example + +```typescript + +const tableData = [ + {data: 'Header1', header: true}, + {data: 'Header2', header: true}, + {data: 'Header3', header: true}, + {data: 'MyData1'}, + {data: 'MyData2'}, + {data: 'MyData3'} +] + +// Add an HTML table +core.summary.addTable([tableData]) +// Output:
Header1 | Header2 | Header3 |
---|---|---|
MyData1 | MyData2 | MyData3 |
Alloy is the integration development platform that makes it simple and
fast for SaaS companies to launch critical user-facing integrations.
- Sign up free • - Documentation -
-
-
-
-
- API-first authentication, authorization, and fraud prevention -- Website • - Documentation • Node.js Backend SDK - - |
-
-
-
-
- Drag-and-drop authentication, authorization, and identity management -- Website • - Documentation • Community - - |
-
API-first authentication, authorization, and fraud prevention + | We’re bound by one common purpose: to give you the financial tools, resources and information you ne... + | Hi, we're Descope! We are building something in the authentication space for app developers and... + |
At Buzzoid, you can buy Instagram followers quickly, safely, and easily with just a few clicks. Rate... + | At Famety, you can grow your social media following quickly, safely, and easily with just a few clic... + | Buy Instagram Likes + |
💜 Become a sponsor + | 💜 Become a sponsor + | 💜 Become a sponsor + |