Skip to content

ci: OPTE rev check could be better with GitHub errors #8537

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion tools/ci_check_opte_ver.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,26 @@ API_VER=$(curl -s https://raw.githubusercontent.com/oxidecomputer/opte/"$OPTE_RE
# use the total number of pages to get the total number of commits.
# Thus the query parameter `page` in the "last" link (e.g. `&page=162`)
# gives us the rev count we want.
REV_COUNT=$(curl -I -s "https://api.github.com/repos/oxidecomputer/opte/commits?per_page=1&sha=$OPTE_REV" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p')
#
# We should be resilient against a transient GitHub issue here. If GitHub gives
# any answer, we'll carry on trying to get a page number out, but we really
# shouldn't if we get a non-200 error. We could `curl -f` to fail for a 4xx or
# above status, but then the observed output when this fails would be an opaque
# "exited with status 22" or something. Help ourselves out and keep the response
# head, printing that if something goes sideways instead.
COMMIT_INFO_HEAD="$(curl -I -s "https://api.github.com/repos/oxidecomputer/opte/commits?per_page=1&sha=$OPTE_REV")"
REV_COUNT=$(echo "$COMMIT_INFO_HEAD" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p')

if [ -z "$REV_COUNT" ]; then
# We didn't get a OPTE rev out. The rev *should* exist, so it should not be
# a 404. If this is a 5xx, it might be a transient error from GitHub. In
# either case, errors are infrequent enough lets just dump the response head
# and hope someone can do something contextually appropriate. And hope this
# doesn't become regular enough anyone wants to be smarter.
echo "Could not get rev count from GitHub response. Response headers:"
echo "$COMMIT_INFO_HEAD"
exit 1
fi

# Combine the API version and the revision count to get the full version
OPTE_VER="0.$API_VER.$REV_COUNT"
Expand Down
Loading