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

Add CI pipeline #45

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.git
dist
docs
node_modules
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ npm-debug.log
yarn-error.log
testem.log
/typings
/.reports

# System Files
.DS_Store
Expand Down
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# .prettierrc
printWidth: 120
singleQuote: true
22 changes: 22 additions & 0 deletions ci/Dockerfile.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
FROM node:10-alpine

LABEL maintainer="[email protected]"
ARG BUILD_USER="jenkins"
ENV CHROME_BIN /usr/bin/chromium-browser
ENV PUPPETEER_SKIP_CHROMIUM_DOWNLOAD true

# 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

RUN addgroup -g 10000 ${BUILD_USER} && adduser -D -G ${BUILD_USER} -u 10000 ${BUILD_USER}
USER ${BUILD_USER}
177 changes: 177 additions & 0 deletions ci/Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
// The GIT repository for this pipeline lib is defined in the global Jenkins setting
@Library('jenkins-pipeline-library')
import com.gentics.*

// Make the helpers aware of this jobs environment
JobContext.set(this)

pipeline {
agent {
kubernetes {
label env.BUILD_TAG
defaultContainer 'build'
yaml """
apiVersion: v1
kind: Pod
spec:
nodeSelector:
jenkins_worker: true
volumes:
- name: cache
hostPath:
path: /opt/kubernetes/cache
containers:
- name: build
image: """ + buildEnvironmentDockerImage("ci/Dockerfile.build") + """
imagePullPolicy: Always
command:
- cat
tty: true
resources:
requests:
cpu: 2
memory: 2Gi
env:
- name: DOCKER_HOST
value: tcp://127.0.0.1:2375
volumeMounts:
- mountPath: /home/jenkins/.npm/_cacache
name: cache
subPath: npm/_cacache
- name: docker
image: docker:18-dind
imagePullPolicy: Always
args:
- '--storage-driver=overlay2'
securityContext:
privileged: true
tty: true
imagePullSecrets:
- name: docker-jenkinsbuilds-apa-it
"""
}
}

environment {
VERSION_CONSTRAINT = /^((([0-9]+)\.([0-9]+)\.([0-9]+)(?:-([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?)$/
}

options {
timestamps()
timeout(time: 1, unit: 'HOURS')
ansiColor('xterm')
}

parameters {
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")
booleanParam(name: 'publishDocs', defaultValue: false, description: 'Build docs app and uploads to Github Pages')
string(name: 'docsVersion', defaultValue: '', description: 'If empty, its auto-detected, otherwise version of the maintenance documentation')
}

stages {
stage('Clone Github Pages') {
when {
expression {
return params.publishDocs
}
}

steps {
dir('docs') {
git branch: 'gh-pages',
credentialsId: 'git',
url: env.GIT_URL
}
}
}

stage('Fetch dependencies') {
steps {
sh 'npm set progress=false'
sh 'npm config set depth 0'
sh '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 {
allOf {
expression {
return params.release
}
expression {
isValidVersion = params.releaseVersion.trim() =~ env.VERSION_CONSTRAINT || params.releaseVersion == ''
return isValidVersion
}
}
}

steps {
unstash 'dist'
withCredentials([string(credentialsId: 'npm-token', variable: 'NPM_TOKEN')]) {
sh "echo //registry.npmjs.org/:_authToken=${env.NPM_TOKEN} > .npmrc"
sh "ci/release.sh " + params.releaseNext + ' "' + params.releaseVersion + '"'
}
}
}

stage('Update Documentation') {
when {
allOf {
expression {
return params.publishDocs
}
expression {
isValidVersion = params.releaseVersion.trim() =~ env.VERSION_CONSTRAINT || params.releaseVersion == ''
return isValidVersion
}
}
}

steps {
unstash 'node_modules'
sshagent(["git"]) {
sh "ci/publishDocs.sh"
}
}
}
}

post {
always {
//updateGitlabCommitCurrentBuildStatus name: 'Jenkins build'
notifyMattermostUsers()
}
}
}
23 changes: 23 additions & 0 deletions ci/publishDocs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/bin/sh
GIT_BRANCH=$1
# This should be before set -o errexit!
MAINTPREFIX="maintenance-v[0-9][\.x0-9]+"
isMaintenanceBranch=$(echo "$GIT_BRANCH" | grep -Eq "$MAINTPREFIX"; echo $?)

set -o errexit
set -o nounset


PARAMS=""

if [ -z "$docsVersion" ] && [ ! -z "$GIT_BRANCH" ] && [ $isMaintenanceBranch -eq 0 ]
then
docsVersion=$(echo "$GIT_BRANCH" | cut -d '-' -f 2)
fi

if [ ! -z "$docsVersion" ]
then
PARAMS="$PARAMS --docsVersion=${docsVersion}"
fi

echo "Will publishes docs part... (PARAMS: $PARAMS)"
24 changes: 24 additions & 0 deletions ci/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/bin/sh
set -o errexit
set -o nounset
WORKDIR="$PWD"

releaseProjectName="gentics-ui-core"
releaseNext=${1:-false}
releaseVersion=$2

if [ ! -z "$releaseVersion" ]
then
cd "projects/$releaseProjectName/"
npm version "$releaseVersion"
cd "$WORKDIR"
fi

npm run build -- "$releaseProjectName"

if [ "$releaseNext" == true ]
then
npm publish --dry-run --tag next "dist/$releaseProjectName"
else
npm publish --dry-run "dist/$releaseProjectName"
fi
Loading