Skip to content

Commit 3e585b8

Browse files
committed
ci: OPTE rev check could be better with GitHub errors
1 parent c16f14f commit 3e585b8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

tools/ci_check_opte_ver.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,26 @@ API_VER=$(curl -s https://raw.githubusercontent.com/oxidecomputer/opte/"$OPTE_RE
3333
# use the total number of pages to get the total number of commits.
3434
# Thus the query parameter `page` in the "last" link (e.g. `&page=162`)
3535
# gives us the rev count we want.
36-
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')
36+
#
37+
# We should be resilient against a transient GitHub issue here. If GitHub gives
38+
# any answer, we'll carry on trying to get a page number out, but we really
39+
# shouldn't if we get a non-200 error. We could `curl -f` to fail for a 4xx or
40+
# above status, but then the observed output when this fails would be an opaque
41+
# "exited with status 22" or something. Help ourselves out and keep the response
42+
# head, printing that if something goes sideways instead.
43+
COMMIT_INFO_HEAD="$(curl -I -s "https://api.github.com/repos/oxidecomputer/opte/commits?per_page=1&sha=$OPTE_REV")"
44+
REV_COUNT=$(echo "$COMMIT_INFO_HEAD" | sed -n '/^[Ll]ink:/ s/.*"next".*page=\([0-9]*\).*"last".*/\1/p')
45+
46+
if [ -z "$REV_COUNT" ]; then
47+
# We didn't get a OPTE rev out. The rev *should* exist, so it should not be
48+
# a 404. If this is a 5xx, it might be a transient error from GitHub. In
49+
# either case, errors are infrequent enough lets just dump the response head
50+
# and hope someone can do something contextually appropriate. And hope this
51+
# doesn't become regular enough anyone wants to be smarter.
52+
echo "Could not get rev count from GitHub response. Response headers:"
53+
echo "$COMMIT_INFO_HEAD"
54+
exit 1
55+
fi
3756

3857
# Combine the API version and the revision count to get the full version
3958
OPTE_VER="0.$API_VER.$REV_COUNT"

0 commit comments

Comments
 (0)