ccgo 3.4.2

A high-performance C++ cross-platform build CLI
name: Release

on:
  push:
    tags:
      - 'v*.*.*'
  workflow_dispatch:
    inputs:
      tag:
        description: 'Release tag (e.g., v0.1.0)'
        required: false
        type: string

env:
  PACKAGE_NAME: ccgo
  CARGO_INCREMENTAL: 0
  CARGO_NET_RETRY: 10
  CARGO_TERM_COLOR: always
  RUSTUP_MAX_RETRIES: 10

permissions:
  contents: write
  id-token: write

jobs:
  # Build source distribution
  sdist:
    name: Build sdist
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build sdist
        uses: PyO3/maturin-action@v1
        with:
          command: sdist
          args: --out dist
      - name: Upload sdist
        uses: actions/upload-artifact@v4
        with:
          name: wheels-sdist
          path: dist

  # Build wheels for Linux
  linux:
    name: Build Linux ${{ matrix.target }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: ubuntu-latest
            target: x86_64
          - runner: ubuntu-24.04-arm
            target: aarch64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --locked --out dist
          manylinux: '2_17'
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-linux-${{ matrix.target }}
          path: dist
      - name: Archive binary
        run: |
          ARCH=${{ matrix.target }}
          if [ "$ARCH" = "x86_64" ]; then
            TARGET=x86_64-unknown-linux-gnu
          else
            TARGET=aarch64-unknown-linux-gnu
          fi
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }} $ARCHIVE_NAME/
          tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
          shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-linux-${{ matrix.target }}
          path: |
            *.tar.gz
            *.sha256

  # Build wheels for Windows
  windows:
    name: Build Windows x86_64
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: x86_64
          args: --release --locked --out dist
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-windows-x86_64
          path: dist
      - name: Archive binary
        shell: bash
        run: |
          TARGET=x86_64-pc-windows-msvc
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.zip

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }}.exe $ARCHIVE_NAME/
          7z a $ARCHIVE_FILE $ARCHIVE_NAME
          sha256sum $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-windows-x86_64
          path: |
            *.zip
            *.sha256

  # Build wheels for macOS
  macos:
    name: Build macOS ${{ matrix.target }}
    runs-on: ${{ matrix.runner }}
    strategy:
      fail-fast: false
      matrix:
        include:
          - runner: macos-15-intel
            target: x86_64
          - runner: macos-15
            target: aarch64
    steps:
      - uses: actions/checkout@v4
      - uses: actions/setup-python@v5
        with:
          python-version: '3.11'
      - name: Build wheels
        uses: PyO3/maturin-action@v1
        with:
          target: ${{ matrix.target }}
          args: --release --locked --out dist
      - name: Upload wheels
        uses: actions/upload-artifact@v4
        with:
          name: wheels-macos-${{ matrix.target }}
          path: dist
      - name: Archive binary
        run: |
          ARCH=${{ matrix.target }}
          if [ "$ARCH" = "x86_64" ]; then
            TARGET=x86_64-apple-darwin
          else
            TARGET=aarch64-apple-darwin
          fi
          ARCHIVE_NAME=${{ env.PACKAGE_NAME }}-$TARGET
          ARCHIVE_FILE=$ARCHIVE_NAME.tar.gz

          mkdir -p $ARCHIVE_NAME
          cp target/$TARGET/release/${{ env.PACKAGE_NAME }} $ARCHIVE_NAME/
          tar czvf $ARCHIVE_FILE $ARCHIVE_NAME
          shasum -a 256 $ARCHIVE_FILE > $ARCHIVE_FILE.sha256
      - name: Upload binary
        uses: actions/upload-artifact@v4
        with:
          name: binaries-macos-${{ matrix.target }}
          path: |
            *.tar.gz
            *.sha256

  # Create GitHub Release
  github-release:
    name: Create GitHub Release
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    steps:
      - uses: actions/checkout@v4
      - name: Download all binaries
        uses: actions/download-artifact@v4
        with:
          pattern: binaries-*
          path: binaries
          merge-multiple: true
      - name: Extract version
        id: version
        run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT
      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          files: binaries/*
          body: |
            ## Installation

            **Python Package (PyPI):**
            ```bash
            pip install ccgo==${{ steps.version.outputs.VERSION }}
            # or
            pip install --upgrade ccgo
            ```

            **Rust Binary (crates.io):**
            ```bash
            cargo install ccgo
            ```

            **Pre-built Binaries:**
            Download platform-specific binaries from the assets below.

            ## Quick Start

            ```bash
            # Create a new C++ cross-platform project
            ccgo new my-project

            # Build for different platforms
            cd my-project/<project_name>
            ccgo build android
            ccgo build ios
            ccgo build macos
            ccgo build linux
            ccgo build windows

            # Cross-platform builds using Docker
            ccgo build linux --docker
            ccgo build windows --docker
            ccgo build macos --docker
            ccgo build ios --docker
            ```

            See [CHANGELOG.md](https://github.com/zhlinh/ccgo/blob/main/CHANGELOG.md) for details.
          generate_release_notes: true
          draft: false
          prerelease: ${{ contains(github.ref, 'alpha') || contains(github.ref, 'beta') || contains(github.ref, 'rc') }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  # Publish to PyPI
  publish-pypi:
    name: Publish to PyPI
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    environment:
      name: release
    permissions:
      id-token: write
    steps:
      - name: Download all wheels
        uses: actions/download-artifact@v4
        with:
          pattern: wheels-*
          path: dist
          merge-multiple: true
      - name: Publish to PyPI
        uses: pypa/gh-action-pypi-publish@release/v1

  # Publish to crates.io
  publish-crates:
    name: Publish to crates.io
    runs-on: ubuntu-latest
    if: startsWith(github.ref, 'refs/tags/')
    needs: [sdist, linux, windows, macos]
    steps:
      - uses: actions/checkout@v4
      - uses: dtolnay/rust-toolchain@stable
      - name: Verify build
        run: cargo build --release --locked
      - name: Run tests
        run: cargo test --locked
      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
        run: cargo publish --locked