forked from tutao/tutanota
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIos.Jenkinsfile
169 lines (154 loc) · 4.96 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
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\"")
}
agent {
label 'linux'
}
parameters {
booleanParam(name: 'PROD', defaultValue: false, description: 'Build for production')
booleanParam(
name: 'PUBLISH', defaultValue: false,
description: "Publish the app to Nexus and Apple Store (when not in production mode, " +
"it will publish to Nexus only)"
)
}
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 IOS app") {
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'
}
steps {
script {
createAppfile()
def stage = params.PROD ? 'prod' : 'test'
def lane = params.PROD ? 'adhoc' : 'adhoctest'
def ipaFileName = params.PROD ? "tutanota-${VERSION}-adhoc.ipa" : "tutanota-${VERSION}-test.ipa"
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 (params.PROD && params.PUBLISH) {
sh "GIT_SSH_COMMAND=\"ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no\" fastlane release submit:true"
}
}
}
stash includes: "app-ios/releases/${ipaFileName}", name: 'ipa'
if (params.PUBLISH && params.PROD) {
def tag = "tutanota-ios-release-${VERSION}"
sh "git tag ${tag}"
sh "git push --tags"
}
}
}
}
stage('Upload to Nexus') {
environment {
PATH="${env.NODE_PATH}:${env.PATH}"
}
when {
expression { params.PUBLISH }
}
agent {
label 'linux'
}
steps {
script {
def util = load "jenkins-lib/util.groovy"
def ipaFileName = params.PROD ? "tutanota-${VERSION}-adhoc.ipa" : "tutanota-${VERSION}-test.ipa"
def artifactId = params.PROD ? "ios" : "ios-test"
unstash 'ipa'
util.publishToNexus(groupId: "app",
artifactId: "${artifactId}",
version: "${VERSION}",
assetFilePath: "${WORKSPACE}/app-ios/releases/${ipaFileName}",
fileExtension: "ipa"
)
}
}
}
stage('Create github release') {
environment {
PATH="${env.NODE_PATH}:${env.PATH}"
}
when {
expression { params.PROD }
expression { params.PUBLISH }
}
agent {
label 'linux'
}
steps {
script {
catchError(stageResult: 'FAILURE', buildResult: 'SUCCESS', message: 'Failed to create github release page') {
def tag = "tutanota-ios-release-${VERSION}"
// need to run npm ci to install dependencies of createGithubReleasePage.js
sh "npm ci"
withCredentials([string(credentialsId: 'github-access-token', variable: 'GITHUB_TOKEN')]) {
sh """node buildSrc/createGithubReleasePage.js --name '${VERSION} (IOS)' \
--milestone '${VERSION}' \
--tag '${tag}' \
--platform ios """
}
}
}
}
}
}
}
/**
* Prepares the fastlane Appfile which defines the required ids for the ios application build.
*/
def createAppfile() {
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}"
}
}
}