diff --git a/.circleci/config.yml b/.circleci/config.yml index 631773558..500b3e43c 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -54,38 +54,38 @@ jobs: path: cypress/videos - store_artifacts: path: cypress/screenshots - - run: - when: always - name: Slack Custom Reporting via typeScript source File - command: yarn run slack-ts + # - run: + # when: always + # name: Slack Custom Reporting via typeScript source File + # command: yarn run slack-ts - run: when: always name: Slack Custom Reporting via JavaScript Compiled File command: yarn run slack-js - - run: - when: always - name: Slack Custom Reporting via typeScript source File with opts - command: yarn run slack-ts-opts - - run: - when: always - name: Slack Custom Reporting via JavaScript Compiled File with opts - command: yarn run slack-js-opts - - run: - when: always - name: Generate Test Passing Slack Alert - command: yarn run slack-js-opts-test-passed - - run: - when: always - name: Generate Test Failing Slack Alert - command: yarn run slack-js-opts-test-failed - - run: - when: always - name: Generate Build Failure Slack Alert - command: yarn run slack-js-opts-build-failed - - run: - when: always - name: Run the CLI Cypress Runner - command: yarn run cli + # - run: + # when: always + # name: Slack Custom Reporting via typeScript source File with opts + # command: yarn run slack-ts-opts + # - run: + # when: always + # name: Slack Custom Reporting via JavaScript Compiled File with opts + # command: yarn run slack-js-opts + # - run: + # when: always + # name: Generate Test Passing Slack Alert + # command: yarn run slack-js-opts-test-passed + # - run: + # when: always + # name: Generate Test Failing Slack Alert + # command: yarn run slack-js-opts-test-failed + # - run: + # when: always + # name: Generate Build Failure Slack Alert + # command: yarn run slack-js-opts-build-failed + # - run: + # when: always + # name: Run the CLI Cypress Runner + # command: yarn run cli - store_artifacts: path: src/slack/test - store_artifacts: diff --git a/config.env.test.circleci b/config.env.test.circleci index 9071bfe09..a3f99781f 100644 --- a/config.env.test.circleci +++ b/config.env.test.circleci @@ -17,3 +17,4 @@ LOG_LEVEL=debug CIRCLE_JOB=jobName ENV_SUT=envsut CIRCLE_PROJECT_ID=177880476 +CIRCLE_WORKFLOW_JOB_ID=177880476 diff --git a/src/slack/slack-alert.ts b/src/slack/slack-alert.ts index 6728dfd09..74134ecea 100644 --- a/src/slack/slack-alert.ts +++ b/src/slack/slack-alert.ts @@ -48,6 +48,7 @@ export interface CiEnvVars { CI_PROJECT_USERNAME: string | undefined; JOB_NAME: string | undefined; CIRCLE_PROJECT_ID: string | undefined; + CIRCLE_WORKFLOW_JOB_ID: string | undefined; } interface ReportStatistics { @@ -113,14 +114,13 @@ export const slackRunner = async ({ }); const SLACK_WEBHOOK_URL = process.env.SLACK_WEBHOOK_URL; - if (!SLACK_WEBHOOK_URL){ - throw new Error('no SLACK_WEBHOOK_URL env var set') + if (!SLACK_WEBHOOK_URL) { + throw new Error("no SLACK_WEBHOOK_URL env var set"); } switch (reportStatistics.status) { case "failed": { - const slackWebhookFailedUrl = process.env - .SLACK_WEBHOOK_FAILED_URL; + const slackWebhookFailedUrl = process.env.SLACK_WEBHOOK_FAILED_URL; const slackWebhookUrls = slackWebhookFailedUrl ? slackWebhookFailedUrl.split(",") : SLACK_WEBHOOK_URL.split(","); @@ -147,7 +147,7 @@ export const slackRunner = async ({ "Slack message sent successfully" ); return result; - } catch (e) { + } catch (e: any) { e.code ? log.error( { @@ -198,7 +198,7 @@ export const slackRunner = async ({ "Slack message sent successfully" ); return result; - } catch (e) { + } catch (e: any) { e.code ? log.error( { @@ -220,8 +220,7 @@ export const slackRunner = async ({ ); } default: { - const slackWebhookErrorUrl = process.env - .SLACK_WEBHOOK_ERROR_URL; + const slackWebhookErrorUrl = process.env.SLACK_WEBHOOK_ERROR_URL; const slackWebhookUrls = slackWebhookErrorUrl ? slackWebhookErrorUrl.split(",") : SLACK_WEBHOOK_URL.split(","); @@ -244,7 +243,7 @@ export const slackRunner = async ({ ); return result; - } catch (e) { + } catch (e: any) { e.code ? log.error( { @@ -267,7 +266,7 @@ export const slackRunner = async ({ } } } - } catch (e) { + } catch (e: any) { throw new Error(e); } }; @@ -600,9 +599,11 @@ const getVideoLinks = async ({ const videoLinks = await Promise.all( videos.map((videoObject) => { const trimmedVideoFilename = path.basename(videoObject); - return `<${videosURL}/${videosDir}/${path.relative( + + return `<${buildUrl( + videosURL, videosDir, - videoObject + path.relative(videosDir, videoObject) )}|Video:- ${trimmedVideoFilename}>\n`; }) ); @@ -640,9 +641,11 @@ const getScreenshotLinks = async ({ const screenshotLinks = await Promise.all( screenshots.map((screenshotObject) => { const trimmedScreenshotFilename = path.basename(screenshotObject); - return `<${screenshotURL}/${screenshotDir}/${path.relative( + + return `<${buildUrl( + screenshotURL, screenshotDir, - screenshotObject + path.relative(screenshotDir, screenshotObject) )}|Screenshot:- ${trimmedScreenshotFilename}>\n`; }) ); @@ -676,15 +679,7 @@ const getArtefactUrl = async ({ if (customUrl) { return customUrl; } else if (ciProvider === "circleci") { - switch (vcsRoot) { - case "github": - return `https://${ciEnvVars.CI_BUILD_NUM}-${ciEnvVars.CIRCLE_PROJECT_ID}-gh.circle-artifacts.com/0/`; - case "bitbucket": - return `https://${ciEnvVars.CI_BUILD_NUM}-${ciEnvVars.CIRCLE_PROJECT_ID}-bb.circle-artifacts.com/0/`; - default: { - return ""; - } - } + return `https://output.circle-artifacts.com/output/job/${ciEnvVars.CIRCLE_WORKFLOW_JOB_ID}/artifacts/0/`; } return ""; }; @@ -717,6 +712,7 @@ const resolveCIProvider = async (ciProvider?: string): Promise => { CI_PROJECT_USERNAME, JOB_NAME, CIRCLE_PROJECT_ID, + CIRCLE_WORKFLOW_JOB_ID, } = process.env; if (!ciProvider && process.env.CIRCLE_SHA1) { @@ -739,20 +735,24 @@ const resolveCIProvider = async (ciProvider?: string): Promise => { (CI_PROJECT_USERNAME = process.env.CIRCLE_PROJECT_USERNAME), (JOB_NAME = process.env.CIRCLE_JOB); CIRCLE_PROJECT_ID = process.env.CIRCLE_PROJECT_ID; + CIRCLE_WORKFLOW_JOB_ID = process.env.CIRCLE_WORKFLOW_JOB_ID; } break; case "github": { (CI_SHA1 = process.env.GITHUB_SHA), - (CI_BRANCH = process.env.GITHUB_BASE_REF||process.env.GITHUB_HEAD_REF), + (CI_BRANCH = + process.env.GITHUB_BASE_REF || process.env.GITHUB_HEAD_REF), (CI_USERNAME = process.env.GITHUB_ACTOR), - (CI_BUILD_URL = process.env.CIRCLE_BUILD_URL|| 'CI_BUILD_URL'), - (CI_BUILD_NUM = process.env.CIRCLE_BUILD_NUM|| 'CIRCLE_BUILD_NUM'), - (CI_PULL_REQUEST = process.env.CIRCLE_PULL_REQUEST|| 'CIRCLE_PULL_REQUEST'), + (CI_BUILD_URL = process.env.CIRCLE_BUILD_URL || "CI_BUILD_URL"), + (CI_BUILD_NUM = process.env.CIRCLE_BUILD_NUM || "CIRCLE_BUILD_NUM"), + (CI_PULL_REQUEST = + process.env.CIRCLE_PULL_REQUEST || "CIRCLE_PULL_REQUEST"), (CI_PROJECT_REPONAME = process.env.GITHUB_REPOSITORY), // The owner and repository name. For example, octocat/Hello-World. (CI_PROJECT_USERNAME = process.env.GITHUB_REPOSITORY_OWNER), (JOB_NAME = process.env.GITHUB_ACTION); - CIRCLE_PROJECT_ID = process.env.CIRCLE_PROJECT_ID|| 'CIRCLE_PROJECT_ID'; + CIRCLE_PROJECT_ID = + process.env.CIRCLE_PROJECT_ID || "CIRCLE_PROJECT_ID"; } break; case "jenkins": @@ -799,6 +799,7 @@ const resolveCIProvider = async (ciProvider?: string): Promise => { CI_PROJECT_USERNAME, JOB_NAME, CIRCLE_PROJECT_ID, + CIRCLE_WORKFLOW_JOB_ID, }; }; diff --git a/src/slack/test/slack-alert.test.ts b/src/slack/test/slack-alert.test.ts index dd14a4ef6..00c148883 100644 --- a/src/slack/test/slack-alert.test.ts +++ b/src/slack/test/slack-alert.test.ts @@ -3,6 +3,7 @@ import { MessageAttachment } from "@slack/types"; import "jest"; import * as path from "path"; +import { env } from "process"; import { testables } from "../slack-alert"; const { buildHTMLReportURL, @@ -30,6 +31,7 @@ const envVars = { CI_PROJECT_USERNAME: "123", JOB_NAME: "123", CIRCLE_PROJECT_ID: "123", + CIRCLE_WORKFLOW_JOB_ID: "123", }; describe("webhookInitialArgs tester", () => { test("it returns the test status in the title", async () => { @@ -102,7 +104,7 @@ describe("Video Link Checker", () => { videosDir: dir, }); expect(s).toContain( - `` + `` ); }); @@ -153,7 +155,7 @@ describe("Screenshot Link Checker", () => { screenshotDir: dir, }); expect(s).toContain( - `` + `` ); }); });