taskId: ${taskcluster.taskId}
provisionerId: ${taskcluster.generic.provisionerId}
workerType: ${build.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: { $fromNow: '6 months' }
scopes:
  - "index:insert-task:project.deepspeech.*"

payload:
  maxRunTime: { $eval: to_int(build.maxRunTime) }

  features:
    taskclusterProxy: true

  command:
    - - "/bin/bash"
      - "--login"
      - "-cxe"
      - $let:
          extraSystemSetup: { $eval: strip(str(build.system_setup)) }
          extraSystemConfig: { $eval: strip(str(build.system_config)) }
          taskIndexExpire: { $fromNow: '6 months' }
        in: >
          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 &&
          env &&
          mkdir -p $TASKCLUSTER_ARTIFACTS/ &&
          cache_artifact=`curl -sSIL -o /dev/null -w "%{http_code}" ${build.cache.artifact_url}` &&
          if [ "$cache_artifact" != "200" ]; then
            git clone --quiet ${build.build_or_cache.repo} $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir} &&
            cd $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir} && git checkout --quiet ${build.build_or_cache.sha} &&
            ${extraSystemConfig} &&
            $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir}/${build.scripts.setup} &&
            $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir}/${build.scripts.build} &&
            $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir}/${build.scripts.package} &&
            $TASKCLUSTER_TASK_DIR/${build.build_or_cache.dir}/taskcluster/tc-update-index.sh ${taskIndexExpire} 127.0.0.1:8080 ${build.cache.artifact_namespace}
          fi;

  artifacts:
    - type: "directory"
      path: "public/"
      expires: { $fromNow: '6 months' }

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