diff --git a/Jenkinsfile b/Jenkinsfile index 544b8452219cbac150a540f29c8dd72942079a58..625d971c928f4a2d94542ab2fab7a47be3708cc4 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -1,3 +1,5 @@ +def FAILED_STAGE + pipeline { agent { node { @@ -5,38 +7,69 @@ pipeline { } } + environment { + BLUE_OCEAN_URL = "https://jenkins-dev-tools.apps.lab.okd.local/blue/organizations/jenkins/OZG%2Fgoofy/detail/${env.BRANCH_NAME}/${env.BUILD_NUMBER}/pipeline" + } + options { timeout(time: 1, unit: 'HOURS') disableConcurrentBuilds() + buildDiscarder(logRotator(numToKeepStr: '5')) } stages { - stage('client build') { + stage('Client') { steps { + script { + FAILED_STAGE=env.STAGE_NAME + } container("nodejs"){ sh 'npm --version' dir('goofy-client') { sh 'npm install' - sh 'npm run build' - sh 'npm run test' + sh 'npm run ci-build' + sh 'npm run ci-test' } } } + post { + always{ + junit testResults: 'goofy-client/junit.xml', skipPublishingChecks: true + + publishHTML (target: [ + allowMissing: false, + alwaysLinkToLastBuild: false, + keepAll: true, + reportDir: 'goofy-client/coverage/lcov-report', + reportFiles: 'index.html', + reportName: "Goofy-Client code coverage" + ]) + } + } } - stage('server build') { + stage('Server') { steps { + script { + FAILED_STAGE=env.STAGE_NAME + } container("maven"){ sh 'mvn --version' sh 'mvn -pl -goofy-client clean install' } } + post { + always{ + junit testResults: '**/target/surefire-reports/*.xml', skipPublishingChecks: true + } + } } - stage('openshift deploy') { + stage('Openshift build') { steps { script { + FAILED_STAGE=env.STAGE_NAME def pom = readMavenPom file: 'pom.xml' def version = pom.version @@ -47,11 +80,92 @@ pipeline { } openshift.tag("goofy-builder:latest", "goofy-builder:${env.BRANCH_NAME}-${version}") + + if (env.BRANCH_NAME == 'master') { + def dc = openshift.selector('dc', 'goofy-e2e') + openshift.tag("goofy-builder:latest", "goofy-builder:e2e-latest") + dc.rollout().status() + } + } + } + } + } + } + + stage('E2E-Test') { + when { + branch 'master' + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + } + container("cypress"){ + sh 'npm --version' + dir('goofy-client') { + sh 'npm install' + sh 'npm run cypress:version' + sh 'npm run cypress:ci-run' + } + } + } + post { + always { + publishHTML (target: [ + allowMissing: false, + alwaysLinkToLastBuild: false, + keepAll: true, + reportDir: 'goofy-client/apps/goofy-e2e/reports', + reportFiles: 'report.html', + reportName: "Goofy E2E-Tests" + ]) + } + } + } + + stage('Openshift deploy') { + when { + anyOf { + branch 'master'; + branch 'release' + } + } + steps { + script { + FAILED_STAGE=env.STAGE_NAME + def pom = readMavenPom file: 'pom.xml' + def version = pom.version + + openshift.withCluster() { + openshift.withProject() { openshift.tag("goofy-builder:${env.BRANCH_NAME}-${version}", "sh-kiel-dev/goofy:${env.BRANCH_NAME}-${version}") - } + } + if (env.BRANCH_NAME == 'master') { + openshift.withProject('sh-kiel-dev') { + def dc = openshift.selector('deployments', 'goofy') + + dc.rollout().status() + } + } } } } - } + } + } + post { + success { + script { + if (env.BRANCH_NAME == 'master') { + slackSend(color: "good", message: "Goofy: Build Succeeded. Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>") + } + } + } + failure { + script { + if (env.BRANCH_NAME == 'master') { + slackSend(color: "danger", message: "Goofy: Build Failed. Stage: ${FAILED_STAGE} Build-ID: <${BLUE_OCEAN_URL}|${env.BUILD_NUMBER}>") + } + } + } } } \ No newline at end of file diff --git a/goofy-client/.gitignore b/goofy-client/.gitignore index ee5c9d8336b76b3bb5658d0888bdec86eb7b0990..f14824446dbbf8f70dc7e64783c0c948a26bd876 100644 --- a/goofy-client/.gitignore +++ b/goofy-client/.gitignore @@ -4,6 +4,8 @@ /dist /tmp /out-tsc +junit.xml +/apps/goofy-e2e/reports # dependencies /node_modules diff --git a/goofy-client/apps/goofy-e2e/cypress-ci.json b/goofy-client/apps/goofy-e2e/cypress-ci.json new file mode 100644 index 0000000000000000000000000000000000000000..c18365590219a9ae25a54441da62125df0899117 --- /dev/null +++ b/goofy-client/apps/goofy-e2e/cypress-ci.json @@ -0,0 +1,22 @@ +{ + "baseUrl": "http://goofy-e2e-dev-tools.apps.lab.okd.local/", + "fileServerFolder": ".", + "fixturesFolder": "./src/fixtures", + "integrationFolder": "./src/integration", + "modifyObstructiveCode": false, + "pluginsFile": "./src/plugins/index", + "supportFile": "./src/support/index.ts", + "video": true, + "videosFolder": "./reports/videos", + "screenshotsFolder": "./reports/screenshots", + "chromeWebSecurity": false, + "reporter": "../../node_modules/cypress-mochawesome-reporter", + "reporterOptions": { + "html": false, + "json": true, + "quite": true, + "reportDir": "./reports/mochawesome-report", + "reportFilename": "report", + "overwrite": false + } + } \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/cypress.json b/goofy-client/apps/goofy-e2e/cypress.json index 1a4b828d9393dd1fbc3fd7569b28464e60a8988f..b30a06e628bd3cf9034737ff876e5885e1d50a43 100644 --- a/goofy-client/apps/goofy-e2e/cypress.json +++ b/goofy-client/apps/goofy-e2e/cypress.json @@ -1,4 +1,5 @@ { + "baseUrl": "http://localhost:8080", "fileServerFolder": ".", "fixturesFolder": "./src/fixtures", "integrationFolder": "./src/integration", @@ -6,7 +7,15 @@ "pluginsFile": "./src/plugins/index", "supportFile": "./src/support/index.ts", "video": true, - "videosFolder": "./recordings/videos", - "screenshotsFolder": "./recordings/screenshots", - "chromeWebSecurity": false -} + "videosFolder": "./reports/videos", + "screenshotsFolder": "./reports/screenshots", + "chromeWebSecurity": false, + "reporter": "../../node_modules/cypress-mochawesome-reporter", + "reporterOptions": { + "html": false, + "json": true, + "reportDir": "./reports/mochawesome-report", + "reportFilename": "report", + "overwrite": true + } +} \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/recordings/.gitignore b/goofy-client/apps/goofy-e2e/recordings/.gitignore deleted file mode 100644 index f59ec20aabf5842d237244ece8c81ab184faeac1..0000000000000000000000000000000000000000 --- a/goofy-client/apps/goofy-e2e/recordings/.gitignore +++ /dev/null @@ -1 +0,0 @@ -* \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/src/integration/app.spec.ts b/goofy-client/apps/goofy-e2e/src/integration/app.spec.ts index b5fe4c37d2a6a27677c742c3c46855e1e89f3b51..9357bd02c5836004941b0338a2e0d6ddc9984073 100644 --- a/goofy-client/apps/goofy-e2e/src/integration/app.spec.ts +++ b/goofy-client/apps/goofy-e2e/src/integration/app.spec.ts @@ -1,4 +1,4 @@ -import { MainPage } from '../page-abjects/main.po'; +import { MainPage } from '../page-objects/main.po'; describe('goofy', () => { const mainPage: MainPage = new MainPage(); diff --git a/goofy-client/apps/goofy-e2e/src/page-abjects/header.po.ts b/goofy-client/apps/goofy-e2e/src/page-objects/header.po.ts similarity index 100% rename from goofy-client/apps/goofy-e2e/src/page-abjects/header.po.ts rename to goofy-client/apps/goofy-e2e/src/page-objects/header.po.ts diff --git a/goofy-client/apps/goofy-e2e/src/page-abjects/main.po.ts b/goofy-client/apps/goofy-e2e/src/page-objects/main.po.ts similarity index 84% rename from goofy-client/apps/goofy-e2e/src/page-abjects/main.po.ts rename to goofy-client/apps/goofy-e2e/src/page-objects/main.po.ts index 1072d299af08aed8b4e7f961eaf5667e3b1f66fa..e10ed195fbcf13e1dd1614a707ed214d951f0d99 100644 --- a/goofy-client/apps/goofy-e2e/src/page-abjects/main.po.ts +++ b/goofy-client/apps/goofy-e2e/src/page-objects/main.po.ts @@ -8,7 +8,7 @@ export class MainPage{ } public open(){ - cy.visit('http://localhost:4300/'); + cy.visit('/'); } public getTitle(){ diff --git a/goofy-client/apps/goofy-e2e/src/support/delete-old-reports.ts b/goofy-client/apps/goofy-e2e/src/support/delete-old-reports.ts new file mode 100644 index 0000000000000000000000000000000000000000..31a5d9326928d9357f0d324f0de904bc89a9847b --- /dev/null +++ b/goofy-client/apps/goofy-e2e/src/support/delete-old-reports.ts @@ -0,0 +1,3 @@ +const fs = require("fs") + +fs.rmdirSync("apps/goofy-e2e/reports/mochawesome-report", {recursive: true}); \ No newline at end of file diff --git a/goofy-client/apps/goofy-e2e/src/support/index.ts b/goofy-client/apps/goofy-e2e/src/support/index.ts index 3d469a6b6cf31eb66117d73e278bcf74f398f1db..78678b6f51d8e72a9d9a0b02013c952fe0d03d93 100644 --- a/goofy-client/apps/goofy-e2e/src/support/index.ts +++ b/goofy-client/apps/goofy-e2e/src/support/index.ts @@ -15,3 +15,4 @@ // Import commands.js using ES2015 syntax: import './commands'; +import 'cypress-mochawesome-reporter/register'; \ No newline at end of file diff --git a/goofy-client/package.json b/goofy-client/package.json index 444a8ed6fa61020871b79e653b11f722d2120598..3af331bc48553b03a9630d9147e13f8999c47619 100644 --- a/goofy-client/package.json +++ b/goofy-client/package.json @@ -14,7 +14,7 @@ "test:lib": "run-s \"ng -- test {1} --watchAll\" --", "test:debug:lib": "run-s \"ng -- test {1} --detectOpenHandles --watchAll\" --", "ci-build": "ng build", - "ci-test": "jest test a", + "ci-test": "jest test a --ci --coverage --testResultsProcessor='jest-junit'", "lint": "nx workspace-lint && ng lint", "e2e": "ng e2e", "affected:apps": "nx affected:apps", @@ -33,7 +33,14 @@ "dep-graph": "nx dep-graph", "help": "nx help", "favicon": "real-favicon generate favicon/faviconDescription.json favicon/faviconData.json src/favicon", - "cypress:open": "npx cypress open --project apps/goofy-e2e" + "cypress:open": "npx cypress open --project apps/goofy-e2e", + "cypress:run": "npx cypress run --project apps/goofy-e2e", + "cypress:version": "npx cypress version", + "cypress:merge-report": "mochawesome-merge apps/goofy-e2e/reports/mochawesome-report/*.json > apps/goofy-e2e/reports/report.json", + "cypress:generate-html": "marge apps/goofy-e2e/reports/report.json -f report -o apps/goofy-e2e/reports/", + "cypress:delete-old-reports": "node apps/goofy-e2e/src/support/delete-old-reports.ts", + "cypress:generate-report": "npm run cypress:merge-report ; npm run cypress:generate-html", + "cypress:ci-run": "npm run cypress:delete-old-reports ; npm run cypress:run -- --config-file ./cypress-ci.json ; test=$(echo \"$?\") ; npm run cypress:generate-report ; exit $test" }, "private": true, "dependencies": { @@ -75,12 +82,14 @@ "@typescript-eslint/parser": "4.3.0", "codelyzer": "~5.0.1", "cypress": "^5.6.0", + "cypress-mochawesome-reporter": "^1.3.0", "dotenv": "6.2.0", "eslint": "7.10.0", "eslint-config-prettier": "6.0.0", "eslint-plugin-cypress": "^2.10.3", "jest": "^26.2.2", "jest-createspyobj": "^2.0.0", + "jest-junit": "^12.0.0", "jest-preset-angular": "8.3.1", "prettier": "2.0.4", "ts-jest": "26.4.0",