test.yml 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. name: Test Build
  2. on:
  3. push:
  4. branches:
  5. - main
  6. paths:
  7. - '**'
  8. # - '!**/assets/**'
  9. # - '!**.md'
  10. - '!**/ISSUE_TEMPLATE/**'
  11. - '!**/modules/web/**'
  12. pull_request:
  13. paths-ignore:
  14. - '**/modules/web/**'
  15. workflow_run:
  16. workflows: [Build Web]
  17. branches: [master]
  18. types:
  19. - completed
  20. workflow_dispatch:
  21. permissions:
  22. contents: write
  23. concurrency:
  24. group: ${{ github.workflow }}-${{ github.ref }}
  25. cancel-in-progress: true
  26. jobs:
  27. prepare:
  28. runs-on: ubuntu-latest
  29. if: ${{ !startsWith(github.event.head_commit.message, 'Merge pull request') }}
  30. outputs:
  31. version: ${{ steps.set-ver.outputs.version }}
  32. versionL: ${{ steps.set-ver.outputs.versionL }}
  33. lanzou: ${{ steps.check.outputs.lanzou }}
  34. telegram: ${{ steps.check.outputs.telegram }}
  35. steps:
  36. - id: set-ver
  37. run: |
  38. echo "version=$(date -d "8 hour" -u +3.%y.%m%d%H)" >> $GITHUB_OUTPUT
  39. echo "versionL=$(date -d "8 hour" -u +3.%y.%m%d%H%M)" >> $GITHUB_OUTPUT
  40. - id: check
  41. run: |
  42. if [ ${{ secrets.LANZOU_ID }} ]; then
  43. echo "lanzou=yes" >> $GITHUB_OUTPUT
  44. fi
  45. if [ ${{ secrets.BOT_TOKEN }} ]; then
  46. echo "telegram=yes" >> $GITHUB_OUTPUT
  47. fi
  48. build:
  49. needs: prepare
  50. strategy:
  51. matrix:
  52. product: [ app ]
  53. type: [ release ]
  54. fail-fast: false
  55. runs-on: ubuntu-latest
  56. env:
  57. product: ${{ matrix.product }}
  58. type: ${{ matrix.type }}
  59. VERSION: ${{ needs.prepare.outputs.version }}
  60. VERSIONL: ${{ needs.prepare.outputs.versionL }}
  61. steps:
  62. - uses: actions/checkout@v5
  63. with:
  64. fetch-depth: 0
  65. - name: Set up JDK 17
  66. uses: actions/setup-java@v5
  67. with:
  68. distribution: 'temurin'
  69. java-version: 17
  70. - name: Clear 18PlusList.txt
  71. run: |
  72. echo "清空18PlusList.txt"
  73. echo "">$GITHUB_WORKSPACE/app/src/main/assets/18PlusList.txt
  74. - name: Release Apk Sign
  75. run: |
  76. echo "${{ secrets.SIGNING_KEY }}" | base64 -d > $GITHUB_WORKSPACE/app/my-release-key.jks
  77. echo "RELEASE_STORE_FILE=my-release-key.jks" >> $GITHUB_WORKSPACE/gradle.properties
  78. echo "RELEASE_STORE_PASSWORD=${{ secrets.KEYSTORE_PASSWORD }}" >> $GITHUB_WORKSPACE/gradle.properties
  79. echo "RELEASE_KEY_ALIAS=${{ secrets.KEY_ALIAS }}" >> $GITHUB_WORKSPACE/gradle.properties
  80. echo "RELEASE_KEY_PASSWORD=${{ secrets.KEY_PASSWORD }}" >> $GITHUB_WORKSPACE/gradle.properties
  81. - name: Set up Gradle
  82. uses: gradle/actions/setup-gradle@v4
  83. - name: Build With Gradle
  84. run: |
  85. echo "统一版本号"
  86. sed -i "s/ext.versionName = .*/ext.versionName = \"${{ env.VERSION }}\"/" $GITHUB_WORKSPACE/app/build.gradle
  87. echo "开始${{ env.product }}${{ env.type }}构建"
  88. chmod +x gradlew
  89. ./gradlew assemble${{ env.product }}Release
  90. - name: Move Missing Rules Files
  91. run: |
  92. echo "移动missing_rules.txt文件"
  93. mkdir -p ${{ github.workspace }}/mapping/
  94. for file in `ls ${{ github.workspace }}/app/build/outputs/mapping/*/missing_rules.txt`; do
  95. mv "$file" ${{ github.workspace }}/mapping/missing_rules.txt
  96. done
  97. - name: Upload Missing Rules File To Artifact
  98. uses: actions/upload-artifact@v4
  99. with:
  100. name: legado.${{ env.product }}.${{ env.type }}.mapping.missing_rules
  101. if-no-files-found: ignore
  102. path: ${{ github.workspace }}/mapping/missing_rules.txt
  103. - name: Check Build production
  104. run: |
  105. echo "查看 APK 输出目录"
  106. ls -R $GITHUB_WORKSPACE/app/build/outputs/apk/
  107. if ! ls $GITHUB_WORKSPACE/app/build/outputs/apk/*/*/*.apk 1> /dev/null 2>&1; then
  108. echo "Build production not found! Check gradle logs."
  109. exit 1
  110. fi
  111. - name: Upload universal APK
  112. uses: actions/upload-artifact@v4
  113. with:
  114. name: universal-apk
  115. path: app/build/outputs/apk/app/release/legado_app_*[0-9].apk
  116. - name: Upload arm64-v8a APK
  117. uses: actions/upload-artifact@v4
  118. with:
  119. name: arm64-v8a-apk
  120. path: app/build/outputs/apk/app/release/*arm64-v8a.apk
  121. - name: Upload armeabi-v7a APK
  122. uses: actions/upload-artifact@v4
  123. with:
  124. name: armeabi-v7a-apk
  125. path: app/build/outputs/apk/app/release/*armeabi-v7a.apk
  126. - name: Upload Mapping File To Artifact
  127. uses: actions/upload-artifact@v4
  128. with:
  129. name: legado.${{ env.product }}.${{ env.type }}.mapping
  130. if-no-files-found: ignore
  131. path: ${{ github.workspace }}/mapping/mapping.txt
  132. lanzou:
  133. needs: [ prepare, build ]
  134. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.lanzou == 'yes' }}
  135. runs-on: ubuntu-latest
  136. env:
  137. # 登录蓝奏云后在控制台运行document.cookie
  138. ylogin: ${{ secrets.LANZOU_ID }}
  139. phpdisk_info: ${{ secrets.LANZOU_PSD }}
  140. # 蓝奏云里的文件夹ID(阅读3测试版:2670621)
  141. LANZOU_FOLDER_ID: ${{ secrets.LANZOU_FOLDER_ID }}
  142. #蓝奏云分享链接
  143. LANZOU_URL: ${{ secrets.LANZOU_URL }}
  144. steps:
  145. - uses: actions/checkout@v5
  146. - uses: actions/download-artifact@v5
  147. with:
  148. path: apk/
  149. - working-directory: apk/
  150. run: mv */*.apk . ;rm -rf */
  151. - name: Upload To Lanzou
  152. continue-on-error: true
  153. run: |
  154. path="$GITHUB_WORKSPACE/apk/"
  155. python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
  156. echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: $LANZOU_URL"
  157. test_Branch:
  158. needs: [ prepare, build ]
  159. runs-on: ubuntu-latest
  160. if: ${{ github.event_name != 'pull_request' && github.actor == 'gedoor' }}
  161. steps:
  162. - uses: actions/checkout@v5
  163. - uses: actions/download-artifact@v5
  164. with:
  165. path: apk/
  166. - working-directory: apk/
  167. run: mv */*.apk . ;rm -rf */
  168. - name: Push To "test" Branch
  169. run: |
  170. cd $GITHUB_WORKSPACE/apk/
  171. git init
  172. git checkout -b test
  173. git config --global user.name "github-actions[bot]"
  174. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  175. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  176. git add *.apk
  177. git commit -m "${{ needs.prepare.outputs.versionL }}"
  178. git push -f -u origin test
  179. telegram:
  180. needs: [ prepare, build ]
  181. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.telegram == 'yes' }}
  182. runs-on: ubuntu-latest
  183. steps:
  184. - uses: actions/checkout@v5
  185. - uses: actions/download-artifact@v5
  186. with:
  187. path: apk/
  188. - working-directory: apk/
  189. run: |
  190. for file in `ls */*.apk`; do
  191. mv "$file" "$(echo "$file"|sed -e 's#.*\/##g' -e "s/_/ /g" -e 's/legado/阅读/')"
  192. done
  193. rm -rf */
  194. - name: Post to channel
  195. uses: xireiki/channel-post@v1
  196. with:
  197. chat_id: ${{ secrets.CHANNEL_ID }}
  198. bot_token: ${{ secrets.BOT_TOKEN }}
  199. context: "#阅读 #Legado #Beta ${{ needs.prepare.outputs.versionL }}"
  200. path: apk/*
  201. method: sendFile