Fastfile 11 KB

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