test.yml 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  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
  91. echo "修改APK文件名"
  92. mkdir -p ${{ github.workspace }}/apk/
  93. for file in ${{ github.workspace }}/app/app/release/*-release.apk; do
  94. filename=$(basename "$file")
  95. if [[ "$filename" == *"armeabi-v7a"* ]]; then
  96. mv "$file" ${{ github.workspace }}/apk/legado_${{ env.product }}_${{ env.VERSIONL }}_${{ env.type }}_32.apk
  97. elif [[ "$filename" == *"arm64-v8a"* ]]; then
  98. mv "$file" ${{ github.workspace }}/apk/legado_${{ env.product }}_${{ env.VERSIONL }}_${{ env.type }}_64.apk
  99. elif [[ "$filename" == *"universal"* ]]; then
  100. mv "$file" ${{ github.workspace }}/apk/legado_${{ env.product }}_${{ env.VERSIONL }}_${{ env.type }}_universal.apk
  101. fi
  102. done
  103. echo "移动mapping文件"
  104. mkdir -p ${{ github.workspace }}/mapping/
  105. for file in `ls ${{ github.workspace }}/app/build/outputs/mapping/*/mapping.txt`; do
  106. mv "$file" ${{ github.workspace }}/mapping/mapping.txt
  107. done
  108. - name: Move Missing Rules Files
  109. run: |
  110. echo "移动missing_rules.txt文件"
  111. mkdir -p ${{ github.workspace }}/mapping/
  112. for file in `ls ${{ github.workspace }}/app/build/outputs/mapping/*/missing_rules.txt`; do
  113. mv "$file" ${{ github.workspace }}/mapping/missing_rules.txt
  114. done
  115. - name: Upload Missing Rules File To Artifact
  116. uses: actions/upload-artifact@v4
  117. with:
  118. name: legado.${{ env.product }}.${{ env.type }}.mapping.missing_rules
  119. if-no-files-found: ignore
  120. path: ${{ github.workspace }}/mapping/missing_rules.txt
  121. - name: Check Build production
  122. run: |
  123. if [ ! -d ${{ github.workspace }}/apk ]; then
  124. echo "Build production not found! Check gradle logs."
  125. exit 1
  126. fi
  127. cd ${{ github.workspace }}/apk/
  128. if [ ! -e legado_*.apk ]; then
  129. echo "Build production not found! Check gradle logs."
  130. exit 1
  131. fi
  132. - name: Upload 32-bit APK
  133. uses: actions/upload-artifact@v4
  134. with:
  135. name: legado.${{ env.product }}.${{ env.type }}.apk.32
  136. path: ${{ github.workspace }}/apk/*_32.apk
  137. - name: Upload 64-bit APK
  138. uses: actions/upload-artifact@v4
  139. with:
  140. name: legado.${{ env.product }}.${{ env.type }}.apk.64
  141. path: ${{ github.workspace }}/apk/*_64.apk
  142. - name: Upload Universal APK
  143. uses: actions/upload-artifact@v4
  144. with:
  145. name: legado.${{ env.product }}.${{ env.type }}.apk.universal
  146. path: ${{ github.workspace }}/apk/*_universal.apk
  147. - name: Upload Mapping File To Artifact
  148. uses: actions/upload-artifact@v4
  149. with:
  150. name: legado.${{ env.product }}.${{ env.type }}.mapping
  151. if-no-files-found: ignore
  152. path: ${{ github.workspace }}/mapping/mapping.txt
  153. lanzou:
  154. needs: [ prepare, build ]
  155. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.lanzou == 'yes' }}
  156. runs-on: ubuntu-latest
  157. env:
  158. # 登录蓝奏云后在控制台运行document.cookie
  159. ylogin: ${{ secrets.LANZOU_ID }}
  160. phpdisk_info: ${{ secrets.LANZOU_PSD }}
  161. # 蓝奏云里的文件夹ID(阅读3测试版:2670621)
  162. LANZOU_FOLDER_ID: ${{ secrets.LANZOU_FOLDER_ID }}
  163. #蓝奏云分享链接
  164. LANZOU_URL: ${{ secrets.LANZOU_URL }}
  165. steps:
  166. - uses: actions/checkout@v5
  167. - uses: actions/download-artifact@v5
  168. with:
  169. path: apk/
  170. - working-directory: apk/
  171. run: mv */*.apk . ;rm -rf */
  172. - name: Upload To Lanzou
  173. continue-on-error: true
  174. run: |
  175. path="$GITHUB_WORKSPACE/apk/"
  176. python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
  177. echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: $LANZOU_URL"
  178. test_Branch:
  179. needs: [ prepare, build ]
  180. runs-on: ubuntu-latest
  181. if: ${{ github.event_name != 'pull_request' && github.actor == 'gedoor' }}
  182. steps:
  183. - uses: actions/checkout@v5
  184. - uses: actions/download-artifact@v5
  185. with:
  186. path: apk/
  187. - working-directory: apk/
  188. run: mv */*.apk . ;rm -rf */
  189. - name: Push To "test" Branch
  190. run: |
  191. cd $GITHUB_WORKSPACE/apk/
  192. git init
  193. git checkout -b test
  194. git config --global user.name "github-actions[bot]"
  195. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  196. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  197. git add *.apk
  198. git commit -m "${{ needs.prepare.outputs.versionL }}"
  199. git push -f -u origin test
  200. telegram:
  201. needs: [ prepare, build ]
  202. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.telegram == 'yes' }}
  203. runs-on: ubuntu-latest
  204. steps:
  205. - uses: actions/checkout@v5
  206. - uses: actions/download-artifact@v5
  207. with:
  208. path: apk/
  209. - working-directory: apk/
  210. run: |
  211. for file in `ls */*.apk`; do
  212. mv "$file" "$(echo "$file"|sed -e 's#.*\/##g' -e "s/_/ /g" -e 's/legado/阅读/')"
  213. done
  214. rm -rf */
  215. - name: Post to channel
  216. uses: xireiki/channel-post@v1
  217. with:
  218. chat_id: ${{ secrets.CHANNEL_ID }}
  219. bot_token: ${{ secrets.BOT_TOKEN }}
  220. context: "#阅读 #Legado #Beta ${{ needs.prepare.outputs.versionL }}"
  221. path: apk/*
  222. method: sendFile