-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFastfile
151 lines (129 loc) · 4.92 KB
/
Fastfile
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
APPLICATION_ID = "de.gruene.wkapp"
SIGNING_REPOSITORY_URL = ENV["SIGNING_REPOSITORY_URL"]
SIGNING_REPOSITORY_KEYSTORE_PASSWORD = ENV["SIGNING_REPOSITORY_KEYSTORE_PASSWORD"]
KEYSTORE_ALIAS = ENV["KEYSTORE_ALIAS"]
KEYSTORE_PASSWORD = ENV["KEYSTORE_PASSWORD"]
SIGNING_REPOSITORY_KEYSTORE_PATH = "signing/android/gruene-app.jks.gpg"
LOCAL_KEYSTORE_PATH = "#{ENV['HOME']}/keystore.jks"
platform :android do
desc "Download and decrypt the JKS"
lane :keystore do
ensure_env_vars(
env_vars: ["SIGNING_REPOSITORY_URL", "SIGNING_REPOSITORY_KEYSTORE_PASSWORD"]
)
puts("Cloning repository with keystore")
sh("git clone #{SIGNING_REPOSITORY_URL} signing")
puts("Decrypting keystore")
sh("gpg --verbose --passphrase #{SIGNING_REPOSITORY_KEYSTORE_PASSWORD} --pinentry-mode loopback -o #{LOCAL_KEYSTORE_PATH} -d #{SIGNING_REPOSITORY_KEYSTORE_PATH}")
end
# The following parameters have to be passed:
# version_name: The version name the build should use
# version_code: The version code the build should use
desc "Create an android release build"
lane :build do |options|
version_code = options[:version_code]
version_name = options[:version_name]
if [version_name, version_code].include?(nil)
raise "'nil' passed as parameter! Aborting..."
end
ensure_env_vars(
env_vars: ["KEYSTORE_ALIAS", "KEYSTORE_PASSWORD"]
)
gradle_system_properties = {
# 2GB Gradle + 1GB dex + 2-2.5GB RN < 6GB of circleci resource class medium+
:"org.gradle.jvmargs" => "-Xms512m -Xmx2024m",
:"org.gradle.daemon" => false
}
if ENV["TOTAL_CPUS"]
# Gradle uses the wrong cpu count from the host (e.g. 36)
gradle_system_properties["org.gradle.workers.max"] = ENV["TOTAL_CPUS"]
end
env_prod = sh("echo -n environment=production | base64")
tasks = ["bundle", "assemble"]
tasks.each do |task|
gradle(
task: task,
flags: " -Ptarget=lib/main.dart -Pdart-defines=#{env_prod}",
build_type: "Release",
properties: {
:VERSION_CODE => version_code,
:VERSION_NAME => version_name,
:KEYSTORE_PATH => LOCAL_KEYSTORE_PATH,
:KEYSTORE_KEY_ALIAS => KEYSTORE_ALIAS,
:KEYSTORE_PASSWORD => KEYSTORE_PASSWORD,
:KEYSTORE_KEY_PASSWORD => KEYSTORE_PASSWORD,
}.compact,
system_properties: gradle_system_properties,
print_command: false
)
end
end
# The following parameters have to be passed:
# version_name: The version name the build should use
# version_code: The version code the build should use
# production_delivery: Whether to deliver to beta or production
# aab_path: The path to the .aab to upload
desc "Deliver android app to beta or production"
lane :upload do |options|
ensure_env_vars(
env_vars: ["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
version_code = options[:version_code]
version_name = options[:version_name]
production_delivery = options[:production_delivery]
aab_path = options[:aab_path]
if [version_name, version_code, production_delivery, aab_path].include?(nil)
raise "'nil' passed as parameter! Aborting..."
end
upload_to_play_store(
version_code: version_code,
version_name: version_name,
package_name: APPLICATION_ID,
track: production_delivery ? "production" : "beta",
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
skip_upload_metadata: true,
release_status: production_delivery ? "draft" : "completed",
skip_upload_apk: true,
aab: "#{ENV['HOME']}/#{aab_path}",
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
end
desc "Promote the android app from beta to production"
lane :promote do
ensure_env_vars(
env_vars: ["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
production_version_codes = google_play_track_version_codes(
track: "production",
package_name: APPLICATION_ID,
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
beta_version_codes = google_play_track_version_codes(
track: "beta",
package_name: APPLICATION_ID,
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
if beta_version_codes.length == 0 || beta_version_codes[0] <= production_version_codes[0]
puts("Nothing to do, latest version already available in production track...")
next
end
puts("promoting v#{beta_version_codes[0]} to production track")
# https://docs.fastlane.tools/actions/supply/
upload_to_play_store(
version_code: beta_version_codes[0],
package_name: APPLICATION_ID,
track: "beta",
track_promote_to: "production",
skip_upload_changelogs: true,
skip_upload_images: true,
skip_upload_screenshots: true,
skip_upload_metadata: true,
skip_upload_apk: true,
skip_upload_aab: true,
release_status: "draft",
json_key_data: ENV["GOOGLE_SERVICE_ACCOUNT_JSON"]
)
end
end