test.yml 7.6 KB

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