test.yml 6.2 KB

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