asar-rust 0.1.0

Rust port of @electron/asar — create and extract Electron ASAR archives
Documentation
name: Release

on:
  push:
    tags:
      - "v[0-9]+.[0-9]+.[0-9]+*"

permissions:
  contents: write

jobs:
  # ── 生成 changelog ──────────────────────────────────────────────
  changelog:
    runs-on: ubuntu-latest
    outputs:
      body: ${{ steps.cliff.outputs.content }}
    steps:
      - uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Generate changelog
        id: cliff
        uses: orhun/git-cliff-action@v4
        with:
          config: cliff.toml
          args: --latest --strip all
        env:
          OUTPUT: CHANGELOG.md

  # ── 多平台编译 ──────────────────────────────────────────────────
  build:
    needs: changelog
    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            suffix: linux-x64
          - target: x86_64-apple-darwin
            os: macos-latest
            suffix: macos-x64
          - target: aarch64-apple-darwin
            os: macos-latest
            suffix: macos-arm64
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            suffix: windows-x64
    runs-on: ${{ matrix.os }}
    steps:
      - uses: actions/checkout@v6

      - uses: dtolnay/rust-toolchain@stable
        with:
          targets: ${{ matrix.target }}

      - name: Build
        run: cargo build --release --target ${{ matrix.target }}

      - name: Package (Unix)
        if: runner.os != 'Windows'
        run: |
          cd target/${{ matrix.target }}/release
          tar czf ../../../asar-${{ matrix.suffix }}.tar.gz asar

      - name: Package (Windows)
        if: runner.os == 'Windows'
        run: |
          cd target/${{ matrix.target }}/release
          7z a ../../../asar-${{ matrix.suffix }}.zip asar.exe

      - uses: actions/upload-artifact@v7
        with:
          name: asar-${{ matrix.suffix }}
          path: asar-${{ matrix.suffix }}.*

  # ── 发布到 crates.io ───────────────────────────────────────────
  publish:
    needs: build
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - uses: dtolnay/rust-toolchain@stable

      - name: Verify version matches tag
        run: |
          TAG_VERSION="${GITHUB_REF_NAME#v}"
          CARGO_VERSION=$(cargo metadata --format-version=1 --no-deps | jq -r '.packages[0].version')
          if [ "$TAG_VERSION" != "$CARGO_VERSION" ]; then
            echo "Tag version ($TAG_VERSION) != Cargo.toml version ($CARGO_VERSION)"
            exit 1
          fi

      - name: Publish to crates.io
        run: cargo publish --token "${{ secrets.CARGO_REGISTRY_TOKEN }}"

  # ── 创建 GitHub Release ────────────────────────────────────────
  release:
    needs: [ changelog, build, publish ]
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v6

      - uses: actions/download-artifact@v8
        with:
          pattern: asar-*
          merge-multiple: true
          path: dist

      - name: List artifacts
        run: ls -lh dist/

      - name: Create GitHub Release
        uses: softprops/action-gh-release@v3
        with:
          name: ${{ github.ref_name }}
          body: ${{ needs.changelog.outputs.body }}
          files: dist/*
          draft: false
          prerelease: ${{ contains(github.ref_name, '-') }}
          generate_release_notes: false