$if: '(event.event != "push") && (event.event != "tag")'
then:
  taskId: ${taskcluster.taskId}
  provisionerId: ${taskcluster.docker.provisionerId}
  workerType: ${build.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: '7 days' }

  extra:
    github:
      { $eval: taskcluster.github_events.pull_request }

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

    env:
      DEEPSPEECH_MODEL: "https://github.com/reuben/DeepSpeech/releases/download/v0.8.0/models_0.8.tar.gz"
      DEEPSPEECH_AUDIO: "https://github.com/mozilla/DeepSpeech/releases/download/v0.4.1/audio-0.4.1.tar.gz"
      PIP_DEFAULT_TIMEOUT: "60"
      EXAMPLES_CLONE_URL: "https://github.com/mozilla/STT-examples"
      EXAMPLES_CHECKOUT_TARGET: "r0.8"

    command:
      - "/bin/bash"
      - "--login"
      - "-cxe"
      - $let:
          extraSystemSetup: { $eval: strip(str(build.system_setup)) }
        in: >
          apt-get -qq update && apt-get -qq -y upgrade && apt-get -qq -y install git sox sudo && ${extraSystemSetup} &&
          adduser --system --home ${system.homedir.linux} ${system.username} &&
          cd ${system.homedir.linux} &&
          echo -e "#!/bin/bash\nset -xe\n env && id && mkdir ~/DeepSpeech/ && git clone --quiet $EXAMPLES_CLONE_URL ~/DeepSpeech/examples && cd ~/DeepSpeech/examples && git checkout --quiet $EXAMPLES_CHECKOUT_TARGET && git clone --quiet ${event.head.repo.url} ~/DeepSpeech/ds/ && cd ~/DeepSpeech/ds && git checkout --quiet ${event.head.sha} && wget -O - $DEEPSPEECH_MODEL | tar -C ~/DeepSpeech/ -xzvf - && wget -O - $DEEPSPEECH_AUDIO | tar -C ~/DeepSpeech/ -xzvf - " > /tmp/clone.sh && chmod +x /tmp/clone.sh &&
          sudo -H -u ${system.username} /bin/bash /tmp/clone.sh &&
          sudo -H -u ${system.username} --preserve-env /bin/bash ${build.args.tests_cmdline}

    artifacts:
      "public":
        type: "directory"
        path: "/tmp/artifacts/"
        expires: { $fromNow: '7 days' }

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