compi 0.5.2

A build system written in Rust.
name: Release

on:
  push:
    tags:
      - "v*.*.*"

permissions:
  contents: write
  packages: write

jobs:
  create_release:
    runs-on: ubuntu-latest
    outputs:
      upload_url: ${{ steps.create_release.outputs.upload_url }}
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Create GitHub Release
        id: create_release
        uses: actions/create-release@v1
        with:
          tag_name: ${{ github.ref_name }}
          release_name: ${{ github.ref_name }}
          draft: false
          prerelease: false
          body: |
            **Full Changelog**: https://github.com/${{ github.repository }}/commits/${{ github.ref_name }}
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  build_and_upload:
    needs: create_release
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-latest, macos-latest, windows-latest]

    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Build release binary
        run: cargo build --release

      - name: Upload to GitHub Release
        uses: actions/upload-release-asset@v1
        with:
          upload_url: ${{ needs.create_release.outputs.upload_url }}
          asset_path: ${{ runner.os == 'Windows' && 'target/release/compi.exe' || 'target/release/compi' }}
          asset_name: ${{ runner.os == 'Windows' && 'compi-windows.exe' || runner.os == 'macOS' && 'compi-macos' || 'compi-linux' }}
          asset_content_type: application/octet-stream
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

  publish_crate:
    needs: build_and_upload
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v3

      - name: Set up Rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          override: true

      - name: Publish to crates.io
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
          CRATE_NAME: compi
          TAG: ${{ github.ref_name }}
        run: |
          printf '%s' "$CARGO_REGISTRY_TOKEN" | cargo login

          VERSION=${TAG#v}
          echo "Checking if $CRATE_NAME v$VERSION is already on crates.io…"
          if curl -s https://crates.io/api/v1/crates/$CRATE_NAME/versions \
               | jq -e --arg v "$VERSION" '.versions[] | select(.num == $v)' > /dev/null; then
            echo "$CRATE_NAME v$VERSION already exists on crates.io – skipping publish."
          else
            echo "Publishing $CRATE_NAME v$VERSION to crates.io…"
            cargo publish
          fi