You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2022/03/23 14:54:24 UTC
[pulsar-test-infra] branch master updated: Use the new GitHub API to re-run failed jobs
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-test-infra.git
The following commit(s) were added to refs/heads/master by this push:
new bb9a0de Use the new GitHub API to re-run failed jobs
bb9a0de is described below
commit bb9a0deb2e1fa2ede7ba38589275e70a3563eb7b
Author: Lari Hotari <la...@hotari.net>
AuthorDate: Wed Mar 23 16:43:06 2022 +0200
Use the new GitHub API to re-run failed jobs
- instead of re-running all jobs in a failed workflow, re-run only the failed jobs
- API reference:
https://docs.github.com/en/rest/reference/actions#re-run-failed-jobs-from-a-workflow-run
- Feature description and UI reference:
https://docs.github.com/en/actions/managing-workflow-runs/re-running-workflows-and-jobs#re-running-failed-jobs-in-a-workflow
---
pulsarbot/entrypoint.sh | 43 ++++++++++++++++++++++++++++---------------
1 file changed, 28 insertions(+), 15 deletions(-)
diff --git a/pulsarbot/entrypoint.sh b/pulsarbot/entrypoint.sh
index 6df6374..fa9d36b 100755
--- a/pulsarbot/entrypoint.sh
+++ b/pulsarbot/entrypoint.sh
@@ -37,25 +37,38 @@ fi
PR_NUM=$(jq -r '.issue.number' "${GITHUB_EVENT_PATH}")
+function github_get() {
+ path="$1"
+ github_client "https://api.github.com/repos/${BOT_TARGET_REPOSITORY}${path}"
+}
+
+function github_client() {
+ curl -s -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.v3+json" "$@"
+}
+
# get head sha
-curl -s -H "Accept: application/vnd.github.antiope-preview+json" "https://api.github.com/repos/${BOT_TARGET_REPOSITORY}/git/ref/pull/${PR_NUM}/head" > result-headsha.txt
-HEAD_SHA=$(jq -r '.object.sha' result-headsha.txt)
+PR_JSON="$(github_get "/pulls/${PR_NUM}")"
+HEAD_SHA=$(printf "%s" "${PR_JSON}" | jq -r .head.sha)
+PR_BRANCH=$(printf "%s" "${PR_JSON}" | jq -r .head.ref)
+PR_USER=$(printf "%s" "${PR_JSON}" | jq -r .head.user.login)
-# get checkrun results
-curl -s -H "Accept: application/vnd.github.antiope-preview+json" "https://api.github.com/repos/${BOT_TARGET_REPOSITORY}/commits/${HEAD_SHA}/check-runs?per_page=100" > result-check-runs.txt
+function get_runs() {
+ status="${1:-failure}"
+ # API reference https://docs.github.com/en/rest/reference/actions#list-workflow-runs-for-a-repository
+ github_get "/actions/runs?actor=${PR_USER}&branch=${PR_BRANCH}&status=${status}&per_page=100" | jq -r --arg head_sha "${HEAD_SHA}" '.workflow_runs[] | select(.head_sha==$head_sha) | .url'
+}
# find the failures
-for row in $(cat result-check-runs.txt | jq -r '.check_runs[] | select(.status == "completed" and (.conclusion == "failure" or .conclusion == "cancelled")) | @base64'); do
- _jq() {
- echo ${row} | base64 --decode | jq -r ${1}
- }
-
- name=$(echo $(_jq '.name'))
- check_suite_id=$(echo $(_jq '.check_suite.id'))
- if [[ "${CHECK_NAME}" == "_all" || "${CHECK_NAME}" == "${name}" ]]; then
- echo "rerun action ${name}, check_suite_id = ${check_suite_id}"
- curl -H "Authorization: token ${GITHUB_TOKEN}" -H "Accept: application/vnd.github.antiope-preview+json" -X POST "https://api.github.com/repos/${BOT_TARGET_REPOSITORY}/check-suites/${check_suite_id}/rerequest"
+FAILED_URLS=$(get_runs failure)
+CANCELLED_URLS=$(get_runs cancelled)
+for url in $FAILED_URLS $CANCELLED_URLS; do
+ name=$(github_client "$url"|jq -r '.name')
+ if [[ "${CHECK_NAME}" == "_all" || "${name}" == *"${CHECK_NAME}"* ]]; then
+ echo "rerun-failed-jobs for '${name}' ($url)"
+ # use https://docs.github.com/en/rest/reference/actions#re-run-failed-jobs-from-a-workflow-run
+ # to rerun only the failed jobs
+ github_client -X POST "${url}/rerun-failed-jobs"
else
- echo "Expect ${CHECK_NAME} but skip action ${name}, check_suite_id = ${check_suite_id}"
+ echo "Expect ${CHECK_NAME}, skipping build job '${name}' ($url)"
fi
done