test.yml 5.9 KB

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