test.yml 5.9 KB

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