{% render "scripts/helper/templates/copyright-liquid.yml" %}

{% if platforms == "all" -%}
  {% assign platforms = "linux-x64,linux-ia32,linux-arm64,linux-arm,darwin-x64,darwin-arm64,win32-x64,win32-ia32" -%}
{% endif -%}
{% assign platforms = platforms | split: "," -%}

name: 'Build xPack {{ APP_NAME }} xbbmi'

on:
  workflow_dispatch:
    inputs:
      version:
        description: 'The semver of the release'
        required: false
        default: 'current'

jobs:
{% for platform in platforms -%}
{% if platform == "darwin-x64" %}
  macos-x64:
    name: 'macOS Intel - {{ APP_NAME }} {% raw %}${{ github.event.inputs.version }}{% endraw %} build'
    timeout-minutes: 2880 # 2 days
    runs-on: [self-hosted, macos, intel]
    steps:
      - name: 'Machine'
        run: uname -a

      - name: 'Checkout'
        uses: actions/checkout@v2
        with:
          fetch-depth: 3
          submodules: true

      - name: 'Clean working area'
        run: rm -rf ~/Work/{{ APP_LC_NAME }}-{% raw %}${{ github.event.inputs.version }}{% endraw %}*
{% for platform in platforms -%}
  {% case platform -%}
    {% when "darwin-x64" %}
      - name: 'Build macOS x64 binary'
        timeout-minutes: 1440
        run: bash scripts/helper/build.sh --version "{% raw %}${{ github.event.inputs.version }}{% endraw %}" --macos
  {% endcase -%}
{% endfor %}
      - name: 'Publish pre-release'
        # https://github.com/ncipollo/release-action
        uses: ncipollo/release-action@v1
        with:
          allowUpdates: true
          artifacts: '~/Work/{{ APP_LC_NAME }}-{% raw %}${{ github.event.inputs.version }}{% endraw %}/deploy/*'
          bodyFile: '.github/workflows/body-github-pre-releases-test.md'
          commit: 'master'
          draft: false
          name: 'Test binaries'
          omitBodyDuringUpdate: true
          omitNameDuringUpdate: true
          owner: 'xpack-dev-tools'
          prerelease: true
          replacesArtifacts: true
          repo: 'pre-releases'
          tag: 'test'
          token: {% raw %}${{ secrets.PUBLISH_TOKEN }}{% endraw %}
{% endif -%}
{% endfor %}
