forked from katspaugh/wavesurfer.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJenkinsfile
155 lines (145 loc) · 3.8 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
#!/bin/groovy
import com.animoto.*
def JenkinsType = new getJenkinsType()
def MyPod = new getExecutorPod().get(this)
pipeline {
agent {
kubernetes {
inheritFrom MyPod.inheritFrom
yaml MyPod.yaml
}
}
options {
disableConcurrentBuilds()
timeout(time: 30, unit: 'MINUTES')
skipStagesAfterUnstable()
}
stages {
stage('build') {
steps {
withCredentials([
usernamePassword(credentialsId: 'animoto-techops', usernameVariable: 'USERNAME', passwordVariable: 'JENKINS_TOKEN'),
string(credentialsId: 'ANIMOTO_NPM_TOKEN', variable: 'ANIMOTO_NPM_TOKEN')]) {
sh '''
ao build
'''
}
}
}
stage('test') {
when {
not {
expression {
hasBumpVersion()
}
}
}
parallel {
// stage('linting') {
// steps {
// sh '''
// ao test -n lint
// '''
// }
// post {
// always {
// junit(allowEmptyResults: false, testResults: 'test_output/eslint/eslint.xml, test_output/stylelint.xml')
// }
// }
// }
stage('unit tests') {
steps {
sh '''
ao test -n test
'''
}
post {
always {
junit(allowEmptyResults: false, testResults: 'test_output/karma/wavesurfer-results.xml')
}
}
}
}
}
stage('version'){
when {
allOf {
branch 'main'
expression {
shouldVersion() && JenkinsType.isJenkinsOperator() == true
}
}
}
steps {
sh '''
ao run -- yarn release
'''
}
}
stage('publish'){
when {
allOf {
branch 'main'
expression {
hasBumpVersion() && JenkinsType.isJenkinsOperator() == true
}
}
}
steps {
sh '''
ao publish
'''
}
}
}
post {
always {
// Notify the defined Slack channels of our build status
withCredentials([string(credentialsId: 'slack_token', variable: 'slack_token')]) {
script {
def previous = (currentBuild.previousBuild != null) ? currentBuild.previousBuild.currentResult : "SUCCESS"
sh "ao notify -c ${currentBuild.currentResult} -p ${previous}"
}
}
}
}
}
// Checks if commit message contains [bump version]
// The sh command returns:
// Returns 0 if [bump version] is found in the commit message
// Returns 1 if it is not found
def hasBumpVersion() {
def BUMP_VERSION
BUMP_VERSION = sh (
script: """
ao run -- "git log -1 | grep '.*\\[bump version\\].*'"
""",
returnStatus: true
)
return BUMP_VERSION == 0
}
// Checks if current local commit hash is the same as the latest origin commit hash
// The sh command returns:
// Returns 0 if local commit hash is the same as the latest origin commit hash
// Returns 1 if local commit hash is not the same as the latest origin commit hash
def isLatestCommit() {
def IS_LATEST_MAIN
IS_LATEST_MAIN = sh (
script: """
ao run \
-v /get_main_hash.sh:/wavesurfer.js/get_main_hash.sh \
-- /wavesurfer.js/get_main_hash.sh main
""",
returnStatus: true
)
return IS_LATEST_MAIN == 0
}
// Checks if the versioning step should be ran based on
// if the current commit is not a [bump version] commit and
// if current commit is latest origin main commit
// The sh command returns:
// Returns 0 if current local commit is not [bump version] commit and is latest origin commit
// Returns 1 if current local commit is [bump version] commit or is not the latest origin commit
def shouldVersion() {
return !hasBumpVersion() && isLatestCommit()
}