test.yml 7.7 KB

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