release.yml 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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 "version=$(date -d "8 hour" -u +3.%y.%m%d%H)" >> $GITHUB_OUTPUT
  21. - id: check
  22. run: |
  23. if [ ! -z "${{ secrets.RELEASE_KEY_STORE }}" ]; then
  24. echo "sign=yes" >> $GITHUB_OUTPUT
  25. fi
  26. if [ ! -z "${{ secrets.SERVICE_ACCOUNT_JSON }}" ]; then
  27. echo "play=yes" >> $GITHUB_OUTPUT
  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@v4
  43. - name: Set up JDK 17
  44. uses: actions/setup-java@v3
  45. with:
  46. distribution: 'temurin'
  47. java-version: 17
  48. - name: Release Apk Sign
  49. run: |
  50. # not use this output
  51. # echo "KeyStore=yes" >> $GITHUB_OUTPUT
  52. echo RELEASE_KEY_ALIAS='${{ secrets.RELEASE_KEY_ALIAS }}' >> gradle.properties
  53. echo RELEASE_KEY_PASSWORD='${{ secrets.RELEASE_KEY_PASSWORD }}' >> gradle.properties
  54. echo RELEASE_STORE_PASSWORD='${{ secrets.RELEASE_STORE_PASSWORD }}' >> gradle.properties
  55. echo RELEASE_STORE_FILE='./key.jks' >> gradle.properties
  56. echo ${{ secrets.RELEASE_KEY_STORE }} | base64 --decode > $GITHUB_WORKSPACE/app/key.jks
  57. - name: Unify Version Name
  58. run: |
  59. echo "统一版本号"
  60. sed "/def version/c def version = \"${{ env.VERSION }}\"" $GITHUB_WORKSPACE/app/build.gradle -i
  61. - name: Set up Gradle
  62. uses: gradle/gradle-build-action@v2
  63. - name: Build With Gradle
  64. run: |
  65. echo "开始进行${{ env.product }}构建"
  66. chmod +x gradlew
  67. ./gradlew assemble${{ env.product }}release --build-cache --parallel --daemon --warning-mode all
  68. - name: Organize the Files
  69. run: |
  70. mkdir -p ${{ github.workspace }}/apk/
  71. cp -rf ${{ github.workspace }}/app/build/outputs/apk/*/*/*.apk ${{ github.workspace }}/apk/
  72. - name: Upload App To Artifact
  73. uses: actions/upload-artifact@v3
  74. with:
  75. name: legado_${{ env.product }}
  76. path: ${{ github.workspace }}/apk/*.apk
  77. - name: Release
  78. if: ${{ env.product == 'app' }}
  79. uses: softprops/action-gh-release@de2c0eb89ae2a093876385947365aca7b0e5f844
  80. with:
  81. name: legado_app_${{ env.VERSION }}
  82. tag_name: ${{ env.VERSION }}
  83. body_path: ${{ github.workspace }}/CHANGELOG.md
  84. draft: false
  85. prerelease: false
  86. files: ${{ github.workspace }}/apk/legado_app_*.apk
  87. env:
  88. GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
  89. - name: Prepare For GooglePlay
  90. if: env.product == 'google' && env.play == 'yes'
  91. run: |
  92. mkdir -p ReleaseNotes
  93. ln -s ${{ github.workspace }}/CHANGELOG.md ReleaseNotes/whatsnew-en-US
  94. ln -s ${{ github.workspace }}/CHANGELOG.md ReleaseNotes/whatsnew-zh-CN
  95. - name: Release To GooglePlay
  96. if: env.product == 'google' && env.play == 'yes'
  97. uses: r0adkll/upload-google-play@v1
  98. with:
  99. serviceAccountJsonPlainText: ${{ secrets.SERVICE_ACCOUNT_JSON }}
  100. packageName: io.legado.play
  101. releaseFiles: ${{ github.workspace }}/apk/legado_google_*.apk
  102. track: production
  103. whatsNewDirectory: ${{ github.workspace }}/ReleaseNotes
  104. - name: Push Assets To "release" Branch
  105. if: ${{ github.actor == 'gedoor' }}
  106. run: |
  107. cd $GITHUB_WORKSPACE/apk/
  108. git init
  109. git checkout -b release
  110. git config --global user.name "github-actions[bot]"
  111. git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
  112. git remote add origin "https://${{ github.actor }}:${{ secrets.ACTIONS_TOKEN }}@github.com/${{ github.actor }}/release"
  113. git add *.apk
  114. git commit -m "${{ env.VERSION }}"
  115. git push -f -u origin release
  116. - name: Purge Jsdelivr Cache
  117. if: ${{ github.actor == 'gedoor' }}
  118. run: |
  119. result=$(curl -s https://purge.jsdelivr.net/gh/${{ github.actor }}/release@release/)
  120. if echo $result |grep -q 'success.*true'; then
  121. echo "jsdelivr缓存更新成功"
  122. else
  123. echo $result
  124. fi