forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIos.Jenkinsfile
216 lines (192 loc) · 6.25 KB
/
Ios.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
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
pipeline {
environment {
NODE_PATH = "/opt/node-v16.3.0-linux-x64/bin"
NODE_MAC_PATH = "/usr/local/opt/node@16/bin/"
VERSION = sh(returnStdout: true, script: "${NODE_PATH}/node -p -e \"require('./package.json').version\" | tr -d \"\n\"")
TAG = "tutanota-ios-release-${VERSION}"
RELEASE_NOTES_PATH = "app-ios/fastlane/metadata/default/release_notes.txt"
}
agent {
label 'linux'
}
parameters {
booleanParam(
name: 'RELEASE',
defaultValue: false,
description: "Build staging and production version, and upload them to nexus/testflight/appstore. " +
"The production version will need to be released manually from appstoreconnect.apple.com"
)
string(
name: 'MILESTONE',
defaultValue: '',
description: 'Which github milestone to reference for generating release notes. Defaults to the version number'
)
}
stages {
stage("Run tests") {
agent {
label 'mac'
}
environment {
LC_ALL = "en_US.UTF-8"
LANG = "en_US.UTF-8"
}
steps {
script {
dir('app-ios') {
sh 'fastlane test'
}
}
}
}
stage("Build and upload to Apple") {
environment {
PATH = "${env.NODE_MAC_PATH}:${env.PATH}"
MATCH_GIT_URL = "git@gitlab:/tuta/apple-certificates.git"
LC_ALL = "en_US.UTF-8"
LANG = "en_US.UTF-8"
}
agent {
label 'mac'
}
stages {
stage('Staging') {
steps {
script {
script {
doBuild('test', 'adhoctest', false, params.MILESTONE.trim().equals("") ? VERSION : params.MILESTONE)
stash includes: "app-ios/releases/tutanota-${VERSION}-test.ipa", name: 'ipa-staging'
}
}
}
}
stage('Production') {
steps {
script {
doBuild('prod', 'adhoc', params.RELEASE, params.MILESTONE.trim().equals("") ? VERSION : params.MILESTONE)
stash includes: "app-ios/releases/tutanota-${VERSION}-adhoc.ipa", name: 'ipa-production'
}
}
}
}
}
stage('Upload to Nexus') {
environment {
PATH = "${env.NODE_PATH}:${env.PATH}"
}
when {
expression { params.RELEASE }
}
agent {
label 'linux'
}
steps {
script {
unstash 'ipa-staging'
unstash 'ipa-production'
script {
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS', message: 'There was an error when uploading to Nexus') {
publishToNexus("ios-test", "tutanota-${VERSION}-test.ipa")
publishToNexus("ios", "tutanota-${VERSION}-adhoc.ipa")
}
}
}
}
}
stage('Tag and create github release page') {
environment {
PATH = "${env.NODE_PATH}:${env.PATH}"
}
when {
expression { params.RELEASE }
}
agent {
label 'linux'
}
steps {
sh "git tag ${TAG}"
sh "git push --tags"
script {
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS', message: 'Failed to create github release page') {
def tag = "tutanota-ios-release-${VERSION}"
def milestone = params.MILESTONE.trim().equals("") ? VERSION : params.MILESTONE
// need to run npm ci to install dependencies of releaseNotes.js
sh "npm ci"
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
sh """node buildSrc/releaseNotes.js --releaseName '${VERSION} (IOS)' \
--milestone '${milestone}' \
--tag '${tag}' \
--platform ios"""
}
}
}
}
}
}
}
void doBuild(String stage, String lane, boolean publishToAppStore, String milestone) {
// Prepare the fastlane Appfile which defines the required ids for the ios app build.
script {
def app_identifier = 'de.tutao.tutanota'
def appfile = './app-ios/fastlane/Appfile'
sh "echo \"app_identifier('${app_identifier}')\" > ${appfile}"
withCredentials([string(credentialsId: 'apple-id', variable: 'apple_id')]) {
sh "echo \"apple_id('${apple_id}')\" >> ${appfile}"
}
withCredentials([string(credentialsId: 'itc-team-id', variable: 'itc_team_id')]) {
sh "echo \"itc_team_id('${itc_team_id}')\" >> ${appfile}"
}
withCredentials([string(credentialsId: 'team-id', variable: 'team_id')]) {
sh "echo \"team_id('${team_id}')\" >> ${appfile}"
}
}
script {
catchError(stageResult: 'UNSTABLE', buildResult: 'SUCCESS', message: 'Failed to create github release notes') {
def tag = "tutanota-ios-release-${VERSION}"
// need to run npm ci to install dependencies of releaseNotes.js
sh "npm ci"
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
sh """node buildSrc/releaseNotes.js --releaseName '${VERSION} (IOS)' \
--milestone '${milestone}' \
--tag '${tag}' \
--platform ios \
--format ios \
--toFile ${RELEASE_NOTES_PATH}"""
}
}
}
sh "echo Created release notes for fastlane ${RELEASE_NOTES_PATH}"
sh "pwd"
stash includes: "${RELEASE_NOTES_PATH}", name: 'release_notes'
sh "echo $PATH"
sh "npm ci"
sh 'npm run build-packages'
sh "node --max-old-space-size=8192 webapp ${stage}"
sh "node buildSrc/prepareMobileBuild.js dist"
withCredentials([
file(credentialsId: 'appstore-api-key-json', variable: "API_KEY_JSON_FILE_PATH"),
string(credentialsId: 'match-password', variable: 'MATCH_PASSWORD'),
string(credentialsId: 'team-id', variable: 'FASTLANE_TEAM_ID'),
sshUserPrivateKey(credentialsId: 'jenkins', keyFileVariable: 'MATCH_GIT_PRIVATE_KEY'),
string(credentialsId: 'fastlane-keychain-password', variable: 'FASTLANE_KEYCHAIN_PASSWORD')
]) {
dir('app-ios') {
sh "security unlock-keychain -p ${FASTLANE_KEYCHAIN_PASSWORD}"
// Set git ssh command to avoid ssh prompting to confirm an unknown host
// (since we don't have console access we can't confirm and it gets stuck)
sh "GIT_SSH_COMMAND=\"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\" fastlane ${lane}"
if (publishToAppStore) {
sh "GIT_SSH_COMMAND=\"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\" fastlane release submit:true"
}
}
}
}
void publishToNexus(String artifactId, String ipaFileName) {
def util = load "jenkins-lib/util.groovy"
util.publishToNexus(groupId: "app",
artifactId: "${artifactId}",
version: "${VERSION}",
assetFilePath: "${WORKSPACE}/app-ios/releases/${ipaFileName}",
fileExtension: "ipa"
)
}