test.yml 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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. labelFixedIssue:
  18. runs-on: ubuntu-latest
  19. steps:
  20. - uses: actions/checkout@v3
  21. with:
  22. fetch-depth: 0
  23. - name: Fixed Issues Labeler
  24. uses: gh-bot/fix-labeler@master
  25. with:
  26. label: 已解决
  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, google, lollipop ]
  53. type: [ release, releaseA ]
  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@v3
  63. with:
  64. fetch-depth: 0
  65. - name: Set up JDK 17
  66. uses: actions/setup-java@v3
  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 "给apk增加签名"
  77. cp $GITHUB_WORKSPACE/.github/workflows/legado.jks $GITHUB_WORKSPACE/app/legado.jks
  78. sed '$a\RELEASE_STORE_FILE=./legado.jks' $GITHUB_WORKSPACE/gradle.properties -i
  79. sed '$a\RELEASE_KEY_ALIAS=legado' $GITHUB_WORKSPACE/gradle.properties -i
  80. sed '$a\RELEASE_STORE_PASSWORD=gedoor_legado' $GITHUB_WORKSPACE/gradle.properties -i
  81. sed '$a\RELEASE_KEY_PASSWORD=gedoor_legado' $GITHUB_WORKSPACE/gradle.properties -i
  82. - name: Set up Gradle
  83. uses: gradle/gradle-build-action@v2
  84. - name: Build With Gradle
  85. run: |
  86. if [ ${{ env.type }} == 'release' ]; then
  87. typeName="原包名"
  88. else
  89. typeName="共存"
  90. sed "s/'.release'/'.releaseA'/" $GITHUB_WORKSPACE/app/build.gradle -i
  91. sed 's/.release/.releaseA/' $GITHUB_WORKSPACE/app/google-services.json -i
  92. fi
  93. echo "统一版本号"
  94. sed "/def version/c def version = \"${{ env.VERSION }}\"" $GITHUB_WORKSPACE/app/build.gradle -i
  95. echo "开始${{ env.product }}$typeName构建"
  96. chmod +x gradlew
  97. ./gradlew assemble${{ env.product }}release --build-cache --parallel --daemon --warning-mode all
  98. echo "修改文件名"
  99. mkdir -p ${{ github.workspace }}/apk/
  100. for file in `ls ${{ github.workspace }}/app/build/outputs/apk/*/*/*.apk`; do
  101. mv "$file" ${{ github.workspace }}/apk/legado_${{ env.product }}_${{ env.VERSIONL }}_$typeName.apk
  102. done
  103. - name: Upload App To Artifact
  104. uses: actions/upload-artifact@v3
  105. with:
  106. name: legado.${{ env.product }}.${{ env.type }}
  107. path: ${{ github.workspace }}/apk/*.apk
  108. lanzou:
  109. needs: [ prepare, build ]
  110. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.lanzou == 'yes' }}
  111. runs-on: ubuntu-latest
  112. env:
  113. # 登录蓝奏云后在控制台运行document.cookie
  114. ylogin: ${{ secrets.LANZOU_ID }}
  115. phpdisk_info: ${{ secrets.LANZOU_PSD }}
  116. # 蓝奏云里的文件夹ID(阅读3测试版:2670621)
  117. LANZOU_FOLDER_ID: '2670621'
  118. steps:
  119. - uses: actions/checkout@v3
  120. - uses: actions/download-artifact@v3
  121. with:
  122. path: apk/
  123. - working-directory: apk/
  124. run: mv */*.apk . ;rm -rf */
  125. - name: Upload To Lanzou
  126. continue-on-error: true
  127. run: |
  128. path="$GITHUB_WORKSPACE/apk/"
  129. python3 $GITHUB_WORKSPACE/.github/scripts/lzy_web.py "$path" "$LANZOU_FOLDER_ID"
  130. echo "[$(date -u -d '+8 hour' '+%Y.%m.%d %H:%M:%S')] 分享链接: https://kunfei.lanzoux.com/b0f810h4b"
  131. test_Branch:
  132. needs: [ prepare, build ]
  133. runs-on: ubuntu-latest
  134. if: ${{ github.event_name != 'pull_request' && github.actor == 'gedoor' }}
  135. steps:
  136. - uses: actions/checkout@v3
  137. - uses: actions/download-artifact@v3
  138. with:
  139. path: apk/
  140. - working-directory: apk/
  141. run: mv */*.apk . ;rm -rf */
  142. - name: Push To "test" Branch
  143. run: |
  144. cd $GITHUB_WORKSPACE/apk/
  145. git init
  146. git checkout -b test
  147. git config --global user.name "github-actions[bot]"
  148. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  149. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  150. git add *.apk
  151. git commit -m "${{ needs.prepare.outputs.versionL }}"
  152. git push -f -u origin test
  153. telegram:
  154. needs: [ prepare, build ]
  155. if: ${{ github.event_name != 'pull_request' && needs.prepare.outputs.telegram == 'yes' }}
  156. runs-on: ubuntu-latest
  157. env:
  158. CHANNEL_ID: ${{ secrets.CHANNEL_ID }}
  159. BOT_TOKEN: ${{ secrets.BOT_TOKEN }}
  160. steps:
  161. - uses: actions/checkout@v3
  162. - uses: actions/download-artifact@v3
  163. with:
  164. path: apk/
  165. - working-directory: apk/
  166. run: |
  167. for file in `ls */*.apk`; do
  168. mv "$file" "$(echo "$file"|sed -e 's#.*\/##g' -e "s/_/ /g" -e 's/legado/阅读/')"
  169. done
  170. rm -rf */
  171. - name: Post to channel
  172. run: |
  173. pip install pyTelegramBotAPI
  174. path="$GITHUB_WORKSPACE/apk/"
  175. python3 $GITHUB_WORKSPACE/.github/scripts/tg_bot.py "$BOT_TOKEN" "$CHANNEL_ID" "$path"