Fastfile 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  1. # SPDX-FileCopyrightText: 2017-2024 Nextcloud GmbH and Nextcloud contributors
  2. # SPDX-License-Identifier: AGPL-3.0-or-later OR GPL-2.0-only
  3. # run fastlane
  4. # bundle exec fastlane
  5. # update fastlane
  6. # bundle update fastlane
  7. # update plugins
  8. # bundle exec fastlane update_plugins
  9. # This is the minimum version number required.
  10. fastlane_version "2.58.0"
  11. ## config
  12. # add following to your shell rc:
  13. # export FASTLANE_NEXTCLOUD_STORE_FILE=""
  14. # export FASTLANE_NEXTCLOUD_STORE_PASSWORD=""
  15. # export FASTLANE_NEXTCLOUD_KEY_ALIAS=""
  16. # export FASTLANE_NEXTCLOUD_KEY_PASSWORD=""
  17. # export FASTLANE_NEXTCLOUD_GITHUB_API_TOKEN=""
  18. # export FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID=""
  19. # export FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET=""
  20. # export FASTLANE_NEXTCLOUD_HUAWEI_APP_ID=""
  21. skip_docs
  22. ## public lanes
  23. lane :screenshotsPhone do
  24. beautifyPhone()
  25. build_for_screengrab()
  26. screengrab(
  27. device_type: "phone",
  28. app_apk_path: APK_LOCATION,
  29. tests_apk_path: TEST_APK_LOCATION
  30. )
  31. end
  32. lane :screenshotsTablet do
  33. beautifyPhone()
  34. build_for_screengrab()
  35. screengrab(
  36. device_type: "sevenInch",
  37. app_apk_path: APK_LOCATION,
  38. tests_apk_path: TEST_APK_LOCATION
  39. )
  40. end
  41. desc "Release phase 1: make gplay/generic for RC, then test it"
  42. lane :RC_releasePhase1 do
  43. disableLogger()
  44. makeReleases()
  45. enableLogger()
  46. end
  47. desc "Release phase 2 for RC: checks, tag, upload gplay to playstore with values from build.gradle"
  48. lane :RC_releasePhase2 do |options|
  49. checkReleaseRequirements_RC()
  50. info = androidVersion
  51. promptVersion(info)
  52. checkChangelog(info)
  53. checkLibrary_RC()
  54. checkIfScreenshotsExist()
  55. checkIfAPKexists()
  56. tag(info)
  57. uploadToPlaystore_RC(info)
  58. createGithubRelease_RC(info)
  59. fdroidMergeRequest_RC(info)
  60. createChangelogPullRequest_RC(info)
  61. end
  62. desc "Release phase 1: make gplay/generic for FINAL, then test it"
  63. lane :Final_releasePhase1 do
  64. makeReleases()
  65. end
  66. desc "Release phase 2 for FINAL: checks, tag, upload gplay to playstore with values from build.gradle"
  67. lane :Final_releasePhase2 do |options|
  68. checkReleaseRequirements_Final()
  69. info = androidVersion
  70. promptVersion(info)
  71. checkChangelog(info)
  72. checkLibrary_Final()
  73. checkIfScreenshotsExist()
  74. checkIfAPKexists()
  75. tag(info)
  76. uploadToPlaystore_Final(info)
  77. createGithubRelease_Final(info)
  78. fdroidMergeRequest_Final(info)
  79. createChangelogPullRequest_Final(info)
  80. uploadToHuawei_Final(info)
  81. end
  82. desc "Makes gplay and generic releases in ../releases/"
  83. lane :makeReleases do
  84. info = androidVersion
  85. sh("rm -rf ../release/ && mkdir -p ../release")
  86. gradle(task: 'clean')
  87. createGenericRelease(versionCode:info["versionCode"])
  88. createGplayRelease(versionCode:info["versionCode"])
  89. createHuaweiRelease()
  90. end
  91. desc "Create GPlay release"
  92. lane :createGplayRelease do |options|
  93. buildBundle(flavor:"Gplay")
  94. sh("mv ../app/build/outputs/bundle/gplayRelease/app-gplay-release.aab ../release/")
  95. buildApkFromBundle(outputDir: "../release", bundlePath: "../release/app-gplay-release.aab")
  96. sh("rm ../release/toc.pb")
  97. sh("mv ../release/universal.apk ../release/gplay-release-#{options[:versionCode]}.apk")
  98. end
  99. desc "Create Generic release"
  100. lane :createGenericRelease do |options|
  101. SignedRelease(flavor:"Generic")
  102. sh("mv ../app/build/outputs/apk/generic/release/*.apk ../release/")
  103. sh("mv ../release/generic-release-#{options[:versionCode]}.apk ../release/nextcloud-#{options[:versionCode]}.apk")
  104. end
  105. desc "Create Huawei release"
  106. lane :createHuaweiRelease do
  107. SignedRelease(flavor:"Huawei")
  108. sh("mv ../app/build/outputs/apk/huawei/release/*.apk ../release/")
  109. end
  110. desc "Create Dev release"
  111. lane :createDevRelease do
  112. SignedRelease(flavor:"VersionDev")
  113. sh("mv ../app/build/outputs/apk/versionDev/release/*.apk ../release/")
  114. end
  115. desc "Beautify phone for screenshots: set time, remove other icons, no charging"
  116. lane :beautifyPhone do
  117. sh("adb shell settings put global sysui_demo_allowed 1")
  118. sh("adb shell am broadcast -a com.android.systemui.demo -e command clock -e hhmm 1200")
  119. sh("adb shell am broadcast -a com.android.systemui.demo -e command network -e mobile show -e level 4 -e datatype false")
  120. sh("adb shell am broadcast -a com.android.systemui.demo -e command notifications -e visible false")
  121. sh("adb shell am broadcast -a com.android.systemui.demo -e command battery -e plugged false -e level 100")
  122. end
  123. # to install
  124. # bundle exec fastlane add_plugin huawei_appgallery_connect
  125. # bundle install --path build/vendor/bundle
  126. private_lane :uploadToHuawei_Final do |options|
  127. huawei_appgallery_connect(
  128. client_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_ID"],
  129. client_secret: ENV["FASTLANE_NEXTCLOUD_HUAWEI_CLIENT_SECRET"],
  130. app_id: ENV["FASTLANE_NEXTCLOUD_HUAWEI_APP_ID"],
  131. apk_path: "release/huawei-release-" + options["versionCode"] + ".apk",
  132. submit_for_review: true,
  133. delay_before_submit_for_review: 30,
  134. )
  135. end
  136. ## private lanes
  137. desc "Build debug and test APK for screenshots"
  138. private_lane :build_for_screengrab do
  139. build_android_app(
  140. task: 'assemble',
  141. flavor: 'Generic',
  142. build_type: 'Debug'
  143. )
  144. APK_LOCATION = lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS].select{ |i| i[/00/] }[0]
  145. build_android_app(
  146. task: 'assemble',
  147. flavor: 'Generic',
  148. build_type: 'DebugAndroidTest'
  149. )
  150. TEST_APK_LOCATION = lane_context[SharedValues::GRADLE_ALL_APK_OUTPUT_PATHS].select{ |i| i[/androidTest/] }[0]
  151. end
  152. private_lane :checkReleaseRequirements_common do
  153. sh("if ! command -v fdroid &>/dev/null; then echo 'fdroid command not found' && exit 1; fi")
  154. sh("if ! command -v bundletool &>/dev/null; then echo 'bundletool command not found' && exit 1; fi")
  155. end
  156. private_lane :checkReleaseRequirements_RC do
  157. checkReleaseRequirements_common()
  158. sh("if ! command -v fdroidMergeRequestRC &>/dev/null; then echo 'fdroidMergeRequestRC command not found'; exit 1; fi")
  159. sh("if ! command -v createChangelogPullRequestRC &>/dev/null; then echo 'createChangelogPullRequestRC command not found'; exit 1; fi")
  160. end
  161. private_lane :checkReleaseRequirements_Final do
  162. checkReleaseRequirements_common()
  163. sh("if ! command -v fdroidMergeRequestFinal &>/dev/null; then echo 'fdroidMergeRequestFinal command not found'; exit 1; fi")
  164. sh("if ! command -v createChangelogPullRequestFinal &>/dev/null; then echo 'createChangelogPullRequestFinal command not found'; exit 1; fi")
  165. end
  166. private_lane :createChangelogPullRequest_RC do |options|
  167. sh("createChangelogPullRequestRC " + options["tag"] + " \"" + options["versionName"] + "\" " + options["versionCode"] + " \"" + options["branch"] + "\" ")
  168. end
  169. private_lane :createChangelogPullRequest_Final do |options|
  170. sh("createChangelogPullRequestFinal " + options["tag"] + " \"" + options["versionName"] + "\" " + options["versionCode"] + " \"" + options["branch"] + "\" ")
  171. end
  172. private_lane :checkIfAPKexists do |options|
  173. sh("if [ $(/bin/ls -1 ../release | wc -l) -ne 4 ]; then echo 'Release artifacts not present or wrong number present; aborting!' ; exit 1 ;
  174. fi")
  175. end
  176. desc "compute version"
  177. private_lane :androidVersion do
  178. File.open("../app/build.gradle","r") do |f|
  179. text = f.read
  180. # everything between Document and Authors
  181. major = text.match(/def versionMajor = ([0-9]*)$/)
  182. minor = text.match(/def versionMinor = ([0-9]*)$/)
  183. patch = text.match(/def versionPatch = ([0-9]*)$/)
  184. build = text.match(/def versionBuild = ([0-9]*).*$/)
  185. majorInt = major[1].to_i
  186. minorInt = minor[1].to_i
  187. patchInt = patch[1].to_i
  188. buildInt = build[1].to_i
  189. versionCode = majorInt * 10000000 + minorInt * 10000 + patchInt * 100 + buildInt
  190. if buildInt > 89
  191. name = major[1] + "." + minor[1] + "." + patch[1]
  192. tag = "stable-" + major[1] + "." + minor[1] + "." + patch[1]
  193. branch = "stable-" + major[1] + "." + minor[1]
  194. elsif buildInt > 50
  195. name = major[1] + "." + minor[1] + "." + patch[1] + " RC" + (buildInt - 50).to_s
  196. tag = "rc-" + major[1] + "." + minor[1] + "." + patch[1] + "-" + format('%02d', (buildInt - 50))
  197. branch = "stable-" + major[1] + "." + minor[1]
  198. else
  199. name = major[1] + "." + minor[1] + "." + patch[1] + " Alpha " + format('%02d', (buildInt + 1))
  200. tag = "/"
  201. branch = "stable-" + major[1] + "." + minor[1]
  202. end
  203. { "versionCode" => versionCode.to_s, "versionName" => name, "tag" => tag, "branch" => branch }
  204. end
  205. end
  206. desc "Show versions and prompt for confirmation"
  207. private_lane :promptVersion do |options|
  208. print "VersionCode: " + options["versionCode"].to_s + "\n"
  209. print "Name: " + options["versionName"] + "\n"
  210. print "Tag: " + options["tag"] + "\n"
  211. print "Branch: " + options["branch"] + "\n"
  212. print "\ndisable IPv6 to upload to Gplay!!!\n"
  213. answer = prompt(text: "is this okay?", boolean: true)
  214. if !answer
  215. exit
  216. end
  217. end
  218. desc "check if library is set correctly"
  219. private_lane :checkLibrary_RC do
  220. sh(" if [ $(egrep 'androidLibraryVersion.*master.*' ../build.gradle -c) -eq 1 ] ; then echo 'Library is set to master tag; aborting!' ; exit 1 ; fi")
  221. end
  222. desc "check if library is set correctly: must NOT contain master nor rc"
  223. private_lane :checkLibrary_Final do
  224. sh(" if [ $(grep 'androidLibraryVersion' ../build.gradle | egrep 'master|rc' -c) -eq 1 ] ; then echo 'Library is still set to rc tag; aborting!' ; exit 1 ; fi")
  225. end
  226. desc "check if screenshots exists and exit"
  227. private_lane :checkIfScreenshotsExist do
  228. sh(" if [ $(find metadata/android/*/images -type f -not -name icon.png | grep -c . ) -gt 0 ] ; then echo 'Screenshots in fastlane folder exist; aborting!' ; exit 1 ; fi")
  229. end
  230. private_lane :tag do |options|
  231. add_git_tag(
  232. tag: options["tag"],
  233. sign: true
  234. )
  235. push_git_tags(
  236. tag: options["tag"])
  237. end
  238. private_lane :disableLogger do
  239. sh("sed -i s'#<bool name=\"logger_enabled\">false</bool>#<bool name=\"logger_enabled\">true</bool>#' ../app/src/main/res/values/setup.xml")
  240. end
  241. private_lane :enableLogger do
  242. sh("sed -i s'#<bool name=\"logger_enabled\">true</bool>#<bool name=\"logger_enabled\">false</bool>#' ../app/src/main/res/values/setup.xml")
  243. end
  244. desc "Upload to play store (beta)"
  245. private_lane :uploadToPlaystore_RC do |options|
  246. upload_to_play_store(
  247. skip_upload_images: true,
  248. track: 'beta',
  249. aab: "release/app-gplay-release.aab"
  250. )
  251. end
  252. desc "Upload to play store"
  253. private_lane :uploadToPlaystore_Final do |options|
  254. upload_to_play_store(
  255. skip_upload_images: true,
  256. skip_upload_apk: true,
  257. aab: "release/app-gplay-release.aab"
  258. )
  259. end
  260. desc "Build app bundle"
  261. private_lane :buildBundle do |options|
  262. gradle(
  263. task: 'bundle',
  264. flavor: options[:flavor],
  265. build_type: 'Release',
  266. print_command: false,
  267. properties: {
  268. "android.injected.signing.store.file" => ENV["FASTLANE_NEXTCLOUD_UPLOAD_STORE_FILE"],
  269. "android.injected.signing.store.password" => ENV["FASTLANE_NEXTCLOUD_UPLOAD_STORE_PASSWORD"],
  270. "android.injected.signing.key.alias" => ENV["FASTLANE_NEXTCLOUD_UPLOAD_KEY_ALIAS"],
  271. "android.injected.signing.key.password" => ENV["FASTLANE_NEXTCLOUD_UPLOAD_KEY_PASSWORD"],
  272. }
  273. )
  274. end
  275. desc "Generate signed universal APK from app bundle"
  276. private_lane :buildApkFromBundle do |options|
  277. sh(command:"bundletool build-apks --mode universal --output '#{options[:outputDir]}' --output-format DIRECTORY" +
  278. " --ks '#{ENV["FASTLANE_NEXTCLOUD_STORE_FILE"]}'"+
  279. " --ks-pass 'pass:#{ENV["FASTLANE_NEXTCLOUD_STORE_PASSWORD"]}'"+
  280. " --ks-key-alias '#{ENV["FASTLANE_NEXTCLOUD_KEY_ALIAS"]}'"+
  281. " --key-pass 'pass:#{ENV["FASTLANE_NEXTCLOUD_KEY_PASSWORD"]}'"+
  282. " --bundle '#{options[:bundlePath]}'",
  283. log:false)
  284. end
  285. desc "Build signed APK"
  286. private_lane :SignedRelease do |options|
  287. gradle(
  288. task: 'assemble',
  289. flavor: options[:flavor],
  290. build_type: 'Release',
  291. print_command: false,
  292. properties: {
  293. "android.injected.signing.store.file" => ENV["FASTLANE_NEXTCLOUD_STORE_FILE"],
  294. "android.injected.signing.store.password" => ENV["FASTLANE_NEXTCLOUD_STORE_PASSWORD"],
  295. "android.injected.signing.key.alias" => ENV["FASTLANE_NEXTCLOUD_KEY_ALIAS"],
  296. "android.injected.signing.key.password" => ENV["FASTLANE_NEXTCLOUD_KEY_PASSWORD"],
  297. }
  298. )
  299. end
  300. private_lane :createGithubRelease_RC do |options|
  301. set_github_release(
  302. repository_name: "nextcloud/android",
  303. api_token: ENV["FASTLANE_NEXTCLOUD_GITHUB_API_TOKEN"],
  304. name: options["versionName"],
  305. tag_name: options["tag"],
  306. is_prerelease: true,
  307. description: (File.read("metadata/android/en-US/changelogs/" + options["versionCode"] + ".txt") rescue "No changelog provided"),
  308. upload_assets: [ "release/gplay-release-" + options["versionCode"] + ".apk", "release/nextcloud-" +
  309. options["versionCode"] + ".apk" ]
  310. )
  311. end
  312. private_lane :createGithubRelease_Final do |options|
  313. set_github_release(
  314. repository_name: "nextcloud/android",
  315. api_token: ENV["FASTLANE_NEXTCLOUD_GITHUB_API_TOKEN"],
  316. name: options["versionName"],
  317. tag_name: options["tag"],
  318. description: (File.read("metadata/android/en-US/changelogs/" + options["versionCode"] + ".txt") rescue "No changelog provided"),
  319. upload_assets: [ "release/gplay-release-" + options["versionCode"] + ".apk", "release/nextcloud-" +
  320. options["versionCode"] + ".apk" ]
  321. )
  322. end
  323. private_lane :fdroidMergeRequest_RC do |options|
  324. sh("fdroidMergeRequestRC " + options["tag"] + " \"" + options["versionName"] + "\" " + options["versionCode"])
  325. end
  326. private_lane :fdroidMergeRequest_Final do |options|
  327. sh("fdroidMergeRequestFinal " + options["tag"] + " \"" + options["versionName"] + "\" " + options["versionCode"])
  328. end
  329. private_lane :checkChangelog do |options|
  330. sh(" if [ ! -e metadata/android/en-US/changelogs/" + options["versionCode"] + ".txt ] ; then echo 'Changelog fastlane/metadata/android/en-US/changelogs/" + options["versionCode"] + ".txt does not exist' ; exit 1 ; fi")
  331. sh(" if [ $(wc -m metadata/android/en-US/changelogs/" + options["versionCode"] + ".txt | cut -d' ' -f1) -ge 500 ] ; then echo 'Changlog more than 500 chars' ; exit 1 ; fi")
  332. end