test.yml 6.2 KB

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