name: Build macOS x86_64 Distributable

on:
  push:
    branches: [ master ]
  pull_request:
    branches: [ master ]

env:
  target_cpu: x86_64
  target_os: darwin
  target_flavour: opt

jobs:
  build:

    runs-on: macos-11.0
    
    steps:
    - uses: actions/checkout@v2
    - name: Fetch entire repository
      run: git fetch --prune --unshallow
    - name: Make
      run: make OPENMSX_TARGET_CPU=${{ env.target_cpu }} OPENMSX_TARGET_OS=${{ env.target_os }} OPENMSX_FLAVOUR=${{ env.target_flavour }} staticbindist
    - name: Determine version
      id: get_version
      run: |
        OPENMSX_VERSION=`python3 build/version.py`
        echo ::set-output name=OPENMSX_VERSION::$OPENMSX_VERSION
    - name: Rename redistributable dmg
      run: |
        cd derived/${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd
        mv openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-mac-${{ env.target_cpu }}-bin.dmg openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd.dmg
    - name: Upload redistributable dmg
      uses: actions/upload-artifact@v1
      with:
        name: openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd.dmg
        path: derived/${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd/openmsx-${{ steps.get_version.outputs.OPENMSX_VERSION }}-${{ env.target_cpu }}-${{ env.target_os }}-${{ env.target_flavour }}-3rd.dmg
