name: Release

permissions:
  contents: write

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

defaults:
  run:
    shell: bash --noprofile --norc -CeEuo pipefail {0}

jobs:
  build:
    runs-on: windows-latest
    steps:
      - uses: actions/checkout@v4

      - name: Install Rust toolchain
        uses: dtolnay/rust-toolchain@stable
        with:
          targets: x86_64-pc-windows-msvc

      - name: Build release
        run: cargo build --release
        env:
          RUSTFLAGS: -C target-feature=+crt-static

      - name: Package release
        run: |
          cd target/release
          7z a -tzip ../../rcm-x86_64-pc-windows-msvc.zip rcm.exe rcm_com.dll

      - name: Publish Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref == 'refs/heads/main' && 'nightly' || github.ref_name }}
          name: ${{ github.ref == 'refs/heads/main' && 'Nightly Release' || github.ref_name }}
          files: rcm-x86_64-pc-windows-msvc.zip