test.yml 6.1 KB

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