Release #64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Release | |
| on: | |
| push: | |
| tags: | |
| - "v*" | |
| workflow_dispatch: | |
| inputs: | |
| tag_name: | |
| description: '要创建的标签名 (例如: v1.0.0)' | |
| required: true | |
| type: string | |
| release_notes: | |
| description: '发布说明 (可选,默认使用 .github/release_notes.md)' | |
| required: false | |
| type: string | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - uses: actions/checkout@v3 | |
| # 手动触发时检出默认分支,而不是指定的标签 | |
| with: | |
| ref: ${{ github.event_name == 'workflow_dispatch' && github.ref || github.ref }} | |
| - uses: actions/setup-java@v3 | |
| with: | |
| distribution: temurin | |
| java-version: 21 | |
| - uses: gradle/gradle-build-action@v2 | |
| with: | |
| gradle-version: current | |
| arguments: assembleRelease | |
| - uses: r0adkll/sign-android-release@v1 | |
| id: sign_app | |
| with: | |
| releaseDirectory: app/build/outputs/apk/release | |
| signingKeyBase64: ${{ secrets.SIGNING_KEY }} | |
| alias: ${{ secrets.ALIAS }} | |
| keyStorePassword: ${{ secrets.KEY_STORE_PASSWORD }} | |
| keyPassword: ${{ secrets.KEY_PASSWORD }} | |
| env: | |
| BUILD_TOOLS_VERSION: "34.0.0" | |
| # 根据触发方式决定APK文件名 | |
| - name: Rename APK file | |
| run: | | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| mv ${{ steps.sign_app.outputs.signedReleaseFile }} Mei_${{ github.event.inputs.tag_name }}.apk | |
| else | |
| mv ${{ steps.sign_app.outputs.signedReleaseFile }} Mei_${GITHUB_REF_NAME}.apk | |
| fi | |
| - name: Read Release Notes | |
| id: release_notes | |
| run: | | |
| # 优先使用手动输入的发布说明,其次使用文件,最后使用默认值 | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ] && [ -n "${{ github.event.inputs.release_notes }}" ]; then | |
| body="${{ github.event.inputs.release_notes }}" | |
| elif [ -f .github/release_notes.md ]; then | |
| body=$(cat .github/release_notes.md) | |
| else | |
| if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
| body="Release ${{ github.event.inputs.tag_name }}" | |
| else | |
| body="Release ${{ github.ref_name }}" | |
| fi | |
| fi | |
| { | |
| echo "BODY<<EOF" | |
| echo "$body" | |
| echo "EOF" | |
| } >> "$GITHUB_OUTPUT" | |
| # 手动触发时需要先创建标签 | |
| - name: Create tag for manual release | |
| if: github.event_name == 'workflow_dispatch' | |
| run: | | |
| git config user.name "github-actions" | |
| git config user.email "github-actions@github.com" | |
| git tag -a "${{ github.event.inputs.tag_name }}" -m "Release ${{ github.event.inputs.tag_name }}" | |
| git push origin "${{ github.event.inputs.tag_name }}" | |
| - uses: ncipollo/release-action@v1 | |
| with: | |
| artifacts: "*.apk" | |
| token: ${{ github.token }} | |
| tag: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.tag_name || github.ref_name }} | |
| generateReleaseNotes: true | |
| body: ${{ steps.release_notes.outputs.BODY }} | |
| # 手动触发时,如果标签已存在则跳过创建 | |
| skipIfReleaseExists: true |