-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathJenkinsfile
More file actions
167 lines (149 loc) · 5.72 KB
/
Jenkinsfile
File metadata and controls
167 lines (149 loc) · 5.72 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
pipeline {
agent {
label 'ubuntu'
}
environment {
PATH = "/home/jenkins/development/flutter/bin:${env.PATH}"
}
stages {
stage('Pre-build Cleanup') {
steps {
script {
sh '''#!/bin/sh
set -x
fusermount -u secrets || true
'''
}
}
}
stage('Decrypt main keys') {
when {
branch 'main'
}
steps {
script {
def userInput = input(
id: 'signaturePassword',
message: 'Please enter the signing key password:',
parameters: [
password(
defaultValue: '',
description: 'Enter the signing key password',
name: 'password'
)
]
)
env.PASSWORD = userInput.toString()
}
sh '''#!/bin/sh
echo \$PASSWORD | gocryptfs $HOME/android_secrets secrets/ -nonempty
'''
}
}
stage('Clone submodules') {
steps {
script {
sh 'git submodule update --init --recursive'
}
}
}
stage('Build firka') {
steps {
sh 'bash -c "./tools/linux/build_apk.sh ' + env.BRANCH_NAME + '"'
}
}
stage('Rename Release APKs') {
when {
branch 'main'
}
steps {
script {
sh '''#!/bin/sh
set -e
APK_DIR="firka/build/app/outputs/flutter-apk"
# Find all release APKs and rename them
for apk_file in $APK_DIR/app-*-release.apk; do
if [ -f "$apk_file" ]; then
# Extract ABI from filename (e.g., app-arm64-v8a-release.apk -> arm64-v8a)
basename_file=$(basename "$apk_file")
abi=$(echo "$basename_file" | sed 's/app-//; s/-release.apk//')
# Create new filename
new_name="app.firka.naplo_${abi}.apk"
new_path="$APK_DIR/$new_name"
echo "Renaming $apk_file to $new_path"
mv "$apk_file" "$new_path"
fi
done
ls -la $APK_DIR/app.firka.naplo_*.apk || echo "APK files not found"
'''
}
}
}
stage('Calculate Version Code') {
steps {
script {
sh '''#!/bin/sh
set -e
cd firka
# Calculate version code based on git commits (same logic as build script)
COMMIT_COUNT=$(git rev-list --count HEAD)
BASE_BUILD_NUMBER=$((1300 + COMMIT_COUNT))
if [ "$BRANCH_NAME" = "main" ]; then
# For main branch, highest version code is BASE + 3000 (x64 build)
VERSION_CODE=$((BASE_BUILD_NUMBER + 3000))
else
# For debug builds, version code is BASE + 0
VERSION_CODE=$BASE_BUILD_NUMBER
fi
echo "Calculated version code: $VERSION_CODE"
echo "$VERSION_CODE" > ../version_code.txt
'''
env.VERSION_CODE = readFile('version_code.txt').trim()
echo "Setting VERSION_CODE environment variable to: ${env.VERSION_CODE}"
}
}
}
stage('Publish debug artifacts') {
when {
not {
branch 'main'
}
}
steps {
archiveArtifacts artifacts: 'firka/build/app/outputs/flutter-apk/app-debug.apk', fingerprint: true
}
}
stage('Publish release AABs artifacts') {
when {
branch 'main'
}
steps {
archiveArtifacts artifacts: 'firka/build/app/outputs/bundle/release/*.aab', fingerprint: true
sh 'rm firka/build/app/outputs/bundle/release/*.aab'
}
}
stage('Publish release APKs artifacts') {
when {
branch 'main'
}
steps {
archiveArtifacts artifacts: 'firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk', fingerprint: true
sh 'rm firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk'
}
}
stage('Post Cleanup') {
steps {
script {
sh '''
rm firka/build/app/outputs/bundle/release/*.aab || true
rm firka/build/app/outputs/flutter-apk/app.firka.naplo_*.apk || true
rm firka/build/app/outputs/flutter-apk/app-debug.apk || true
rm version_code.txt || true
git checkout -- firka/pubspec.yaml || true
git checkout -- firka/lib/helpers/firka_bundle.dart || true
'''
}
}
}
}
}