test.yml 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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 "/def version/c def version = \"${{ env.VERSION }}\"" $GITHUB_WORKSPACE/app/build.gradle -i
  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 APK
  112. uses: actions/upload-artifact@v4
  113. with:
  114. name: APKs
  115. path: |
  116. $GITHUB_WORKSPACE/app/app/build/outputs/apk/release/*/*.apk
  117. - name: Upload Mapping File To Artifact
  118. uses: actions/upload-artifact@v4
  119. with:
  120. name: legado.${{ env.product }}.${{ env.type }}.mapping
  121. if-no-files-found: ignore
  122. path: ${{ github.workspace }}/mapping/mapping.txt
  123. lanzou:
  124. needs: [ prepare, build ]
  125. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.lanzou == 'yes' }}
  126. runs-on: ubuntu-latest
  127. env:
  128. # 登录蓝奏云后在控制台运行document.cookie
  129. ylogin: ${{ secrets.LANZOU_ID }}
  130. phpdisk_info: ${{ secrets.LANZOU_PSD }}
  131. # 蓝奏云里的文件夹ID(阅读3测试版:2670621)
  132. LANZOU_FOLDER_ID: ${{ secrets.LANZOU_FOLDER_ID }}
  133. #蓝奏云分享链接
  134. LANZOU_URL: ${{ secrets.LANZOU_URL }}
  135. steps:
  136. - uses: actions/checkout@v5
  137. - uses: actions/download-artifact@v5
  138. with:
  139. path: apk/
  140. - working-directory: apk/
  141. run: mv */*.apk . ;rm -rf */
  142. - name: Upload To Lanzou
  143. continue-on-error: true
  144. run: |
  145. path="$GITHUB_WORKSPACE/apk/"
  146. python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
  147. echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: $LANZOU_URL"
  148. test_Branch:
  149. needs: [ prepare, build ]
  150. runs-on: ubuntu-latest
  151. if: ${{ github.event_name != 'pull_request' && github.actor == 'gedoor' }}
  152. steps:
  153. - uses: actions/checkout@v5
  154. - uses: actions/download-artifact@v5
  155. with:
  156. path: apk/
  157. - working-directory: apk/
  158. run: mv */*.apk . ;rm -rf */
  159. - name: Push To "test" Branch
  160. run: |
  161. cd $GITHUB_WORKSPACE/apk/
  162. git init
  163. git checkout -b test
  164. git config --global user.name "github-actions[bot]"
  165. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  166. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  167. git add *.apk
  168. git commit -m "${{ needs.prepare.outputs.versionL }}"
  169. git push -f -u origin test
  170. telegram:
  171. needs: [ prepare, build ]
  172. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.telegram == 'yes' }}
  173. runs-on: ubuntu-latest
  174. steps:
  175. - uses: actions/checkout@v5
  176. - uses: actions/download-artifact@v5
  177. with:
  178. path: apk/
  179. - working-directory: apk/
  180. run: |
  181. for file in `ls */*.apk`; do
  182. mv "$file" "$(echo "$file"|sed -e 's#.*\/##g' -e "s/_/ /g" -e 's/legado/阅读/')"
  183. done
  184. rm -rf */
  185. - name: Post to channel
  186. uses: xireiki/channel-post@v1
  187. with:
  188. chat_id: ${{ secrets.CHANNEL_ID }}
  189. bot_token: ${{ secrets.BOT_TOKEN }}
  190. context: "#阅读 #Legado #Beta ${{ needs.prepare.outputs.versionL }}"
  191. path: apk/*
  192. method: sendFile