test.yml 9.4 KB

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