Fastfile 9.8 KB

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