name: MacOS build

on:
  push:
    tags:
      - 'latest'
      - 'v*'
    branches-ignore:
      - master

jobs:
  macos-build:
    name: MacOS build
    runs-on: macos-latest

    steps:
      - uses: actions/checkout@v2
      - uses: actions/setup-node@v4
      - run: brew update
      - run: brew install sdl2 freetype zlib libpng gnu-sed
      - run: make -j 3 ARCH=macos
      - run: make -j 3 ARCH=macos unit_test
      - run: alias sed=gsed && make -j 3 e2e_test
      - run: make -j 3 ARCH=macos macos_bundle

      - name: Publish latest
        uses: softprops/action-gh-release@v2
        if: github.ref == 'refs/tags/latest'
        with:
          name: latest
          tag_name: latest
          message: Caprice32 latest
          body: Latest build of Caprice 32, with the newest cool features and the most recent bugs.
          files: |
            release/cap32-macos-bundle/Caprice32.dmg
            release/cap32-macos.zip
          fail_on_unmatched_files: true
          draft: false
          prerelease: false
          make_latest: true
          token: ${{ secrets.GITHUB_TOKEN }}

      - name: Publish release
        uses: softprops/action-gh-release@v2
        if: startsWith(github.ref, 'refs/tags/v')
        with:
          name: ${{ github.ref_name }}
          tag_name: ${{ github.ref_name }}
          message: Caprice32 ${{ github.ref }}
          body: Caprice32 ${{ github.ref }}. Release notes to be added manually.
          files: |
            release/cap32-macos-bundle/Caprice32.dmg
            release/cap32-macos.zip
          fail_on_unmatched_files: true
          draft: false
          prerelease: false
          make_latest: true
          token: ${{ secrets.GITHUB_TOKEN }}
