Fastfile 11 KB

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