release #16
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: | |
| workflow_dispatch: {} | |
| permissions: | |
| contents: write | |
| jobs: | |
| prepare: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| version: ${{ steps.compute.outputs.version }} | |
| major: ${{ steps.compute.outputs.major }} | |
| minor: ${{ steps.compute.outputs.minor }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Compute release version (patch = commits since last tag) | |
| id: compute | |
| shell: bash | |
| run: | | |
| pkg="apps/desktop/package.json" | |
| ver=$(jq -r '.version' "$pkg") | |
| IFS='.' read -r major minor patch <<<"$ver" | |
| base="v${major}.${minor}" | |
| git fetch --tags --force | |
| last_tag=$(git tag -l "${base}.*" --sort=-version:refname | head -n 1 || true) | |
| if [ -z "$last_tag" ]; then | |
| next_patch=0 | |
| echo "No previous tag for ${base}, using patch=0" | |
| else | |
| next_patch=$(git rev-list "${last_tag}..HEAD" --count) | |
| echo "Last tag: ${last_tag}, commits since tag: ${next_patch}" | |
| fi | |
| next="${major}.${minor}.${next_patch}" | |
| echo "version=$next" >> "$GITHUB_OUTPUT" | |
| echo "major=$major" >> "$GITHUB_OUTPUT" | |
| echo "minor=$minor" >> "$GITHUB_OUTPUT" | |
| echo "Next version: $next" | |
| build: | |
| needs: prepare | |
| strategy: | |
| matrix: | |
| os: [macos-latest, windows-latest] | |
| runs-on: ${{ matrix.os }} | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Setup pnpm | |
| uses: pnpm/action-setup@v4 | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "22" | |
| cache: "pnpm" | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build (tauri) | |
| working-directory: apps/desktop | |
| env: | |
| TAURI_BUILD_VERSION: ${{ needs.prepare.outputs.version }} | |
| VITE_APP_VERSION: ${{ needs.prepare.outputs.version }} | |
| TAURI_BUILD_NUMBER: ${{ github.run_number }} | |
| # 注释掉签名相关环境变量,因为还没有证书 | |
| # TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} | |
| # TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # 禁用签名以避免错误 | |
| TAURI_SKIP_SIGNING: true | |
| run: pnpm tauri build | |
| - name: Upload artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: bundle-${{ matrix.os }} | |
| path: | | |
| apps/desktop/src-tauri/target/release/bundle/**/* | |
| if-no-files-found: error | |
| release: | |
| needs: [prepare, build] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout (for metadata) | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Download macOS artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: bundle-macos-latest | |
| path: dist/macos | |
| - name: Download Windows artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: bundle-windows-latest | |
| path: dist/windows | |
| - name: Create release tag on HEAD | |
| env: | |
| VERSION: ${{ needs.prepare.outputs.version }} | |
| shell: bash | |
| run: | | |
| git fetch --tags --force | |
| # Preflight: avoid GitHub App restriction when the target commit introduces workflow changes | |
| base_ref=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@') | |
| git fetch origin "$base_ref" --quiet | |
| if git diff --name-only "origin/${base_ref}...HEAD" | grep -qE '^\.github/workflows/'; then | |
| echo "This commit changes .github/workflows. GITHUB_TOKEN cannot create tags on commits that introduce workflow changes." | |
| echo "Please push workflow changes first, then trigger release on a subsequent commit." | |
| exit 1 | |
| fi | |
| tag="v${VERSION}" | |
| if git rev-parse -q --verify "refs/tags/${tag}" >/dev/null; then | |
| echo "Tag ${tag} already exists. Aborting to avoid duplicate release." | |
| exit 1 | |
| fi | |
| echo "Creating tag ${tag} on HEAD" | |
| git tag "${tag}" | |
| git push origin "${tag}" | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v1 | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| with: | |
| tag_name: v${{ needs.prepare.outputs.version }} | |
| name: v${{ needs.prepare.outputs.version }} | |
| files: | | |
| dist/macos/**/*.dmg | |
| dist/macos/**/*.app | |
| dist/windows/**/*.exe | |
| dist/windows/**/*.msi |