release.yml 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. name: Release Build
  2. on:
  3. # push:
  4. # branches:
  5. # - master
  6. # paths:
  7. # - 'CHANGELOG.md'
  8. workflow_dispatch:
  9. jobs:
  10. prepare:
  11. runs-on: ubuntu-latest
  12. if: github.event_name != 'pull_request' && github.ref == 'refs/heads/master'
  13. outputs:
  14. version: ${{ steps.set-ver.outputs.version }}
  15. play: ${{ steps.check.outputs.play }}
  16. sign: ${{ steps.check.outputs.sign }}
  17. steps:
  18. - id: set-ver
  19. run: |
  20. echo "::set-output name=version::$(date -d "8 hour" -u +3.%y.%m%d%H)"
  21. - id: check
  22. run: |
  23. if [ ! -z "${{ secrets.RELEASE_KEY_STORE }}" ]; then
  24. echo "::set-output name=sign::yes"
  25. fi
  26. if [ ! -z "${{ secrets.SERVICE_ACCOUNT_JSON }}" ]; then
  27. echo "::set-output name=play::yes"
  28. fi
  29. build:
  30. needs: prepare
  31. if: ${{ needs.prepare.outputs.sign }}
  32. strategy:
  33. matrix:
  34. product: [ app, google ]
  35. fail-fast: false
  36. runs-on: ubuntu-latest
  37. env:
  38. product: ${{ matrix.product }}
  39. VERSION: ${{ needs.prepare.outputs.version }}
  40. play: ${{ needs.prepare.outputs.play }}
  41. steps:
  42. - uses: actions/checkout@v3
  43. with:
  44. fetch-depth: 1
  45. - uses: actions/cache@v3
  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: Release Apk Sign
  54. run: |
  55. echo "::set-output name=KeyStore::yes"
  56. echo RELEASE_KEY_ALIAS='${{ secrets.RELEASE_KEY_ALIAS }}' >> gradle.properties
  57. echo RELEASE_KEY_PASSWORD='${{ secrets.RELEASE_KEY_PASSWORD }}' >> gradle.properties
  58. echo RELEASE_STORE_PASSWORD='${{ secrets.RELEASE_STORE_PASSWORD }}' >> gradle.properties
  59. echo RELEASE_STORE_FILE='./key.jks' >> gradle.properties
  60. echo ${{ secrets.RELEASE_KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks
  61. - name: Unify Version Name
  62. run: |
  63. echo "统一版本号"
  64. sed "/def version/c def version = \"${{ env.VERSION }}\"" $GITHUB_WORKSPACE/app/build.gradle -i
  65. - name: Set up Gradle
  66. uses: gradle/gradle-build-action@v2
  67. - name: Build With Gradle
  68. run: |
  69. echo "开始进行${{ env.product }}构建"
  70. chmod +x gradlew
  71. ./gradlew assemble${{ env.product }}release --build-cache --parallel --daemon --warning-mode all
  72. - name: Organize the Files
  73. run: |
  74. mkdir -p ${{ github.workspace }}/apk/
  75. cp -rf ${{ github.workspace }}/app/build/outputs/apk/*/*/*.apk ${{ github.workspace }}/apk/
  76. - name: Upload App To Artifact
  77. uses: actions/upload-artifact@v3
  78. with:
  79. name: legado_${{ env.product }}
  80. path: ${{ github.workspace }}/apk/*.apk
  81. - name: Release
  82. if: ${{ env.product == 'app' }}
  83. uses: softprops/action-gh-release@1e07f4398721186383de40550babbdf2b84acfc5
  84. with:
  85. name: legado_app_${{ env.VERSION }}
  86. tag_name: ${{ env.VERSION }}
  87. body_path: ${{ github.workspace }}/CHANGELOG.md
  88. draft: false
  89. prerelease: false
  90. files: ${{ github.workspace }}/apk/legado_app_*.apk
  91. env:
  92. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  93. - name: Prepare For GooglePlay
  94. if: env.product == 'google' && env.play == 'yes'
  95. run: |
  96. mkdir -p ReleaseNotes
  97. ln -s ${{ github.workspace }}/CHANGELOG.md ReleaseNotes/whatsnew-en-US
  98. ln -s ${{ github.workspace }}/CHANGELOG.md ReleaseNotes/whatsnew-zh-CN
  99. - name: Release To GooglePlay
  100. if: env.product == 'google' && env.play == 'yes'
  101. uses: r0adkll/upload-google-play@v1
  102. with:
  103. serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
  104. packageName: io.legado.play
  105. releaseFiles: ${{ github.workspace }}/apk/legado_google_*.apk
  106. track: production
  107. whatsNewDirectory: ${{ github.workspace }}/ReleaseNotes
  108. - name: Push Assets To "release" Branch
  109. if: ${{ github.actor == 'gedoor' }}
  110. run: |
  111. cd $GITHUB_WORKSPACE/apk/
  112. git init
  113. git checkout -b release
  114. git config --global user.name "github-actions[bot]"
  115. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  116. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  117. git add *.apk
  118. git commit -m "${{ env.VERSION }}"
  119. git push -f -u origin release
  120. - name: Purge Jsdelivr Cache
  121. if: ${{ github.actor == 'gedoor' }}
  122. run: |
  123. result=$(curl -s https://purge.jsdelivr.net/gh/${{ github.actor }}/release@release/)
  124. if echo $result |grep -q 'success.*true'; then
  125. echo "jsdelivr缓存更新成功"
  126. else
  127. echo $result
  128. fi