-
Notifications
You must be signed in to change notification settings - Fork 53
Expand file tree
/
Copy pathJenkinsfile
More file actions
188 lines (172 loc) · 4.49 KB
/
Jenkinsfile
File metadata and controls
188 lines (172 loc) · 4.49 KB
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
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
#!/usr/bin/env groovy
library 'status-jenkins-lib@v1.9.39'
def changesDetected = false
pipeline {
agent {
docker {
label 'linuxcontainer'
image 'harbor.status.im/infra/ci-build-containers:linux-base-1.0.0'
args '--volume=/nix:/nix ' +
'--volume=/etc/nix:/etc/nix '
}
}
options {
timestamps()
/* Prevent Jenkins jobs from running forever */
timeout(time: 10, unit: 'MINUTES')
/* manage how many builds we keep */
buildDiscarder(logRotator(
numToKeepStr: '20',
daysToKeepStr: '30',
))
disableConcurrentBuilds()
}
parameters {
choice(
name: 'APP_NAME',
description: 'Name of app from apps folder.',
choices: choiceFromJobName(params.APP_NAME, ['connector', 'wallet']),
)
booleanParam(
name: 'FORCE_BUILD',
description: 'Build even if no changes detected.',
defaultValue: params.FORCE_BUILD ?: false
)
}
environment {
PLATFORM = "${params.APP_NAME}"
ZIP_NAME = utils.pkgFilename(
name: 'StatusWeb',
type: params.APP_NAME,
version: 'none',
arch: 'chrome',
ext: 'zip',
)
}
stages {
stage('Check Connector Changes') {
when {
anyOf {
changeset "Jenkinsfile"
changeset "apps/${params.APP_NAME}/**"
changeset "packages/colors/**"
changeset "packages/eslint-config/**"
}
}
steps {
script {
changesDetected = true
}
}
}
stage('Check Wallet Changes') {
when {
anyOf {
changeset "Jenkinsfile"
changeset "apps/${params.APP_NAME}/**"
changeset "packages/colors/**"
changeset "packages/eslint-config/**"
changeset "packages/components/**"
changeset "packages/icons/**"
changeset "packages/wallet/**"
}
}
steps {
script {
changesDetected = true
}
}
}
stage('Install') {
when { expression { changesDetected || params.FORCE_BUILD } }
steps {
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
script {
nix.develop(
'pnpm install --frozen-lockfile --aggregate-output',
pure: false,
)
}
}
}
}
stage('Build') {
when { expression { changesDetected || params.FORCE_BUILD } }
steps {
dir("${env.WORKSPACE}") {
script {
nix.develop(
"pnpm turbo run build --filter=${params.APP_NAME}",
pure: false,
)
}
}
}
}
stage('Zip') {
when { expression { changesDetected || params.FORCE_BUILD } }
steps {
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
zip(
zipFile: env.ZIP_NAME,
dir: getBuildDir(params.APP_NAME),
archive: false,
)
}
}
}
stage('Archive') {
when { expression { changesDetected || params.FORCE_BUILD } }
steps {
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
archiveArtifacts(
artifacts: env.ZIP_NAME,
fingerprint: true,
)
}
}
}
stage('Upload') {
when { expression { changesDetected || params.FORCE_BUILD } }
steps {
dir("${env.WORKSPACE}/apps/${params.APP_NAME}") {
script {
env.PKG_URL = s5cmd.upload(env.ZIP_NAME)
jenkins.setBuildDesc(ZIP: env.PKG_URL)
}
}
}
}
}
post {
success { script { if (changesDetected && env.CHANGE_ID) { github.notifyPR(true) } } }
failure { script { if (changesDetected && env.CHANGE_ID) { github.notifyPR(false) } } }
cleanup { cleanWs() }
}
}
List<String> moveToStart(List<String> original, String input) {
original.split {it.equals(input)}.flatten()
}
/* If job name contains one of choices make that the default(first). */
def choiceFromJobName(String previousChoice, List defaultChoices) {
if (previousChoice != null) {
return moveToStart(defaultChoices, previousChoice)
}
def tokens = env.JOB_NAME.split('/')
for (choice in defaultChoices) {
if (tokens.contains(choice)) {
return moveToStart(defaultChoices, choice)
}
}
return defaultChoices
}
def getBuildDir(String appName) {
switch(appName) {
case 'connector':
return 'build/chrome-mv3-prod'
case 'wallet':
return '.output/chrome-mv3'
default:
error("Unknown app: ${appName}.")
}
}