Skip to content

Commit

Permalink
github: alternate api requests
Browse files Browse the repository at this point in the history
Github is currently broken when requesting filtered results for the
github actions runs.  While this stays broken, apply the following which
works around the issue by filtering on the client side.

Plan is to remove when
https://github.community/t/no-longer-able-to-list-in-progress-builds-via-the-api/244175/3
and
https://github.community/t/workflow-call-has-an-inconsistent-status-in-github-rest-api/244164/2
are resolved.

Signed-off-by: Aaron Conole <aconole@redhat.com>
  • Loading branch information
ovsrobot committed Apr 13, 2022
1 parent 5f2048e commit 27feee6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 deletions.
9 changes: 5 additions & 4 deletions github_get_logs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ print_errored_logs_for_commit () {
# Get run metadata
select="select(.head_branch==\"series_${series_id}\") | select(.head_sha==\"${sha}\") | select(.name==\"${test_name}\")"
headers="{id, logs_url}"
run_meta="$(echo "$runs" | jq ".workflow_runs[] | $select | $headers")"
run_meta="$(echo "$runs" | jq "$select | $headers")"

redirect_url="$(echo "$run_meta" | jq -r ".logs_url")"
run_id="$(echo "$run_meta" | jq -r ".id")"
Expand All @@ -88,7 +88,7 @@ print_errored_logs_for_commit () {

length="$(echo "$jobs_results" | jq -r "length")"

if [ "$length" -eq "0" ]; then
if [ "X$length" == "X" -o "X$length" == "X0" ]; then
echo "No build failures detected for series_${series_id}/${sha}. Exiting" 1>&2
return 0
fi
Expand Down Expand Up @@ -134,8 +134,9 @@ print_errored_logs_for_commit () {
repo_name=$(echo "$repo_name" | sed -e 's@%2F@/@g' -e 's,%40,@,g')

# Get GHA runs
tmp_url="$GITHUB_API/repos/$repo_name/actions/runs?branch=series_$series_id&per_page=100"
runs="$(curl -s -S -H "${AUTH}" -H "${APP}" "${tmp_url}")"
tmp_url="$GITHUB_API/repos/$repo_name/actions/runs?per_page=9000"
all_runs="$(curl -s -S -H "${AUTH}" -H "${APP}" "${tmp_url}")"
runs=$(echo $all_runs | jq -rc ".workflow_runs[] | select(.head_branch == \"series_$series_id\")")
not_found="$(echo "$runs" | jq -rc ".message")"
if [ "$not_found" == "Not Found" ]; then
echo "\"$tmp_url\" could not be reached." 1>&2
Expand Down
18 changes: 13 additions & 5 deletions github_mon
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ make_result_for_series () {
repo_name="$6"

# Get the name of each respective workflow
workflows="$(echo "$runs" | jq -r ".workflow_runs[].name" | sort -u)"
workflows="$(echo "$runs" | jq -r ".name" | sort -u)"

# Check that workflows have all completed
select="select(.head_branch==\"series_${series_id}\") | select(.head_sha==\"${sha}\")"
headers="{status, conclusion, html_url}"
run_meta="$(echo "$runs" | jq ".workflow_runs[] | $select | $headers")"
run_meta="$(echo "$runs" | jq "$select | $headers")"

if [ "$(echo "$run_meta" | jq -r ".status" | sort -u)" != "completed" ]; then
echo "patch_id=$patch_id belonging to series_id=$series_id not completed. Skipping" 1>&2
Expand All @@ -78,7 +78,7 @@ make_result_for_series () {
# Get run metadata
select="select(.head_branch==\"series_${series_id}\") | select(.head_sha==\"${sha}\") | select(.name==\"${WORKFLOWNAME}\")"
headers="{status, conclusion, html_url}"
run_meta="$(echo "$runs" | jq ".workflow_runs[] | $select | $headers")"
run_meta="$(echo "$runs" | jq "$select | $headers")"

# success/failure?
result="$(echo "$run_meta" | jq -r ".conclusion")"
Expand All @@ -100,6 +100,9 @@ make_result_for_series () {

prev_series=""

prev_url=""
all_runs=""

get_unsynced_series "$pw_instance" "$ci_instance" | \
while IFS="|" read -r series_id patch_id patch_url patch_name sha patchwork_instance patchwork_project repo_name gap_sync; do

Expand All @@ -111,8 +114,13 @@ while IFS="|" read -r series_id patch_id patch_url patch_name sha patchwork_inst
prev_series="$series_id"

# Get GHA runs
tmp_url="$GITHUB_API/repos/$repo_name/actions/runs?branch=series_$series_id&per_page=100"
runs="$(curl -s -S -H "${AUTH}" -H "${APP}" "${tmp_url}")"
tmp_url="$GITHUB_API/repos/$repo_name/actions/runs?per_page=9000"
if [ "$tmp_url" != "$prev_url" ]; then
prev_url="$tmp_url"
all_runs="$(curl -s -S -H "${AUTH}" -H "${APP}" "${tmp_url}")"
fi

runs=$(echo "$all_runs" | jq -rc ".workflow_runs[] | select(.head_branch == \"series_$series_id\")")
not_found="$(echo "$runs" | jq -rc ".message")"
fi

Expand Down

0 comments on commit 27feee6

Please sign in to comment.