From 41830e4ec7ba5429f2cd728bd926ea48b466a0bf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Pe=CC=81ter=20Nya=CC=81ri?=
Date: Mon, 3 Jun 2019 16:11:00 +0200
Subject: [PATCH] Pipeline changes
---
.gitignore | 1 +
ci/Dockerfile | 63 ---------------------
ci/Dockerfile.build | 22 ++++++++
ci/Jenkinsfile | 77 ++++++++++++++++++--------
package-lock.json | 18 ++++++
package.json | 1 +
projects/docs/karma.conf.js | 9 ++-
projects/gentics-ui-core/karma.conf.js | 10 +++-
8 files changed, 111 insertions(+), 90 deletions(-)
delete mode 100644 ci/Dockerfile
create mode 100644 ci/Dockerfile.build
diff --git a/.gitignore b/.gitignore
index 044b16aa..e86cb3aa 100644
--- a/.gitignore
+++ b/.gitignore
@@ -38,6 +38,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
+/.reports
# System Files
.DS_Store
diff --git a/ci/Dockerfile b/ci/Dockerfile
deleted file mode 100644
index 01068c5c..00000000
--- a/ci/Dockerfile
+++ /dev/null
@@ -1,63 +0,0 @@
-FROM node:10-alpine AS builder
-LABEL maintainer="p.nyari@gentics.com"
-ARG BUILD_USER="jenkins"
-# Installs latest Chromium package
-RUN echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
- && echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
- && apk add --no-cache \
- chromium@edge \
- harfbuzz@edge \
- nss@edge \
- freetype@edge \
- ttf-freefont@edge \
- git \
- && rm -rf /var/cache/* \
- && mkdir /var/cache/apk
-ENV CHROME_BIN /usr/bin/chromium-browser
-ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
-RUN adduser -D -u 10000 -h /ci ${BUILD_USER}
-RUN chown ${BUILD_USER}: /ci -R
-USER ${BUILD_USER}
-WORKDIR /ci
-LABEL stage=builder
-
-# Setup dependencies
-FROM builder as dependencies
-COPY package.json package-lock.json ./
-RUN npm set progress=false \
- && npm config set depth 0
-RUN npm ci
-COPY --chown=10000 . .
-ARG CACHEBUST=1
-RUN echo "Rebuild from here (unique number: $CACHEBUST)"
-LABEL stage=buildenv
-
-# Run unit tests
-FROM dependencies AS test
-ARG linting=false
-ARG testing=false
-RUN [ "$linting" != true ] || npm run lint
-RUN [ "$testing" != true ] || npm run test -- --watch=false --browsers=ChromeHeadlessCI --reporters=junit
-LABEL stage=test
-
-# Build application
-FROM dependencies AS build
-RUN npm run build -- --progress=false
-LABEL stage=build
-
-# Release to NPM
-FROM dependencies AS release
-ARG releaseProjectName='gentics-ui-core'
-ARG release=false
-ARG releaseNext=false
-ARG releaseVersion=''
-RUN sh ci/release.sh
-LABEL stage=release
-
-# Publish Docs on Github Pages
-FROM dependencies AS docs
-ARG GIT_BRANCH=''
-ARG publishDocs=false
-ARG docsVersion=''
-RUN sh ci/publishDocs.sh
-LABEL stage=docs
\ No newline at end of file
diff --git a/ci/Dockerfile.build b/ci/Dockerfile.build
new file mode 100644
index 00000000..12cc031c
--- /dev/null
+++ b/ci/Dockerfile.build
@@ -0,0 +1,22 @@
+FROM node:10-alpine
+LABEL maintainer="p.nyari@gentics.com"
+ARG BUILD_USER="jenkins"
+# Installs latest Chromium package
+RUN echo @edge http://nl.alpinelinux.org/alpine/edge/community >> /etc/apk/repositories \
+ && echo @edge http://nl.alpinelinux.org/alpine/edge/main >> /etc/apk/repositories \
+ && apk add --no-cache \
+ chromium@edge \
+ harfbuzz@edge \
+ nss@edge \
+ freetype@edge \
+ ttf-freefont@edge \
+ git \
+ && rm -rf /var/cache/* \
+ && mkdir /var/cache/apk
+ENV CHROME_BIN /usr/bin/chromium-browser
+ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true
+RUN adduser -D -u 10000 -h /ci ${BUILD_USER}
+COPY . /ci
+RUN chown ${BUILD_USER}: /ci -R
+USER ${BUILD_USER}
+WORKDIR /ci
\ No newline at end of file
diff --git a/ci/Jenkinsfile b/ci/Jenkinsfile
index 9bd7b61e..efb5bcfe 100644
--- a/ci/Jenkinsfile
+++ b/ci/Jenkinsfile
@@ -22,7 +22,7 @@ spec:
path: /opt/kubernetes/cache
containers:
- name: build
- image: docker:18
+ image: """ + buildEnvironmentDockerImage("ci/Dockerfile.build") + """
imagePullPolicy: Always
command:
- cat
@@ -30,7 +30,7 @@ spec:
resources:
requests:
cpu: 2
- memory: 4Gi
+ memory: 2Gi
env:
- name: DOCKER_HOST
value: tcp://127.0.0.1:2375
@@ -65,8 +65,6 @@ spec:
}
parameters {
- booleanParam(name: 'linting', defaultValue: false, description: 'Whether to run linting')
- booleanParam(name: 'testing', defaultValue: true, description: 'Whether to run unit tests')
string(name: 'releaseVersion', defaultValue: '', description: 'Version must comply with semver, a tag will be created, cannot be the same as in package.json')
booleanParam(name: 'release', defaultValue: false, description: "Whether to run the release steps")
booleanParam(name: 'releaseNext', defaultValue: false, description: "Whether release as an upcoming version")
@@ -77,7 +75,6 @@ spec:
stages {
stage('Clone Github Pages') {
when {
- beforeAgent true
expression {
return params.publishDocs
}
@@ -92,41 +89,73 @@ spec:
}
}
- stage('Docker build') {
+ stage('Fetch dependencies') {
+ steps {
+ sh 'npm set progress=false && npm config set depth 0 && npm ci'
+ stash includes: 'node_modules/', name: 'node_modules'
+ }
+ }
+
+ /*stage('Lint') {
+ steps {
+ unstash 'node_modules'
+ sh 'npm run lint'
+ }
+ }*/
+
+ stage('Unit Tests') {
+ steps {
+ unstash 'node_modules'
+ sh 'npm run test -- --watch=false --browsers=ChromeHeadlessCI --reporters=junit'
+ }
+
+ post {
+ always {
+ junit '.reports/*/*.xml'
+ }
+ }
+ }
+
+ stage('Build') {
+ steps {
+ unstash 'node_modules'
+ sh "npm run build -- --progress=false"
+ stash includes: 'dist/', name: 'dist'
+ }
+ }
+
+ stage('Release') {
when {
- beforeAgent true
expression {
- isValidVersion = params.releaseVersion.trim() =~ env.VERSION_CONSTRAINT || params.releaseVersion == ''
- return isValidVersion
+ return params.release
}
}
steps {
- sh """docker build -f ci/Dockerfile \
- --build-arg linting=${params.linting} \
- --build-arg testing=${params.testing} \
- --build-arg release=${params.release} \
- --build-arg releaseNext=${params.releaseNext} \
- --build-arg releaseVersion=${params.releaseVersion} \
- --build-arg publishDocs=${params.publishDocs} \
- --build-arg docsVersion=${params.docsVersion} \
- --build-arg GIT_BRANCH=${env.GIT_BRANCH} \
- --build-arg CACHEBUST=\$(date +%s) \
- .
- """
+ unstash 'dist'
+ sshagent(["git"]) {
+ sh "ci/release.sh"
+ }
}
}
- stage('Publish Docs to Github Pages') {
+ stage('Update Documentation') {
when {
expression {
return params.publishDocs
}
+ expression {
+ isValidVersion = params.releaseVersion.trim() =~ env.VERSION_CONSTRAINT || params.releaseVersion == ''
+ return isValidVersion
+ }
}
steps {
- echo "Now it should publish..."
- }
+ unstash 'node_modules'
+ sshagent(["git"]) {
+ sh "ci/publishDocs.sh"
+ }
+ }
}
}
diff --git a/package-lock.json b/package-lock.json
index 56227070..08221130 100644
--- a/package-lock.json
+++ b/package-lock.json
@@ -6871,6 +6871,24 @@
"karma-jasmine": "^1.0.2"
}
},
+ "karma-junit-reporter": {
+ "version": "1.2.0",
+ "resolved": "https://registry.npmjs.org/karma-junit-reporter/-/karma-junit-reporter-1.2.0.tgz",
+ "integrity": "sha1-T5xAzt+xo5X4rvh2q/lhiZF8Y5Y=",
+ "dev": true,
+ "requires": {
+ "path-is-absolute": "^1.0.0",
+ "xmlbuilder": "8.2.2"
+ },
+ "dependencies": {
+ "xmlbuilder": {
+ "version": "8.2.2",
+ "resolved": "https://registry.npmjs.org/xmlbuilder/-/xmlbuilder-8.2.2.tgz",
+ "integrity": "sha1-aSSGc0ELS6QuGmE2VR0pIjNap3M=",
+ "dev": true
+ }
+ }
+ },
"karma-source-map-support": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/karma-source-map-support/-/karma-source-map-support-1.3.0.tgz",
diff --git a/package.json b/package.json
index 5c34a558..2934eb06 100644
--- a/package.json
+++ b/package.json
@@ -106,6 +106,7 @@
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
+ "karma-junit-reporter": "^1.2.0",
"marked": "~0.6.0",
"ng-packagr": "^4.7.1",
"ngx-build-plus": "^7.7.6",
diff --git a/projects/docs/karma.conf.js b/projects/docs/karma.conf.js
index dddfaa1f..c46724c3 100644
--- a/projects/docs/karma.conf.js
+++ b/projects/docs/karma.conf.js
@@ -10,7 +10,8 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
- require('@angular-devkit/build-angular/plugins/karma')
+ require('@angular-devkit/build-angular/plugins/karma'),
+ require('karma-junit-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
@@ -32,6 +33,12 @@ module.exports = function (config) {
}
},
reporters: ['progress', 'kjhtml'],
+ reporters: ['progress', 'kjhtml', 'junit'],
+ junitReporter: {
+ outputDir: '../../.reports',
+ outputFile: 'docs-results.xml',
+ suite: ''
+ },
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
diff --git a/projects/gentics-ui-core/karma.conf.js b/projects/gentics-ui-core/karma.conf.js
index 682c0a14..d9f5e67b 100644
--- a/projects/gentics-ui-core/karma.conf.js
+++ b/projects/gentics-ui-core/karma.conf.js
@@ -10,7 +10,8 @@ module.exports = function (config) {
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
- require('@angular-devkit/build-angular/plugins/karma')
+ require('@angular-devkit/build-angular/plugins/karma'),
+ require('karma-junit-reporter')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
@@ -31,7 +32,12 @@ module.exports = function (config) {
],
}
},
- reporters: ['progress', 'kjhtml'],
+ reporters: ['progress', 'kjhtml', 'junit'],
+ junitReporter: {
+ outputDir: '../../.reports',
+ outputFile: 'gentics-ui-core-results.xml',
+ suite: ''
+ },
port: 9876,
colors: true,
logLevel: config.LOG_INFO,