name: Publish

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

jobs:
  publish:
    name: Publish for ${{ matrix.target }}
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        include:
          - os: ubuntu-latest
            artifact_name: oha
            release_name: oha-linux-amd64
            target: x86_64-unknown-linux-musl
          - os: windows-latest
            artifact_name: oha.exe
            release_name: oha-windows-amd64.exe
            target: x86_64-pc-windows-msvc
          - os: macos-latest
            artifact_name: oha
            release_name: oha-macos-amd64
            target: x86_64-apple-darwin
          - os: ubuntu-latest
            artifact_name: oha
            release_name: oha-linux-arm64
            target: aarch64-unknown-linux-musl
          - os: macos-latest
            artifact_name: oha
            release_name: oha-macos-arm64
            target: aarch64-apple-darwin

    steps:
      - uses: actions/checkout@v1
      - name: Install rust
        uses: actions-rs/toolchain@v1
        with:
          toolchain: stable
          profile: minimal
          override: true
          target: ${{ matrix.target }}
      - name: Build target
        uses: actions-rs/cargo@v1
        with:
          use-cross: true
          command: build
          args: --release --target ${{ matrix.target }} --locked --no-default-features --features rustls
      - uses: svenstaro/upx-action@v2
        if: matrix.target != 'aarch64-unknown-linux-musl'
        with:
          file: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
      - name: Upload binaries to release
        uses: svenstaro/upload-release-action@v1-release
        with:
          repo_token: ${{ secrets.GITHUB_TOKEN }}
          file: target/${{ matrix.target }}/release/${{ matrix.artifact_name }}
          asset_name: ${{ matrix.release_name }}
          tag: ${{ github.ref }}
