Skip to content

Commit

Permalink
Merge ace934b into f7b63d7
Browse files Browse the repository at this point in the history
  • Loading branch information
YOU54F committed Nov 18, 2019
2 parents f7b63d7 + ace934b commit ddd5e0c
Show file tree
Hide file tree
Showing 11 changed files with 155 additions and 1,286 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ coverage
testReports
bin
yarn-error.log
mochareports
mochareports
/.idea/
15 changes: 13 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ For users who are not using CircleCi, you can get a simple report

- pass `--ci-provider none` provider flag to provide a simple slack message based on the mochawesome report status

For jenkins users

- pass `--ci-provider jenkins` provider flag.

## Reporting Features

It provides the following distinct message types
Expand Down Expand Up @@ -82,7 +86,7 @@ Set the following environment variables in your localhost or CI configuration.
Options:
-v, --version output the version number
--vcs-provider [type] VCS Provider [github|bitbucket|none] (default: "github")
--ci-provider [type] CI Provider [circleci|none] (default: "circleci")
--ci-provider [type] CI Provider [circleci|jenkins|none] (default: "circleci")
--report-dir [type] mochawesome json & html test report directory, relative to your package.json (default: "mochareports")
--screenshot-dir [type] cypress screenshot directory, relative to your package.json (default: "cypress/screenshots")
--video-dir [type] cypress video directory, relative to your package.json (default: "cypress/videos")
Expand Down Expand Up @@ -307,4 +311,11 @@ function generateReport(options: any) {
- [X] add usage instructions to readme
- [X] test example
- [X] compile
- [X] Migrate Slack mock to seperate module available at [npm - slack-mock-typed](https://www.npmjs.com/package/slack-mock-typed)
- [X] Migrate Slack mock to seperate module available at [npm - slack-mock-typed](https://www.npmjs.com/package/slack-mock-typed)
- Additional CI providers
- [X] Jenkins

## Contributors

- With thanks to [mikepsinn](https://github.com/mikepsinn) for Jenkins support.

File renamed without changes.
52 changes: 52 additions & 0 deletions config.env.test.jenkins
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
SLACK_WEBHOOK_URL=https://hooks.slack.com/services/TEA926DBJ/BEBB8FPCL/xxx
BUILD_CAUSE=SCMTRIGGER
BUILD_CAUSE_SCMTRIGGER=true
BUILD_DISPLAY_NAME=#2991
BUILD_FOLDER=/home/ubuntu/qm-api
BUILD_ID=2991
BUILD_NUMBER=2991
BUILD_TAG=jenkins-DEPLOY-staging-api-2991
BUILD_URL=http://quantimodo2.asuscomm.com:8082/job/DEPLOY-staging-api/2991/
EXECUTOR_NUMBER=1
GIT_AUTHOR_EMAIL=m@quantimodo.com
GIT_AUTHOR_NAME=Mike Sinn
GIT_BRANCH=origin/develop
GIT_COMMIT=86046896310ab5fd6640cb01d25c11f76277efad
GIT_COMMITTER_EMAIL=m@quantimodo.com
GIT_COMMITTER_NAME=Mike Sinn
GIT_PREVIOUS_COMMIT=4f541bafb9ddfce58eefec504dd0f43575ad969c
GIT_PREVIOUS_SUCCESSFUL_COMMIT=a8c938df241ed5f5a60e96b4a841354648e1f06c
GIT_URL=https://github.com/mikepsinn/qm-api.git
HOME=/var/lib/jenkins
HUDSON_HOME=/var/lib/jenkins
HUDSON_URL=http://quantimodo2.asuscomm.com:8082/
J2SDKDIR=/usr/lib/jvm/java-8-oracle
JAVA_HOME=/var/lib/jenkins/tools/hudson.model.JDK/JDK_8
JENKINS_HOME=/var/lib/jenkins
JENKINS_URL=http://quantimodo2.asuscomm.com:8082/
JOB_BASE_NAME=DEPLOY-staging-api
JOB_DISPLAY_URL=http://quantimodo2.asuscomm.com:8082/job/DEPLOY-staging-api/display/redirect
JOB_NAME=DEPLOY-staging-api
JOB_URL=http://quantimodo2.asuscomm.com:8082/job/DEPLOY-staging-api/
LANG=en_US.UTF-8
LOGNAME=jenkins
MAIL=/var/mail/jenkins
NODE_LABELS=master
NODE_NAME=master
OLDPWD=/var/lib/jenkins/workspace/DEPLOY-staging-api/tmp/qm-ui-tests/scripts
PATH=/var/lib/jenkins/tools/hudson.model.JDK/JDK_8/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
PWD=/var/lib/jenkins/workspace/DEPLOY-staging-api/tmp/qm-ui-tests
ROOT_BUILD_CAUSE=SCMTRIGGER
ROOT_BUILD_CAUSE_SCMTRIGGER=true
RUN_CHANGES_DISPLAY_URL=http://quantimodo2.asuscomm.com:8082/job/DEPLOY-staging-api/2991/display/redirect?page=changes
RUN_DISPLAY_URL=http://quantimodo2.asuscomm.com:8082/job/DEPLOY-staging-api/2991/display/redirect
SCRIPT_FOLDER=/var/lib/jenkins/workspace/DEPLOY-staging-api/tmp/qm-ui-tests/scripts
SHELL=/bin/bash
SHLVL=2
SKIP_FIXING_TIMESTAMP_COLUMNS=1
TERM=xterm-256color
USER=root
WORKSPACE=/var/lib/jenkins/workspace/DEPLOY-staging-api
XDG_RUNTIME_DIR=/run/user/1000
XDG_SESSION_ID=25
ENV_SUT=envsut
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"lint": "tslint --project .",
"lint-fix": "tslint --project . --fix",
"test": "jest --coverage",
"test:jenkins": "cross-env CI_PROVIDER_TO_TEST=jenkins jest --coverage",
"test:ci": "jest --coverage --coverageReporters=text-lcov | coveralls",
"compile": "tsc",
"slack-js": "node bin/index.js --logger",
Expand Down Expand Up @@ -64,8 +65,10 @@
"aws-sdk": "2.574.0",
"aws-sdk-mock": "4.5.0",
"coveralls": "3.0.7",
"cross-env": "^6.0.3",
"cypress": "3.6.1",
"cypress-cucumber-preprocessor": "1.12.0",
"cypress-multi-reporters": "1.2.3",
"dotenv": "8.2.0",
"husky": "3.1.0",
"jest": "24.9.0",
Expand All @@ -74,7 +77,6 @@
"lint-staged": "9.4.3",
"mocha": "6.2.2",
"mocha-junit-reporter": "1.23.1",
"cypress-multi-reporters": "1.2.3",
"mochawesome": "4.1.0",
"mochawesome-merge": "2.1.0",
"mochawesome-report-generator": "4.0.1",
Expand Down
6 changes: 5 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@ program
"VCS Provider [github|bitbucket|none]",
"github"
)
.option("--ci-provider [type]", "CI Provider [circleci|none]", "circleci")
.option(
"--ci-provider [type]",
"CI Provider [circleci|jenkins|none]",
"circleci"
)
.option(
"--report-dir [type]",
"mochawesome json & html test report directory, relative to your package.json",
Expand Down
41 changes: 40 additions & 1 deletion src/slack/slack-alert.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,13 @@ export function getCommitUrl(_vcsRoot: string) {
}
}

export function resolveCIProvider(ciProvider: string) {
export function resolveCIProvider(ciProvider?: string) {
if (!ciProvider && process.env.CIRCLE_SHA1) {
ciProvider = "circleci";
}
if (!ciProvider && process.env.JENKINS_HOME) {
ciProvider = "jenkins";
}
switch (ciProvider) {
case "circleci":
{
Expand Down Expand Up @@ -456,6 +462,39 @@ export function resolveCIProvider(ciProvider: string) {
CI_URL = "https://circleci.com/api/v1.1/project";
}
break;
case "jenkins":
{
const {
GIT_COMMIT,
BRANCH_NAME,
CHANGE_AUTHOR,
BUILD_URL,
BUILD_ID,
CHANGE_ID,
JOB_NAME
} = process.env;
if (typeof process.env.GIT_URL === "undefined") {
throw new Error("GIT_URL not defined!");
}
const urlParts = process.env.GIT_URL.replace(
"https://github.com/",
""
).replace(".git", "");
const arr = urlParts.split("/");
const PROJECT_REPONAME = arr[1];
const PROJECT_USERNAME = arr[0];
(CI_SHA1 = GIT_COMMIT),
(CI_BRANCH = BRANCH_NAME),
(CI_USERNAME = CHANGE_AUTHOR),
(CI_BUILD_URL = BUILD_URL),
(CI_BUILD_NUM = BUILD_ID),
(CI_PULL_REQUEST = CHANGE_ID),
(CI_PROJECT_REPONAME = PROJECT_REPONAME),
(CI_PROJECT_USERNAME = PROJECT_USERNAME),
(CI_CIRCLE_JOB = JOB_NAME);
CI_URL = process.env.JENKINS_URL;
}
break;
default: {
break;
}
Expand Down
4 changes: 2 additions & 2 deletions src/slack/test/setup-tests.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { config } from "dotenv";

const CI_PROVIDER_TO_TEST = process.env.CI_PROVIDER_TO_TEST || "circleci";
if (!process.env.CI) {
config({ path: "./config.env.test" });
config({ path: "./config.env.test." + CI_PROVIDER_TO_TEST });
}
10 changes: 6 additions & 4 deletions src/slack/test/slack-alert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { IncomingWebhookDefaultArguments } from "@slack/webhook";
import "jest";
import * as path from "path";
import * as slacker from "../slack-alert";

const isWin = process.platform === "win32";
jest.setTimeout(10000);

describe("webhookInitialArgs tester", () => {
Expand Down Expand Up @@ -112,9 +112,11 @@ describe("Get Files Checker", () => {
const fileList: string[] = [];
const s = await slacker.getFiles(dir, ext, fileList);
const rootDir: string = path.dirname(__dirname);
expect(s).toEqual([
`${rootDir}/test/reportSingle/report-20190403-233436.html`
]);
let expected = `${rootDir}/test/reportSingle/report-20190403-233436.html`;
if (isWin) {
expected = `${rootDir}\\test\\reportSingle/report-20190403-233436.html`;
}
expect(s).toEqual([expected]);
});
test("Returns an empty array if no specified filetypes are found ", async () => {
const dir: string = path.join(__dirname, "reportSingle");
Expand Down
3 changes: 1 addition & 2 deletions tsconfig.jest.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@
"jest",
"commander/typings",
"@types/dotenv",
"slack-mock-typed",
"@types/dotenv",
"slack-mock-typed"
]
},
"exclude": [
Expand Down

0 comments on commit ddd5e0c

Please sign in to comment.