test.yml 6.2 KB

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