taskId: ${taskcluster.taskId}
provisionerId: ${taskcluster.generic.provisionerId}
workerType: ${taskcluster.generic.workerType}
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) }

  env:
    TENSORFLOW_BUILD_ARTIFACT: ${build.tensorflow}

  # There is no VM yet running tasks on OSX
  # so one should install by hand:
  # - brew
  # - Xcode 10.1 in /Applications/Xcode.app, then sudo chown -R root:wheel /Applications/Xcode.app
  # - brew install gnu-tar git pixz wget coreutils pyenv-virtualenv
  # - sudo easy_install pip

  command:
    - - "/bin/bash"
      - "--login"
      - "-cxe"
      - >
        export TASKCLUSTER_ARTIFACTS="$(pwd)/public/" &&
        export TASKCLUSTER_ORIG_TASKDIR="$(pwd)" &&
        (mkdir ../tc-workdir/ || rm -fr ../tc-workdir/*) && cd ../tc-workdir/ &&
        export TASKCLUSTER_TASK_DIR="$(pwd)" &&
        export LC_ALL=C &&
        export MACOSX_DEPLOYMENT_TARGET=10.10 &&
        export SDKROOT=/Library/Developer/CommandLineTools/SDKs/MacOSX10.14.sdk/ &&
        export HOMEBREW_NO_AUTO_UPDATE=1 &&
        env &&
        trap "export TASKCLUSTER_TASK_EXIT_CODE=$? &&
        cd $TASKCLUSTER_ORIG_TASKDIR/ && rm -fr $TASKCLUSTER_TASK_DIR/ &&
        exit $TASKCLUSTER_TASK_EXIT_CODE" 0 &&
        (pixz -d < $TASKCLUSTER_ORIG_TASKDIR/home.tar.xz | gtar -C $TASKCLUSTER_TASK_DIR -xf - ) &&
        cd $TASKCLUSTER_TASK_DIR/DeepSpeech/ds && git remote set-url origin ${event.head.repo.url} && git fetch origin && git checkout --quiet ${event.head.sha} &&
        git submodule --quiet sync tensorflow/ && git submodule --quiet update tensorflow/ &&
        cd $TASKCLUSTER_TASK_DIR &&
        (mkdir pyenv-root/ && gtar -C pyenv-root/ -xf $TASKCLUSTER_ORIG_TASKDIR/pyenv.tar.gz) &&
        (mkdir homebrew-builds/ && gtar -C homebrew-builds/ -xf $TASKCLUSTER_ORIG_TASKDIR/homebrew-builds.tar.gz) &&
        $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/${build.scripts.build} &&
        $TASKCLUSTER_TASK_DIR/DeepSpeech/ds/${build.scripts.package}

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

  mounts:
    - file: pyenv.tar.gz
      content:
        url: ${system.pyenv.osx.url}
    - file: homebrew-builds.tar.gz
      content:
        url: ${system.homebrew_builds.url}
    - directory: ${system.homedir.osx}/Library/Caches/node-gyp/
      format: tar.gz
      content:
        url: ${system.node_gyp_cache.url}
    - file: home.tar.xz
      content:
        url: ${build.tensorflow}

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