name: Release

on:
  push:
    # Sequence of patterns matched against refs/tags
    tags:
      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

jobs:
  release_win64:
    name: Build and release Windows 64Bit
    runs-on: windows-latest

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

      - name: Build
        run: |
          cargo build --release
          Compress-Archive -LiteralPath target/release/odbc2parquet.exe -DestinationPath odbc2parquet-win64.zip

      - name: Github Upload
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: odbc2parquet-win64.zip
          asset_name: odbc2parquet-win64.zip
          tag: ${{ github.ref }}
  
  release_win32:
    name: Build and release Windows 32Bit
    runs-on: windows-latest

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

      - name: Install latests rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          target: i686-pc-windows-msvc
          default: true
          override: true

      - name: Build
        run: |
          cargo build --release
          Compress-Archive -LiteralPath target/release/odbc2parquet.exe -DestinationPath odbc2parquet-win32.zip

      - name: Github Upload
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: odbc2parquet-win32.zip
          asset_name: odbc2parquet-win32.zip
          tag: ${{ github.ref }}

  release_os-x:
    name: Build and release OS-X
    runs-on: macos-latest

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

      - name: Install latests rust toolchain
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          default: true
          override: true

      - name: Build
        run: cargo build --release

      - name: Github Upload
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: target/release/odbc2parquet
          asset_name: odbc2parquet-osx
          tag: ${{ github.ref }}

      - name: Publish to cargo
        env:
          CARGO_TOKEN: ${{ secrets.CRATES_IO_TOKEN }}
        run: |
          cargo publish --token "${CARGO_TOKEN}"

  ubuntu:
    name: Build and release for Ubuntu
    runs-on: ubuntu-latest

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

      - name: Build
        run: |
          cargo build --release
          gzip --force target/release/odbc2parquet
          mv target/release/odbc2parquet.gz odbc2parquet-x86_64-ubuntu.gz

      - name: Github Upload
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: odbc2parquet-x86_64-ubuntu.gz
          asset_name: odbc2parquet-x86_64-ubuntu.gz
          tag: ${{ github.ref }}