build-android.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. # This is the main Android apk build workflow for both nightly and beta releases.
  2. # This is also configured to run as a workflow_call.
  3. name: Build-Android
  4. on:
  5. workflow_dispatch:
  6. inputs:
  7. build-target:
  8. description: 'Build Target (Release Type)'
  9. type: choice
  10. required: true
  11. options:
  12. - beta
  13. - nightly
  14. - non-release
  15. default: "non-release"
  16. git-ref:
  17. description: "Build from Git Ref(master)"
  18. required: true
  19. default: "master"
  20. enable-file-sync-production:
  21. description: 'File sync production mode'
  22. type: boolean
  23. required: true
  24. default: true
  25. workflow_call:
  26. inputs:
  27. build-target:
  28. type: string
  29. required: true
  30. enable-file-sync-production:
  31. description: 'File sync production mode'
  32. type: boolean
  33. secrets:
  34. ANDROID_KEYSTORE:
  35. required: true
  36. ANDROID_KEYSTORE_PASSWORD:
  37. required: true
  38. SENTRY_AUTH_TOKEN:
  39. required: true
  40. env:
  41. CLOJURE_VERSION: '1.10.1.763'
  42. NODE_VERSION: '16'
  43. JAVA_VERSION: '11'
  44. jobs:
  45. build-apk:
  46. runs-on: ubuntu-latest
  47. steps:
  48. - name: Check out Git repository
  49. uses: actions/checkout@v2
  50. with:
  51. ref: ${{ github.event.inputs.git-ref }}
  52. - name: Install Node.js, NPM and Yarn
  53. uses: actions/setup-node@v2
  54. with:
  55. node-version: ${{ env.NODE_VERSION }}
  56. - name: Get yarn cache directory path
  57. id: yarn-cache-dir-path
  58. run: echo "::set-output name=dir::$(yarn cache dir)"
  59. - name: Cache yarn cache directory
  60. uses: actions/cache@v2
  61. id: yarn-cache
  62. with:
  63. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  64. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  65. restore-keys: |
  66. ${{ runner.os }}-yarn-
  67. - name: Setup Java JDK
  68. uses: actions/setup-java@v2
  69. with:
  70. distribution: 'zulu'
  71. java-version: ${{ env.JAVA_VERSION }}
  72. - name: Cache clojure deps
  73. uses: actions/cache@v2
  74. with:
  75. path: |
  76. ~/.m2/repository
  77. ~/.gitlibs
  78. key: ${{ runner.os }}-clojure-lib-${{ hashFiles('**/deps.edn') }}
  79. - name: Setup clojure
  80. uses: DeLaGuardo/[email protected]
  81. with:
  82. cli: ${{ env.CLOJURE_VERSION }}
  83. - name: Retrieve tag version
  84. id: ref
  85. run: |
  86. pkgver=$(node ./scripts/get-pkg-version.js "${{ inputs.build-target || github.event.inputs.build-target }}")
  87. echo ::set-output name=version::$pkgver
  88. - name: Update Nightly APP Version
  89. if: ${{ inputs.build-target == 'nightly' || github.event.inputs.build-target == 'nightly' }}
  90. run: |
  91. sed -i 's/defonce version ".*"/defonce version "${{ steps.ref.outputs.version }}"/g' src/main/frontend/version.cljs
  92. sed -i 's/versionName ".*"/versionName "${{ steps.ref.outputs.version }}"/g' android/app/build.gradle
  93. - name: Set Build Environment Variables
  94. run: |
  95. echo "ENABLE_FILE_SYNC_PRODUCTION=${{ inputs.enable-file-sync-production == 'true' || github.event.inputs.enable-file-sync-production == 'true' }}" >> $GITHUB_ENV
  96. - name: Compile CLJS - android variant, use es6 instead of es-next
  97. run: yarn install && yarn release-android-app
  98. - name: Upload Sentry Sourcemaps (beta only)
  99. if: ${{ github.repository == 'logseq/logseq' && (inputs.build-target == 'beta' || github.event.inputs.build-target == 'beta') }}
  100. run: |
  101. curl -sL https://sentry.io/get-cli/ | bash
  102. release_name="logseq-android@${{ steps.ref.outputs.version }}"
  103. sentry-cli releases new "${release_name}"
  104. sentry-cli releases files "${release_name}" upload-sourcemaps --ext map --ext js ./static/js --url-prefix '~/static/js'
  105. sentry-cli releases finalize "${release_name}"
  106. env:
  107. SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
  108. SENTRY_ORG: logseq
  109. SENTRY_PROJECT: logseq
  110. - name: Prepare public Directory
  111. run: |
  112. cp -r static public/
  113. rm -rvf public/static/js/publishing
  114. rm -rvf public/static/js/*.js.map || true
  115. rm -rvf public/static/*.*
  116. rm -rvf public/static/ios
  117. rm -rvf android/app/src/main/assets/public || true
  118. - name: Sync public to Android Project
  119. run: npx cap sync
  120. - name: Setup Android SDK
  121. uses: android-actions/setup-android@v2
  122. - name: Build Android
  123. run: |
  124. ./gradlew clean
  125. ./gradlew zipApksForRelease
  126. working-directory: android
  127. - name: Sign Android APK
  128. run: |
  129. echo ${{ secrets.ANDROID_KEYSTORE }} | base64 -d > keystore.jks
  130. /usr/local/lib/android/sdk/build-tools/30.0.3/apksigner sign \
  131. --ks keystore.jks --ks-pass "pass:${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" \
  132. --in app/build/outputs/apk/release/app-release-unsigned.apk \
  133. --out app-signed.apk
  134. working-directory: android
  135. - name: Rename Apk
  136. run: |
  137. mkdir builds
  138. mv android/app-signed.apk ./builds/Logseq-android-${{ steps.ref.outputs.version }}.apk
  139. - name: Upload Artifact
  140. uses: actions/upload-artifact@v2
  141. with:
  142. name: logseq-android-builds
  143. path: builds