winer 0.1.5

Helper library for Wine
Documentation
name: Test with Wine and Publish 

on:
  push:
    branches: [ main ]
    tags: ['v*']
  pull_request:
    branches: [ main ]
  workflow_dispatch:
    inputs:
      publish:
        description: 'Publish the package'
        required: false
        type: boolean
        default: false

jobs:
  linting:
    name: Linting
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          target: x86_64-pc-windows-gnu
          override: true
      - name: Linting (clippy)
        run: |
          cargo clippy --target x86_64-pc-windows-gnu -- -Dwarnings

  test:
    name: Test
    needs: linting
    runs-on: ubuntu-latest
    steps:
      - name: Checkout code
        uses: actions/checkout@v4

      - name: Configure system package manager
        run: |
          sudo dpkg --add-architecture i386
          sudo apt-get update

      - name: Install system dependencies
        run: |
          sudo apt-get install wine32:i386 wine64 mingw-w64

      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          target: x86_64-pc-windows-gnu
          override: true

      - name: Cache Rust dependencies
        uses: actions/cache@v4
        with:
          path: |
            ~/.cargo/bin/
            ~/.cargo/registry/index/
            ~/.cargo/registry/cache/
            ~/.cargo/git/db/
            target/
          key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.toml') }}

      - name: Build tests
        run: |
          cargo test --no-run --target x86_64-pc-windows-gnu
          cargo test --no-run --target x86_64-pc-windows-gnu --message-format=json > output.json

      - name: Extract test executable path
        id: extract-test-exe
        run: |
          TEST_EXE=$(jq -r 'select(.reason == "compiler-artifact" and .target.test and .executable) | .executable' output.json)
          echo "TEST_EXE=$TEST_EXE" >> $GITHUB_OUTPUT

      - name: Wine environment checks
        run: |
          WINE_BUILD=$(wine --version)
          WINE_VERSION=$(wine --version | grep -oE '[0-9]+\.[0-9]+' | head -n1)
          NAME=$(uname -s)
          RELEASE=$(uname -r)

          echo "WINER_TEST_VERSION=$WINE_VERSION" >> $GITHUB_ENV
          echo "WINER_TEST_BUILD=$WINE_BUILD" >> $GITHUB_ENV
          echo "WINER_TEST_SYSNAME=$NAME" >> $GITHUB_ENV
          echo "WINER_TEST_RELEASE=$RELEASE" >> $GITHUB_ENV

      - name: Run tests under Wine
        run: |
          wine ${{ steps.extract-test-exe.outputs.TEST_EXE }} --test-threads=1

  publish:
    name: Publish
    needs: test
    if: |
      github.event_name == 'workflow_dispatch' && github.event.inputs.publish == 'true' ||
      startsWith(github.ref, 'refs/tags/v')
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true
      - name: Publish to crates.io
        run: |
          cargo publish --package winer --no-verify
        env:
          CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}