name: pyinstaller

on:
  workflow_run:
    workflows:
      - main
    branches:
      - master
    types:
      - completed

jobs:

  # runs on x86-64 (xeon-d) host: matterhorn
  exe_amd64:
    runs-on: [self-hosted, linux, X64]

    if: github.ref == 'refs/heads/master'

    env:
      AWS_DEFAULT_REGION: eu-central-1
      AWS_S3_BUCKET_NAME: download.crossbario.com
      AWS_ACCESS_KEY_ID:     ${{ secrets.AWS_ACCESS_KEY_ID }}
      AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}

    steps:
    - uses: actions/checkout@v2

    - name: Set up Python 3.x
      uses: actions/setup-python@v2
      with:
        python-version: '3.x'
        architecture: 'x64'

    # curl -sSL https://bootstrap.pypa.io/get-pip.py -o get-pip.py
    # python3 get-pip.py "pip<20"
    # => fails with https://github.com/pypa/setuptools/issues/3044
    - name: Install Python package dependencies
      run: |
        pip3 install -U pip
        pip3 show pip
        pip3 install -r requirements-dev.txt

    - name: Set environment
      run: |
        echo AUTOBAHN_BUILD_DATE=`date -u +"%Y-%m-%d"` >> $GITHUB_ENV
        echo AUTOBAHN_BUILD_ID=$(date --utc +%Y%m%d)-$(git rev-parse --short ${GITHUB_SHA}) >> $GITHUB_ENV
        echo AUTOBAHN_VCS_REF=`git rev-parse --short ${GITHUB_SHA}` >> $GITHUB_ENV
        echo AUTOBAHN_VERSION=$(grep -E '^(__version__)' ./autobahn/_version.py | cut -d ' ' -f3 | sed -e 's|[u"'\'']||g') >> $GITHUB_ENV
        echo XBRNETWORK_EXE_FILENAME="xbrnetwork-linux-amd64-$(date --utc +%Y%m%d)-$(git rev-parse --short ${GITHUB_SHA})" >> $GITHUB_ENV

    - name: Print environment
      run: |
        echo ""
        echo "Build environment configured:"
        echo ""
        echo "  AUTOBAHN_BUILD_DATE     = ${AUTOBAHN_BUILD_DATE}"
        echo "  AUTOBAHN_BUILD_ID       = ${AUTOBAHN_BUILD_ID}"
        echo "  AUTOBAHN_VCS_REF        = ${AUTOBAHN_VCS_REF}"
        echo "  AUTOBAHN_VERSION        = ${AUTOBAHN_VERSION}"
        echo ""
        echo "  XBRNETWORK_EXE_FILENAME = ${XBRNETWORK_EXE_FILENAME}"
        echo ""
        echo "  AWS_DEFAULT_REGION      = ${AWS_DEFAULT_REGION}"
        echo "  AWS_S3_BUCKET_NAME      = ${AWS_S3_BUCKET_NAME}"
        echo ""

    - name: Install this package
      run: |
        pip3 install .[all]

    - name: Build & publish EXE
      run: |
        make build_exe
        make upload_exe
