name: macos

on:
  push:
    branches:
    - master
  pull_request:
    branches:
    - master


jobs:
  build:
    strategy:
      fail-fast: false
    runs-on: "macos-11.0"
    
    steps:
    - name: "checkout repo"
      uses: actions/checkout@v2
      with:
         submodules: "recursive"
    - name: "Fetch tags"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            git fetch --depth=1 origin +refs/tags/*:refs/tags/*
            

    - name: "Fetch tag/branch history"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            git fetch --prune --unshallow
            

    - name: "Install Rust"
      uses: actions-rs/toolchain@v1
      with:
         profile: "minimal"
         toolchain: "stable"
         override: true
         components: "rustfmt"
      env:
         ACTIONS_ALLOW_UNSECURE_COMMANDS: "true"
    - name: "Install Rust (ARM)"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            rustup target add aarch64-apple-darwin
            

    - name: "Install System Deps"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            ./get-deps
            

    - name: "Check formatting"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            cargo fmt --all -- --check
            

    - name: "Build (Release mode Intel)"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            cargo build --target x86_64-apple-darwin --all --release
            

    - name: "Build (Release mode ARM)"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            cargo build --target aarch64-apple-darwin --all --release
            

    - name: "Test (Release mode)"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            cargo test --target x86_64-apple-darwin --all --release
            

    - name: "Package"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            bash ci/deploy.sh
            

    - name: "Move Package for artifact upload"
      shell: bash
      run: |
            export MACOSX_DEPLOYMENT_TARGET=10.9
            mkdir pkg_
            mv *.zip pkg_
            
            

    - name: "Upload artifact"
      uses: actions/upload-artifact@master
      with:
         name: "macos"
         path: "pkg_"