test.yml 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. continue-on-error: true
  85. run: |
  86. echo "统一版本号"
  87. sed "/def version/c def version = \"${{ env.VERSION }}\"" $GITHUB_WORKSPACE/app/build.gradle -i
  88. echo "开始${{ env.product }}${{ env.type }}构建"
  89. chmod +x gradlew
  90. ./gradlew assemble${{ env.product }}release --build-cache --parallel --daemon --warning-mode all
  91. echo "修改APK文件名"
  92. mkdir -p ${{ github.workspace }}/apk/
  93. for file in `ls ${{ github.workspace }}/app/build/outputs/apk/*/*/*.apk`; do
  94. mv "$file" ${{ github.workspace }}/apk/legado_${{ env.product }}_${{ env.VERSIONL }}_${{ env.type }}.apk
  95. done
  96. echo "移动mapping文件"
  97. mkdir -p ${{ github.workspace }}/mapping/
  98. for file in `ls ${{ github.workspace }}/app/build/outputs/mapping/*/mapping.txt`; do
  99. mv "$file" ${{ github.workspace }}/mapping/mapping.txt
  100. done
  101. - name: Move Missing Rules Files
  102. run: |
  103. echo "移动missing_rules.txt文件"
  104. mkdir -p ${{ github.workspace }}/mapping/
  105. for file in `ls ${{ github.workspace }}/app/build/outputs/mapping/*/missing_rules.txt`; do
  106. mv "$file" ${{ github.workspace }}/mapping/missing_rules.txt
  107. done
  108. - name: Upload Missing Rules File To Artifact
  109. uses: actions/upload-artifact@v4
  110. with:
  111. name: legado.${{ env.product }}.${{ env.type }}.mapping.missing_rules
  112. if-no-files-found: ignore
  113. path: ${{ github.workspace }}/mapping/missing_rules.txt
  114. - name: Check Build production
  115. run: |
  116. if [ ! -d ${{ github.workspace }}/apk ]; then
  117. echo "Build production not found! Check gradle logs."
  118. exit 1
  119. fi
  120. cd ${{ github.workspace }}/apk/
  121. if [ ! -e legado_*.apk ]; then
  122. echo "Build production not found! Check gradle logs."
  123. exit 1
  124. fi
  125. - name: Upload App To Artifact
  126. uses: actions/upload-artifact@v4
  127. with:
  128. name: legado.${{ env.product }}.${{ env.type }}
  129. if-no-files-found: ignore
  130. path: ${{ github.workspace }}/apk/*.apk
  131. - name: Upload Mapping File To Artifact
  132. uses: actions/upload-artifact@v4
  133. with:
  134. name: legado.${{ env.product }}.${{ env.type }}.mapping
  135. if-no-files-found: ignore
  136. path: ${{ github.workspace }}/mapping/mapping.txt
  137. prerelease:
  138. needs: [ prepare, build ]
  139. if: github.event_name != 'pull_request' && github.repository == 'HapeLee/legado-with-MD3'
  140. runs-on: ubuntu-latest
  141. env:
  142. VERSION: ${{ needs.prepare.outputs.version }}
  143. steps:
  144. - uses: actions/checkout@v5
  145. - uses: actions/download-artifact@v5
  146. with:
  147. path: apk/
  148. - name: Delete Pre-Release
  149. run: |
  150. if gh release view beta &>/dev/null; then
  151. gh release delete beta -y
  152. fi
  153. env:
  154. GH_TOKEN: ${{ github.token }}
  155. - name: Publish Pre-Release
  156. uses: ncipollo/release-action@v1
  157. with:
  158. name: legado_app_${{ env.VERSION }}
  159. tag: "beta"
  160. body: "此版本为测试版,签名与正式版不同,可能存在不稳定情况,升级前请务必备份好数据。"
  161. prerelease: true
  162. artifacts: ${{ github.workspace }}/apk/*.apk
  163. lanzou:
  164. needs: [ prepare, build ]
  165. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.lanzou == 'yes' }}
  166. runs-on: ubuntu-latest
  167. env:
  168. # 登录蓝奏云后在控制台运行document.cookie
  169. ylogin: ${{ secrets.LANZOU_ID }}
  170. phpdisk_info: ${{ secrets.LANZOU_PSD }}
  171. # 蓝奏云里的文件夹ID(阅读3测试版:2670621)
  172. LANZOU_FOLDER_ID: ${{ secrets.LANZOU_FOLDER_ID }}
  173. #蓝奏云分享链接
  174. LANZOU_URL: ${{ secrets.LANZOU_URL }}
  175. steps:
  176. - uses: actions/checkout@v5
  177. - uses: actions/download-artifact@v5
  178. with:
  179. path: apk/
  180. - working-directory: apk/
  181. run: mv */*.apk . ;rm -rf */
  182. - name: Upload To Lanzou
  183. continue-on-error: true
  184. run: |
  185. path="$GITHUB_WORKSPACE/apk/"
  186. python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
  187. echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: $LANZOU_URL"
  188. test_Branch:
  189. needs: [ prepare, build ]
  190. runs-on: ubuntu-latest
  191. if: ${{ github.event_name != 'pull_request' && github.actor == 'gedoor' }}
  192. steps:
  193. - uses: actions/checkout@v5
  194. - uses: actions/download-artifact@v5
  195. with:
  196. path: apk/
  197. - working-directory: apk/
  198. run: mv */*.apk . ;rm -rf */
  199. - name: Push To "test" Branch
  200. run: |
  201. cd $GITHUB_WORKSPACE/apk/
  202. git init
  203. git checkout -b test
  204. git config --global user.name "github-actions[bot]"
  205. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  206. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  207. git add *.apk
  208. git commit -m "${{ needs.prepare.outputs.versionL }}"
  209. git push -f -u origin test
  210. telegram:
  211. needs: [ prepare, build ]
  212. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.telegram == 'yes' }}
  213. runs-on: ubuntu-latest
  214. steps:
  215. - uses: actions/checkout@v5
  216. - uses: actions/download-artifact@v5
  217. with:
  218. path: apk/
  219. - working-directory: apk/
  220. run: |
  221. for file in `ls */*.apk`; do
  222. mv "$file" "$(echo "$file"|sed -e 's#.*\/##g' -e "s/_/ /g" -e 's/legado/阅读/')"
  223. done
  224. rm -rf */
  225. - name: Post to channel
  226. uses: xireiki/channel-post@v1
  227. with:
  228. chat_id: ${{ secrets.CHANNEL_ID }}
  229. bot_token: ${{ secrets.BOT_TOKEN }}
  230. context: "#阅读 #Legado #Beta ${{ needs.prepare.outputs.versionL }}"
  231. path: apk/*
  232. method: sendFile