Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Circle url update #1089

Merged
merged 10 commits into from
Apr 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 28 additions & 28 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions config.env.test.circleci
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ LOG_LEVEL=debug
CIRCLE_JOB=jobName
ENV_SUT=envsut
CIRCLE_PROJECT_ID=177880476
CIRCLE_WORKFLOW_JOB_ID=177880476
57 changes: 29 additions & 28 deletions src/slack/slack-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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(",");
Expand All @@ -147,7 +147,7 @@ export const slackRunner = async ({
"Slack message sent successfully"
);
return result;
} catch (e) {
} catch (e: any) {
e.code
? log.error(
{
Expand Down Expand Up @@ -198,7 +198,7 @@ export const slackRunner = async ({
"Slack message sent successfully"
);
return result;
} catch (e) {
} catch (e: any) {
e.code
? log.error(
{
Expand All @@ -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(",");
Expand All @@ -244,7 +243,7 @@ export const slackRunner = async ({
);

return result;
} catch (e) {
} catch (e: any) {
e.code
? log.error(
{
Expand All @@ -267,7 +266,7 @@ export const slackRunner = async ({
}
}
}
} catch (e) {
} catch (e: any) {
throw new Error(e);
}
};
Expand Down Expand Up @@ -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`;
})
);
Expand Down Expand Up @@ -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`;
})
);
Expand Down Expand Up @@ -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 "";
};
Expand Down Expand Up @@ -717,6 +712,7 @@ const resolveCIProvider = async (ciProvider?: string): Promise<CiEnvVars> => {
CI_PROJECT_USERNAME,
JOB_NAME,
CIRCLE_PROJECT_ID,
CIRCLE_WORKFLOW_JOB_ID,
} = process.env;

if (!ciProvider && process.env.CIRCLE_SHA1) {
Expand All @@ -739,20 +735,24 @@ const resolveCIProvider = async (ciProvider?: string): Promise<CiEnvVars> => {
(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":
Expand Down Expand Up @@ -799,6 +799,7 @@ const resolveCIProvider = async (ciProvider?: string): Promise<CiEnvVars> => {
CI_PROJECT_USERNAME,
JOB_NAME,
CIRCLE_PROJECT_ID,
CIRCLE_WORKFLOW_JOB_ID,
};
};

Expand Down
6 changes: 4 additions & 2 deletions src/slack/test/slack-alert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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 () => {
Expand Down Expand Up @@ -102,7 +104,7 @@ describe("Video Link Checker", () => {
videosDir: dir,
});
expect(s).toContain(
`<http://sometesturl.com/${dir}/small.mp4|Video:- small.mp4>`
`<http://sometesturl.com${dir}/small.mp4|Video:- small.mp4>`
);
});

Expand Down Expand Up @@ -153,7 +155,7 @@ describe("Screenshot Link Checker", () => {
screenshotDir: dir,
});
expect(s).toContain(
`<http://sometesturl.com/${dir}/pnggrad16rgb.png|Screenshot:- pnggrad16rgb.png>`
`<http://sometesturl.com${dir}/pnggrad16rgb.png|Screenshot:- pnggrad16rgb.png>`
);
});
});
Expand Down