|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +#doc: provide help on how to trigger new CI build |
| 4 | + |
| 5 | +# posting a new commit from this script does not trigger CI checks |
| 6 | +# https://help.github.com/en/actions/reference/events-that-trigger-workflows#triggering-new-workflows-using-a-personal-access-token |
| 7 | + |
| 8 | +set -eu |
| 9 | + |
| 10 | +code='```' |
| 11 | + |
| 12 | +pr_url="$(jq -r '.issue.pull_request.url' "${GITHUB_EVENT_PATH}")" |
| 13 | +commenter="$(jq -r '.comment.user.login' "${GITHUB_EVENT_PATH}")" |
| 14 | +assoc="$(jq -r '.comment.author_association' "${GITHUB_EVENT_PATH}")" |
| 15 | + |
| 16 | +curl -LSs "${pr_url}" -o pull.tmp |
| 17 | +source_repo="$(jq -r '.head.repo.ssh_url' pull.tmp)" |
| 18 | +branch="$(jq -r '.head.ref' pull.tmp)" |
| 19 | +pr_owner="$(jq -r '.head.user.login' pull.tmp)" |
| 20 | +maintainer_can_modify="$(jq -r '.maintainer_can_modify' pull.tmp)" |
| 21 | + |
| 22 | +# PR owner |
| 23 | +# => |
| 24 | +# has local branch, can simply push |
| 25 | +if [[ "${commenter}" == "${pr_owner}" ]]; then |
| 26 | + cat <<-EOF |
| 27 | +To re-run CI checks, please follow these steps with the source branch checked out: |
| 28 | +${code} |
| 29 | +git commit --allow-empty -m 'trigger new CI check' |
| 30 | +git push |
| 31 | +${code} |
| 32 | +EOF |
| 33 | + |
| 34 | +# member AND modification allowed by PR author |
| 35 | +# OR |
| 36 | +# repo owner |
| 37 | +# => |
| 38 | +# include steps to fetch branch |
| 39 | +elif [[ "${maintainer_can_modify}" == "true" ]] && [[ "${assoc}" == "MEMBER" ]] || [[ "${assoc}" == "OWNER" ]]; then |
| 40 | + cat <<-EOF |
| 41 | +To re-run CI checks, please follow these steps: |
| 42 | +${code} |
| 43 | +git fetch "${source_repo}" "${branch}" |
| 44 | +git checkout FETCH_HEAD |
| 45 | +git commit --allow-empty -m 'trigger new CI check' |
| 46 | +git push "${source_repo}" HEAD:"${branch}" |
| 47 | +${code} |
| 48 | +EOF |
| 49 | + |
| 50 | +# other folks |
| 51 | +# => |
| 52 | +# ping author |
| 53 | +else |
| 54 | + cat <<-EOF |
| 55 | +@${pr_owner} please trigger new CI check by following these steps: |
| 56 | +${code} |
| 57 | +git commit --allow-empty -m 'trigger new CI check' |
| 58 | +git push |
| 59 | +${code} |
| 60 | +EOF |
| 61 | +fi |
0 commit comments