name: Publish

on:
  push:
    tags:
      - '*'

jobs:
  linux-gnu:
    runs-on: ubuntu-latest
    # Use a container with GLIBC 2.17
    container: quay.io/pypa/manylinux2014_x86_64
    steps:
      - name: Show GLIBC
        run: ldd --version

      - name: Checkout sources
        uses: actions/checkout@v2

      - name: Install stable toolchain
        uses: actions-rs/toolchain@v1
        with:
          profile: minimal
          toolchain: stable
          override: true

      - name: Build
        run: cargo build --verbose --release
      - name: Create tarball
        run: tar cvfz nwr.tar.gz target/release/nwr
        shell: bash
      - name: Upload binaries to releases
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: nwr.tar.gz
          asset_name: nwr-x86_64-unknown-linux-gnu.tar.gz
          tag: ${{ github.ref }}
  macos:
    runs-on: macOS-latest
    steps:
      - uses: hecrj/setup-rust-action@v1
        with:
          rust-version: stable
      - uses: actions/checkout@v1
      - name: Build
        env:
          MACOSX_DEPLOYMENT_TARGET: 10.12
        run: cargo build --verbose --release
      - name: Create tarball
        run: tar cvfz nwr.tar.gz target/release/nwr
        shell: bash
      - name: Upload binaries to releases
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: nwr.tar.gz
          asset_name: nwr-x86_64-apple-darwin.tar.gz
          tag: ${{ github.ref }}
  windows:
    runs-on: windows-latest
    steps:
      - uses: hecrj/setup-rust-action@v1
        with:
          rust-version: stable
      - uses: actions/checkout@v1
      - name: Enable static CRT linkage
        run: |
          mkdir .cargo
          echo '[target.x86_64-pc-windows-msvc]' >> .cargo/config
          echo 'rustflags = ["-Ctarget-feature=+crt-static"]' >> .cargo/config
      - name: Build
        run: cargo build --verbose --release
      - name: Create zip
        run: Compress-Archive -DestinationPath ./nwr.zip -Path ./target/release/nwr.exe
        shell: powershell
      - name: Upload binaries to releases
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: nwr.zip
          asset_name: nwr-x86_64-pc-windows-msvc.zip
          tag: ${{ github.ref }}
