test.yml 8.3 KB

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