build-android.yml 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. jobs:
  44. build-apk:
  45. runs-on: ubuntu-latest
  46. steps:
  47. - name: Check out Git repository
  48. uses: actions/checkout@v2
  49. with:
  50. ref: ${{ github.event.inputs.git-ref }}
  51. - name: Install Node.js, NPM and Yarn
  52. uses: actions/setup-node@v2
  53. with:
  54. node-version: ${{ env.NODE_VERSION }}
  55. - name: Get yarn cache directory path
  56. id: yarn-cache-dir-path
  57. run: echo "::set-output name=dir::$(yarn cache dir)"
  58. - name: Cache yarn cache directory
  59. uses: actions/cache@v2
  60. id: yarn-cache
  61. with:
  62. path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
  63. key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
  64. restore-keys: |
  65. ${{ runner.os }}-yarn-
  66. - name: Setup Java JDK
  67. uses: actions/[email protected]
  68. with:
  69. java-version: 1.8
  70. - name: Cache clojure deps
  71. uses: actions/cache@v2
  72. with:
  73. path: |
  74. ~/.m2/repository
  75. ~/.gitlibs
  76. key: ${{ runner.os }}-clojure-lib-${{ hashFiles('**/deps.edn') }}
  77. - name: Setup clojure
  78. uses: DeLaGuardo/[email protected]
  79. with:
  80. cli: ${{ env.CLOJURE_VERSION }}
  81. - name: Retrieve tag version
  82. id: ref
  83. run: |
  84. pkgver=$(node ./scripts/get-pkg-version.js "${{ inputs.build-target || github.event.inputs.build-target }}")
  85. echo ::set-output name=version::$pkgver
  86. - name: Update Nightly APP Version
  87. if: ${{ inputs.build-target == 'nightly' || github.event.inputs.build-target == 'nightly' }}
  88. run: |
  89. sed -i 's/defonce version ".*"/defonce version "${{ steps.ref.outputs.version }}"/g' src/main/frontend/version.cljs
  90. sed -i 's/versionName ".*"/versionName "${{ steps.ref.outputs.version }}"/g' android/app/build.gradle
  91. - name: Set Build Environment Variables
  92. run: |
  93. echo "ENABLE_FILE_SYNC_PRODUCTION=${{ inputs.enable-file-sync-production == 'true' || github.event.inputs.enable-file-sync-production == 'true' }}" >> $GITHUB_ENV
  94. - name: Compile CLJS - android variant, use es6 instead of es-next
  95. run: yarn install && yarn release-android-app
  96. - name: Upload Sentry Sourcemaps (beta only)
  97. if: ${{ github.repository == 'logseq/logseq' && (inputs.build-target == 'beta' || github.event.inputs.build-target == 'beta') }}
  98. run: |
  99. curl -sL https://sentry.io/get-cli/ | bash
  100. release_name="logseq-android@${{ steps.ref.outputs.version }}"
  101. sentry-cli releases new "${release_name}"
  102. sentry-cli releases files "${release_name}" upload-sourcemaps --ext map --ext js ./static/js --url-prefix '~/static/js'
  103. sentry-cli releases finalize "${release_name}"
  104. env:
  105. SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
  106. SENTRY_ORG: logseq
  107. SENTRY_PROJECT: logseq
  108. - name: Prepare public Directory
  109. run: |
  110. cp -r static public/
  111. rm -rvf public/static/js/publishing
  112. rm -rvf public/static/js/*.js.map || true
  113. rm -rvf public/static/*.*
  114. rm -rvf public/static/ios
  115. rm -rvf android/app/src/main/assets/public || true
  116. - name: Sync public to Android Project
  117. run: npx cap sync
  118. - name: Setup Android SDK
  119. uses: android-actions/setup-android@v2
  120. - name: Build Android
  121. run: |
  122. ./gradlew clean
  123. ./gradlew zipApksForRelease
  124. working-directory: android
  125. - name: Sign Android APK
  126. run: |
  127. echo ${{ secrets.ANDROID_KEYSTORE }} | base64 -d > keystore.jks
  128. /usr/local/lib/android/sdk/build-tools/30.0.3/apksigner sign \
  129. --ks keystore.jks --ks-pass "pass:${{ secrets.ANDROID_KEYSTORE_PASSWORD }}" \
  130. --in app/build/outputs/apk/release/app-release-unsigned.apk \
  131. --out app-signed.apk
  132. working-directory: android
  133. - name: Rename Apk
  134. run: |
  135. mkdir builds
  136. mv android/app-signed.apk ./builds/Logseq-android-${{ steps.ref.outputs.version }}.apk
  137. - name: Upload Artifact
  138. uses: actions/upload-artifact@v2
  139. with:
  140. name: logseq-android-builds
  141. path: builds