taskId: ${taskcluster.taskId}
provisionerId: ${taskcluster.docker.provisionerId}
workerType: ${taskcluster.docker.workerTypeWin}
taskGroupId: ${taskcluster.taskGroupId}
schedulerId: ${taskcluster.schedulerId}
dependencies:
  $map: { $eval: build.dependencies }
  each(b):
    $eval: as_slugid(b)
created: { $fromNow: '0 sec' }
deadline: { $fromNow: '1 day' }
expires:
  $if: '(event.event == "push") || (event.event == "tag")'
  then: { $fromNow: '6 months' }
  else: { $fromNow: '7 days' }

extra:
  nc_asset_name: { $eval: build.nc_asset_name }
  github:
    $if: '(event.event == "push") || (event.event == "tag")'
    then: { $eval: taskcluster.github_events.merge }
    else: { $eval: taskcluster.github_events.pull_request }

routes:
  $if: '(event.event == "push") || (event.event == "tag")'
  then:
    { $eval: build.routes }

payload:
  maxRunTime: { $eval: to_int(build.maxRunTime) }
  mounts:
    - file: msys2-base-x86_64.tar.xz
      content:
        sha256: 4e799b5c3efcf9efcb84923656b7bcff16f75a666911abd6620ea8e5e1e9870c
        url: >-
          https://sourceforge.net/projects/msys2/files/Base/x86_64/msys2-base-x86_64-20180531.tar.xz/download

  env:
    $let:
      training: { $eval: as_slugid("test-training_upstream-linux-amd64-py27mu-opt") }
    in:
      TC_MSYS_VERSION: 'MSYS_NT-6.3'
      MSYS: 'winsymlinks:nativestrict'
      TENSORFLOW_BUILD_ARTIFACT: ${build.tensorflow}
      DEEPSPEECH_TEST_MODEL: https://queue.taskcluster.net/v1/task/${training}/artifacts/public/output_graph.pb

  command:
    - >-
      "C:\Program Files\7-zip\7z.exe" x -txz -so msys2-base-x86_64.tar.xz |
      "C:\Program Files\7-zip\7z.exe" x -o%USERPROFILE% -ttar -aoa -si
    - .\msys64\usr\bin\bash.exe --login -cx "exit"
    - .\msys64\usr\bin\bash.exe --login -cx "pacman --noconfirm -Syu"
    - echo .\msys64\usr\bin\bash.exe --login -cxe "
      export LC_ALL=C &&
      export PATH=\"/c/builds/tc-workdir/msys64/usr/bin:/c/Python36:/c/Program Files/Git/bin:/c/Program Files/7-Zip/:$PATH\" &&
      export TASKCLUSTER_ARTIFACTS=\"$USERPROFILE/public\" &&
      export TASKCLUSTER_TASK_DIR=\"/c/builds/tc-workdir/\" &&
      (mkdir $TASKCLUSTER_TASK_DIR || rm -fr $TASKCLUSTER_TASK_DIR/*) && cd $TASKCLUSTER_TASK_DIR &&
      env &&
      ln -s $USERPROFILE/msys64 $TASKCLUSTER_TASK_DIR/msys64 &&
      (wget -O - $TENSORFLOW_BUILD_ARTIFACT | 7z x -txz -si -so | 7z x -o$TASKCLUSTER_TASK_DIR -aoa -ttar -si ) &&
      git clone --quiet ${event.head.repo.url} $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/ &&
      cd $TASKCLUSTER_TASK_DIR/DeepSpeech/ds && git checkout --quiet ${event.head.sha} &&
      ln -s $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/native_client/ $TASKCLUSTER_TASK_DIR/DeepSpeech/tf/native_client &&
      cd $TASKCLUSTER_TASK_DIR &&
      pacman --noconfirm -R bsdtar &&
      pacman --noconfirm -S tar make &&
      (pacman --noconfirm -S patch swig &&
        (for patch_file in $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/native_client/swig_node_v7x-v8x-v9x_*.patch $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/native_client/swig_node_v10.12.patch $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/native_client/swig_node_v12_*.patch ; do patch -d /usr/share/swig/3.0.12/ -p2 < $patch_file; done)
      ) &&
      $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/${build.scripts.build} &&
      $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/${build.scripts.package} ;
      echo \"export TASKCLUSTER_TASK_EXIT_CODE=$?\" > $USERPROFILE/tc-exit.sh &&
      cd $TASKCLUSTER_TASK_DIR/../ && rm -fr tc-workdir/ && exit $TASKCLUSTER_TASK_EXIT_CODE" | cmd
      /k ""C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\vcvarsall.bat"" x64

    - .\msys64\usr\bin\bash.exe --login -cxe "source $USERPROFILE/tc-exit.sh &&
      exit $TASKCLUSTER_TASK_EXIT_CODE"

  artifacts:
    - type: "directory"
      path: "public/"
      expires:
        $if: '(event.event == "push") || (event.event == "tag")'
        then: { $fromNow: '6 months' }
        else: { $fromNow: '7 days' }

metadata:
  name: ${build.metadata.name}
  description: ${build.metadata.description}
  owner: ${event.head.user.email}
  source: ${event.head.repo.url}
