jxcape 0.3.1

A command line tool for creating JSON values
Documentation
name: Release

on:
  push:
    tags:
      - 'v*'

env:
  CARGO_TERM_COLOR: always

jobs:
  build-and-release:
    name: Build and Release
    permissions:
      contents: read
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            target: x86_64-unknown-linux-gnu
            binary_name: jxcape
            asset_name: jxcape-linux-x86_64.tar.gz
          - os: macos-latest
            target: x86_64-apple-darwin
            binary_name: jxcape
            asset_name: jxcape-macos-x86_64.tar.gz
          - os: macos-latest
            target: aarch64-apple-darwin
            binary_name: jxcape
            asset_name: jxcape-macos-aarch64.tar.gz
          - os: windows-latest
            target: x86_64-pc-windows-msvc
            binary_name: jxcape.exe
            asset_name: jxcape-windows-x86_64.zip

    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0  # Fetch full history for changelog generation

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable
          target: ${{ matrix.target }}

      - name: Install git-cliff
        uses: taiki-e/install-action@v2
        with:
          tool: git-cliff@2.10.0

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

      - name: Run tests
        run: cargo test --target ${{ matrix.target }}

      - name: Create asset (Unix)
        if: runner.os != 'Windows'
        run: |
          mkdir -p release
          cp target/${{ matrix.target }}/release/${{ matrix.binary_name }} release/
          cp LICENSE README.md CHANGELOG.md release/
          cd release
          tar -czf ../${{ matrix.asset_name }} *

      - name: Create asset (Windows)
        if: runner.os == 'Windows'
        run: |
          mkdir release
          copy target\${{ matrix.target }}\release\${{ matrix.binary_name }} release\
          copy LICENSE release\
          copy README.md release\
          copy CHANGELOG.md release\
          cd release
          7z a ..\${{ matrix.asset_name }} *

      - name: Upload asset
        uses: actions/upload-artifact@v7
        with:
          name: ${{ matrix.asset_name }}
          path: ${{ matrix.asset_name }}

  create-release:
    name: Create Release
    permissions:
      contents: write
    needs: build-and-release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6
        with:
          fetch-depth: 0

      - name: Install git-cliff
        uses: taiki-e/install-action@v2
        with:
          tool: git-cliff@2.10.0

      - name: Generate changelog for this version
        run: |
          # Extract version from tag
          VERSION=${GITHUB_REF#refs/tags/}
          echo "VERSION=$VERSION" >> $GITHUB_ENV

          # Generate changelog for just this version
          git-cliff --latest --strip header > RELEASE_CHANGELOG.md

      - name: Download all assets
        uses: actions/download-artifact@v8
        with:
          path: assets

      - name: Move assets to root
        run: |
          find assets -type f \( -name "*.tar.gz" -o -name "*.zip" \) -exec mv {} . \;

      - name: Create Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ env.VERSION }}
          name: Release ${{ env.VERSION }}
          body_path: RELEASE_CHANGELOG.md
          files: |
            *.tar.gz
            *.zip
          draft: false
          prerelease: false
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish-to-crates-io:
    name: Publish to Crates.io
    permissions:
      contents: read
    needs: create-release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Setup Rust
        uses: actions-rust-lang/setup-rust-toolchain@v1
        with:
          toolchain: stable

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