feat: improve release workflow with enhanced tag handling and clearer input descriptions

This commit is contained in:
2026-05-26 19:39:35 +08:00
parent 2a9c918711
commit b66c846956

View File

@@ -7,22 +7,18 @@ on:
workflow_dispatch: workflow_dispatch:
inputs: inputs:
tag: tag:
description: "Tag (or branch) to build" description: "Tag to build (e.g. v0.6.7)"
required: true required: true
run_notes:
description: "Generate release notes"
type: boolean
default: true
run_linux: run_linux:
description: "Build Linux (x86_64 + aarch64 + musl)" description: "Build Linux"
type: boolean type: boolean
default: true default: true
run_macos: run_macos:
description: "Build macOS (x86_64 + aarch64)" description: "Build macOS"
type: boolean type: boolean
default: true default: true
run_windows: run_windows:
description: "Build Windows (MSVC + GNU)" description: "Build Windows"
type: boolean type: boolean
default: true default: true
run_publish: run_publish:
@@ -34,23 +30,42 @@ permissions:
contents: write contents: write
jobs: jobs:
# ── Resolve Tag ────────────────────────────────────────────────────────────
setup:
runs-on: ubuntu-latest
outputs:
tag: ${{ steps.tag.outputs.value }}
version: ${{ steps.tag.outputs.version }}
prerelease: ${{ steps.tag.outputs.prerelease }}
steps:
- name: Resolve tag
id: tag
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then
TAG="${{ github.event.inputs.tag }}"
else
TAG="${GITHUB_REF_NAME}"
fi
VERSION="${TAG#v}"
[[ "$TAG" == *"-"* ]] && PRERELEASE="true" || PRERELEASE="false"
echo "value=${TAG}" >> "$GITHUB_OUTPUT"
echo "version=${VERSION}" >> "$GITHUB_OUTPUT"
echo "prerelease=${PRERELEASE}" >> "$GITHUB_OUTPUT"
# ── Release Notes ──────────────────────────────────────────────────────────
notes: notes:
needs: setup
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.inputs.tag || github.ref }} ref: ${{ needs.setup.outputs.tag }}
- name: Prepare Release Notes - name: Prepare Release Notes
shell: bash shell: bash
run: | run: |
set -euo pipefail set -euo pipefail
if [[ "${{ github.event_name }}" == "workflow_dispatch" ]]; then tag="${{ needs.setup.outputs.version }}"
tag="${{ github.event.inputs.tag }}"
tag="${tag#v}"
else
tag="${GITHUB_REF_NAME#v}"
fi
notes_file=".github/release-notes.md" notes_file=".github/release-notes.md"
if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then if grep -q "^## \\[${tag}\\]" CHANGELOG.md; then
awk -v ver="$tag" ' awk -v ver="$tag" '
@@ -72,7 +87,7 @@ jobs:
# ── Linux ────────────────────────────────────────────────────────────────── # ── Linux ──────────────────────────────────────────────────────────────────
build-linux: build-linux:
if: ${{ github.event_name == 'push' || github.event.inputs.run_linux == 'true' }} if: ${{ github.event_name == 'push' || github.event.inputs.run_linux == 'true' }}
needs: notes needs: [setup, notes]
runs-on: ubuntu-latest runs-on: ubuntu-latest
strategy: strategy:
fail-fast: false fail-fast: false
@@ -85,7 +100,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.inputs.tag || github.ref }} ref: ${{ needs.setup.outputs.tag }}
- name: Download Release Notes - name: Download Release Notes
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -111,28 +126,24 @@ jobs:
cargo build --release --target ${{ matrix.target }} cargo build --release --target ${{ matrix.target }}
fi fi
- name: Derive version & asset name
run: |
RAW_TAG="${{ github.event.inputs.tag || github.ref_name }}"
echo "RELEASE_TAG=${RAW_TAG}" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=${RAW_TAG#v}" >> "$GITHUB_ENV"
echo "ASSET_NAME=dcr-${{ matrix.target }}-${RAW_TAG#v}" >> "$GITHUB_ENV"
- name: Prepare Artifact - name: Prepare Artifact
run: cp target/${{ matrix.target }}/release/dcr "$ASSET_NAME" run: |
ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
cp target/${{ matrix.target }}/release/dcr "$ASSET"
echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"
- name: Upload Release Asset - name: Upload Release Asset
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ env.RELEASE_TAG }} tag_name: ${{ needs.setup.outputs.tag }}
files: ${{ env.ASSET_NAME }} files: ${{ env.ASSET_NAME }}
body_path: .github/release-notes.md body_path: .github/release-notes.md
prerelease: ${{ contains(env.RELEASE_TAG, '-') }} prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
# ── macOS ────────────────────────────────────────────────────────────────── # ── macOS ──────────────────────────────────────────────────────────────────
build-macos: build-macos:
if: ${{ github.event_name == 'push' || github.event.inputs.run_macos == 'true' }} if: ${{ github.event_name == 'push' || github.event.inputs.run_macos == 'true' }}
needs: notes needs: [setup, notes]
strategy: strategy:
fail-fast: false fail-fast: false
matrix: matrix:
@@ -145,7 +156,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.inputs.tag || github.ref }} ref: ${{ needs.setup.outputs.tag }}
- name: Download Release Notes - name: Download Release Notes
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -161,28 +172,24 @@ jobs:
- name: Build - name: Build
run: cargo build --release --target ${{ matrix.target }} run: cargo build --release --target ${{ matrix.target }}
- name: Derive version & asset name
run: |
RAW_TAG="${{ github.event.inputs.tag || github.ref_name }}"
echo "RELEASE_TAG=${RAW_TAG}" >> "$GITHUB_ENV"
echo "RELEASE_VERSION=${RAW_TAG#v}" >> "$GITHUB_ENV"
echo "ASSET_NAME=dcr-${{ matrix.target }}-${RAW_TAG#v}" >> "$GITHUB_ENV"
- name: Prepare Artifact - name: Prepare Artifact
run: cp target/${{ matrix.target }}/release/dcr "$ASSET_NAME" run: |
ASSET="dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}"
cp target/${{ matrix.target }}/release/dcr "$ASSET"
echo "ASSET_NAME=${ASSET}" >> "$GITHUB_ENV"
- name: Upload Release Asset - name: Upload Release Asset
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ env.RELEASE_TAG }} tag_name: ${{ needs.setup.outputs.tag }}
files: ${{ env.ASSET_NAME }} files: ${{ env.ASSET_NAME }}
body_path: .github/release-notes.md body_path: .github/release-notes.md
prerelease: ${{ contains(env.RELEASE_TAG, '-') }} prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
# ── Windows ──────────────────────────────────────────────────────────────── # ── Windows ────────────────────────────────────────────────────────────────
build-windows: build-windows:
if: ${{ github.event_name == 'push' || github.event.inputs.run_windows == 'true' }} if: ${{ github.event_name == 'push' || github.event.inputs.run_windows == 'true' }}
needs: notes needs: [setup, notes]
runs-on: windows-latest runs-on: windows-latest
strategy: strategy:
fail-fast: false fail-fast: false
@@ -194,7 +201,7 @@ jobs:
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.inputs.tag || github.ref }} ref: ${{ needs.setup.outputs.tag }}
- name: Download Release Notes - name: Download Release Notes
uses: actions/download-artifact@v4 uses: actions/download-artifact@v4
@@ -210,36 +217,32 @@ jobs:
- name: Build - name: Build
run: cargo build --release --target ${{ matrix.target }} run: cargo build --release --target ${{ matrix.target }}
- name: Derive version & asset name
shell: pwsh
run: |
$raw = "${{ github.event.inputs.tag || github.ref_name }}"
$ver = $raw -replace '^v', ''
"RELEASE_TAG=$raw" >> $env:GITHUB_ENV
"RELEASE_VERSION=$ver" >> $env:GITHUB_ENV
"ASSET_NAME=dcr-${{ matrix.target }}-${ver}.exe" >> $env:GITHUB_ENV
- name: Prepare Artifact - name: Prepare Artifact
shell: pwsh shell: pwsh
run: Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$env:ASSET_NAME" run: |
$asset = "dcr-${{ matrix.target }}-${{ needs.setup.outputs.version }}.exe"
Copy-Item "target/${{ matrix.target }}/release/dcr.exe" "$asset"
"ASSET_NAME=$asset" >> $env:GITHUB_ENV
- name: Upload Release Asset - name: Upload Release Asset
uses: softprops/action-gh-release@v2 uses: softprops/action-gh-release@v2
with: with:
tag_name: ${{ env.RELEASE_TAG }} tag_name: ${{ needs.setup.outputs.tag }}
files: ${{ env.ASSET_NAME }} files: ${{ env.ASSET_NAME }}
body_path: .github/release-notes.md body_path: .github/release-notes.md
prerelease: ${{ contains(env.RELEASE_TAG, '-') }} prerelease: ${{ needs.setup.outputs.prerelease == 'true' }}
# ── crates.io ────────────────────────────────────────────────────────────── # ── crates.io ──────────────────────────────────────────────────────────────
publish-crates: publish-crates:
if: ${{ (github.event_name == 'push' || github.event.inputs.run_publish == 'true') && !contains(github.event.inputs.tag || github.ref_name, '-') }} if: |
needs: notes (github.event_name == 'push' && needs.setup.outputs.prerelease == 'false') ||
(github.event_name == 'workflow_dispatch' && github.event.inputs.run_publish == 'true')
needs: [setup, build-linux, build-macos, build-windows]
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v4 - uses: actions/checkout@v4
with: with:
ref: ${{ github.event.inputs.tag || github.ref }} ref: ${{ needs.setup.outputs.tag }}
- uses: dtolnay/rust-toolchain@stable - uses: dtolnay/rust-toolchain@stable