s3-util 0.1.0

A command line utility for interacting with S3 compatible object stores
name: Rust

on:
  push:
    branches: [ main ]
    tags: [ 'v*' ]
  pull_request:
    branches: [ main ]

env:
  CARGO_TERM_COLOR: always

jobs:
  build:
    name: Build
    runs-on: ${{ matrix.os }}

    strategy:
      fail-fast: false
      matrix:
        include:
          - target: x86_64-unknown-linux-gnu
            os: ubuntu-latest
            output: s3-util
            archive: tgz
          - target: x86_64-apple-darwin
            os: macos-latest
            output: s3-util
            archive: tgz
          - target: armv7-unknown-linux-gnueabihf
            os: ubuntu-20.04
            output: s3-util
            archive: tgz
          - target: x86_64-pc-windows-msvc
            os: windows-latest
            output: s3-util.exe
            archive: zip

    steps:
    - uses: actions/checkout@v2
    - uses: FranzDiebold/github-env-vars-action@v1.2.1

    - name: Configure toolchain
      uses: actions-rs/toolchain@v1
      with:
        toolchain: nightly
        target:  ${{ matrix.target }}
        override: true

    - name: Configure caching
      uses: actions/cache@v2
      # Caching disabled on macos due to https://github.com/actions/cache/issues/403
      if: ${{ matrix.os != 'macos-latest' }}
      with:
        key: ${{ matrix.os }}-${{ matrix.target }}
        path: |
          ${{ env.HOME }}/.cargo"
          target

    - name: Install cross toolchain (armv7)
      if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
      run: sudo apt install gcc-arm-linux-gnueabihf

    - name: Enable cross compilation (armv7)
      if: ${{ matrix.target == 'armv7-unknown-linux-gnueabihf' }}
      run: |
        echo "PKG_CONFIG_ALLOW_CROSS=1" >> $GITHUB_ENV
        echo "LZMA_API_STATIC=1" >> $GITHUB_ENV

    - name: Build release
      uses: actions-rs/cargo@v1
      with:
        command: build
        args: --target ${{ matrix.target }} --release

    - name: Copy and rename utility
      run: |
        cp target/${{ matrix.target }}/release/${{ matrix.output }} ${{ matrix.output }}

    - name: Create archive (tgz)
      if: ${{ matrix.target != 'x86_64-pc-windows-msvc' }}
      run: tar -czvf s3-util-${{ matrix.target }}.tgz ${{ matrix.output }}
    
    - name: Create archive (zip)
      if: ${{ matrix.target == 'x86_64-pc-windows-msvc' }}
      run: tar.exe -a -c -f s3-util-${{ matrix.target }}.zip ${{ matrix.output }}

    - name: Upload artifacts
      uses: actions/upload-artifact@v1
      with:
        name: s3-util-${{ matrix.target }}.${{ matrix.archive }}
        path: s3-util-${{ matrix.target }}.${{ matrix.archive }}

    - name: Upload archives to release
      if: ${{ startsWith(github.ref, 'refs/tags/v') }}
      uses: svenstaro/upload-release-action@v2
      with:
        repo_token: ${{ secrets.GITHUB_TOKEN }}
        file: s3-util-${{ matrix.target }}.${{ matrix.archive }}
        asset_name: s3-util-${{ matrix.target }}.${{ matrix.archive }}
        tag: ${{ github.ref }}
        overwrite: true