1#!/bin/sh
2
3set -xe
4
5REQUEST_CI_LABEL="request-ci"
6REQUEST_CI_FAILED_LABEL="request-ci-failed"
7
8for pr in "$@"; do
9  gh pr edit "$pr" --remove-label "$REQUEST_CI_LABEL"
10
11  ci_started=yes
12  rm -f output;
13  ncu-ci run "$pr" >output 2>&1 || ci_started=no
14  cat output
15
16  if [ "$ci_started" = "no" ]; then
17    # Do we need to reset?
18    gh pr edit "$pr" --add-label "$REQUEST_CI_FAILED_LABEL"
19
20    # shellcheck disable=SC2154
21    cqurl="${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
22    body="<details><summary>Failed to start CI</summary><pre>$(cat output)</pre><a href='$cqurl'>$cqurl</a></details>"
23    echo "$body"
24
25    gh pr comment "$pr" --body "$body"
26
27    rm output
28  fi
29done;
30