Fastfile 10 KB

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