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

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

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

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

jobs:
{% for platform in platforms -%}
{% if platform == "linux-arm64" %}
  linux-arm64:
    name: 'Linux Arm 64 - {{ APP_NAME }} {% raw %}${{ github.event.inputs.version }}{% endraw %} build'
    timeout-minutes: 2880 # 2 days
    runs-on: [self-hosted, linux, arm64, xbbla64]
    steps:
      - name: 'Machine'
        run: |
          uname -a
          node --version
          npm --version

      - 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 %}*
      - name: 'Build Linux arm64 binary'
        timeout-minutes: 1440
        run: bash scripts/helper/build.sh --version "{% raw %}${{ github.event.inputs.version }}{% endraw %}" --arm64

      - 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
          omitDraftDuringUpdate: true
          omitNameDuringUpdate: true
          owner: 'xpack-dev-tools'
          prerelease: true
          replacesArtifacts: true
          repo: 'pre-releases'
          tag: 'test'
          token: {% raw %}${{ secrets.PUBLISH_TOKEN }}{% endraw %}
{% break -%}
{% endif -%}
{% endfor %}
