forked from smithmicro/mapbox-gl-circle
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Jenkinsfile
executable file
·161 lines (147 loc) · 6.06 KB
/
Jenkinsfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/env groovy
//noinspection GroovyAssignabilityCheck
pipeline {
agent any
stages {
stage('Set Build Variables') {
steps {
script {
def getProjectVersion = { ->
return sh(
returnStdout: true,
script: 'echo $(node -e "console.log(require(\'./package.json\').version)")'
).replace('\n', '')
}
def getBranchTypeAndName = { String fullBranchName ->
if (fullBranchName in ['develop', 'master']) {
return [fullBranchName, fullBranchName]
}
if (fullBranchName.matches(/(feature|bugfix)\/[.\d\-\w]+$/)) {
return [fullBranchName.split('/')[0],
fullBranchName.split('/')[1].toLowerCase().replaceAll(/[^.\da-z]/, '.')]
}
if (fullBranchName.matches(/hotfix\/\d+(\.\d+){1,2}p\d+$/)) {
return fullBranchName.split('/') as List
}
if (fullBranchName.matches(/release\/\d+(\.\d+){1,2}([ab]\d+)?$/)) {
return fullBranchName.split('/') as List
}
if (fullBranchName.matches(/PR-\d+$/)) {
return fullBranchName.split('-') as List
}
error "Enforcing Gitflow Workflow and SemVer on '${fullBranchName}'. Ha!"
}
def getBuildVersion = { String fullBranchName, buildNumber ->
String projectVersion = getProjectVersion()
def branchTypeAndName = getBranchTypeAndName(fullBranchName)
switch (branchTypeAndName[0]) {
case 'master':
return projectVersion
case 'hotfix':
return "${branchTypeAndName[1]}-rc.${buildNumber}"
case 'develop':
return "${projectVersion}+develop.dev${buildNumber}"
case 'feature':
return "${projectVersion}+feature.${branchTypeAndName[1]}.dev${buildNumber}"
case 'bugfix':
return "${projectVersion}+bugfix.${branchTypeAndName[1]}.dev${buildNumber}"
case 'release':
assert branchTypeAndName[1] == projectVersion
return "${projectVersion}-rc.${buildNumber}"
case 'PR':
return "${projectVersion}+PR.${branchTypeAndName[1]}.${buildNumber}"
default:
error "Oops, we messed up! :("
}
}
def getNpmTag = { String fullBranchName ->
switch (getBranchTypeAndName(fullBranchName)[0]) {
case 'master':
return 'latest'
case 'release':
return 'next'
default:
return ''
}
}
env.BUILD_VERSION = getBuildVersion(BRANCH_NAME as String, BUILD_NUMBER)
env.NPM_TAG = getNpmTag(BRANCH_NAME as String)
env.BUILD_TYPE = env.NPM_TAG ? env.NPM_TAG : 'develop' // latest, next or develop
if (env.BUILD_TYPE == 'next') {
sh 'npm version $BUILD_VERSION'
}
}
}
}
stage('Install Dependencies') {
steps {
stash 'pre_install_git_checkout'
sh 'npm install'
}
}
stage('Run ESLint') {
steps {
sh 'npm run lint'
}
}
stage('Build Artifacts') {
steps {
//noinspection GroovyAssignabilityCheck
parallel(
'Development Bundle': {
sh 'npm run browserify'
archiveArtifacts "dist/mapbox-gl-circle-${BUILD_VERSION}.js"
},
'Production Bundle': {
script {
if (env.BUILD_TYPE in ['next', 'latest']) {
sh 'npm pack'
archiveArtifacts "mapbox-gl-circle-${BUILD_VERSION}.tgz"
} else {
sh 'npm run prepare'
archiveArtifacts "dist/mapbox-gl-circle-${BUILD_VERSION}.min.js"
}
}
},
'API Docs': {
sh 'npm run docs'
}
)
}
}
stage('Publish') {
when {
expression { env.BUILD_TYPE in ['next', 'latest'] }
}
environment {
NPM_TOKEN = credentials('mblomdahl_npm')
}
steps {
//noinspection GroovyAssignabilityCheck
parallel(
'NPM Package': {
sh 'echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" >> .npmrc'
sh 'npm publish --tag $NPM_TAG .'
}
)
}
}
}
post {
always {
deleteDir()
}
success {
echo 'Build succeeded!'
}
unstable {
echo 'Build unstable :/'
}
failure {
echo 'Build failed :('
}
changed {
echo 'Things are different...'
}
}
}