Skip to content

Instantly share code, notes, and snippets.

@dpino
Last active November 16, 2022 12:40
Show Gist options
  • Save dpino/b324320652bb8b758acde123f9a3dbdc to your computer and use it in GitHub Desktop.
Save dpino/b324320652bb8b758acde123f9a3dbdc to your computer and use it in GitHub Desktop.
Fetch commit of last successful WebKit build (default: GTK-Linux-64-bit-Release-Ubuntu-LTS-Build)
#!/usr/bin/env bash
# set -x
# Return commit of last successful WebKit build (default: GTK-Linux-64-bit-Release-Ubuntu-LTS-Build).
# Changes:
# 2022-11-16: Reworked script using changes suggested by asutherland to fetch commit number of last successful build directly from build.webkit.org.
BUILDER_NAME=${1:-GTK-Linux-64-bit-Release-Ubuntu-LTS-Build}
if [[ -z $WEBKIT_CHECKOUT_DIR ]]; then
WEBKIT_CHECKOUT_DIR=${2:-$(realpath $(dirname "$0"))}
fi
usage() {
local exit_code="$1"
local program_name=$(basename "$0")
echo -e "Usage: $program_name BOT-NAME"
echo -e "Returns commit of last successful build for BOT-NAME"
exit $exit_code
}
fatal() {
echo -n "Fatal: "
echo $@
exit 1
}
get_last_successful_build() {
local builder_name="$1"
curl "https://build.webkit.org/api/v2/builders/$builder_name/builds?order=-number&limit=1&complete=true&state_string=build%20successful" 2>/dev/null
}
query_build_number() {
local build_info="$1"
jq -Mr ".builds[0].number" <<< "$build_info"
}
query_builder_id() {
local build_info="$1"
jq -Mr ".builds[0].builderid" <<< "$build_info"
}
get_build_changes() {
local builder_id="$1" build_number="$2"
curl "https://build.webkit.org/api/v2/builders/$builder_id/builds/$build_number/changes" 2>/dev/null
}
query_revision() {
local changes_info="$1"
jq -Mr ".changes[0].revision" <<< "$changes_info"
}
# Main.
if [[ $# -gt 1 ]]; then
usage 1
fi
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
usage 0
fi
build_info=$(get_last_successful_build "$BUILDER_NAME")
if [[ $? -ne 0 ]]; then
fatal "could not fetch build from $BUILDER_NAME"
fi
build_number=$(query_build_number "$build_info")
builder_id=$(query_builder_id "$build_info")
changes_info=$(get_build_changes "$builder_id" "$build_number")
revision=$(query_revision "$changes_info")
echo "$revision"
@dpino
Copy link
Author

dpino commented Sep 29, 2022

Thank you Andrew for looking into this. I'm sorry the script didn't work as expected.

I remember I looked back in the day how to fetch the Git commit directly from the build JSON data, instead of digging into the commit history, but I didn´t find a way to do it. Also querying the JSON document with jq instead of grepping is a much better approach.

I think I'm going to update the script with your changes to avoid confussing anyone looking for how to query data from Bugzilla :D

@asutherland
Copy link

No worries, iteration is always the name of the game in automation like this! (And it's always so energizing to be able to collaborate with people on things, especially searchfox! :)

👍 to updating the script to avoid confusion.

@dpino
Copy link
Author

dpino commented Nov 16, 2022

Updated script with changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment