[script/pull_github_pr.sh] Check Gating status before merging
Maintainers use scripts/pull_github_pr.sh from scylladb.git when merging PRs and before pushing to the next. We want to prevent merges from piling up on top of unstable builds. This change will check Gating's current status and notify the maintainers Related to scylladb/scylla-pkg#3644 Closes scylladb/scylladb#20742
This commit is contained in:
committed by
Botond Dénes
parent
7715abfc56
commit
fac682df7e
@@ -10,13 +10,25 @@
|
||||
set -e
|
||||
|
||||
gh_hosts=~/.config/gh/hosts.yml
|
||||
jenkins_url="https://jenkins.scylladb.com"
|
||||
FORCE=$2
|
||||
ORANGE='\033[0;33m'
|
||||
NC='\033[0m'
|
||||
|
||||
if [[ ( -z "$GITHUB_LOGIN" || -z "$GITHUB_TOKEN" ) && -f "$gh_hosts" ]]; then
|
||||
GITHUB_LOGIN=$(awk '/user:/ { print $2 }' "$gh_hosts")
|
||||
GITHUB_TOKEN=$(awk '/oauth_token:/ { print $2 }' "$gh_hosts")
|
||||
fi
|
||||
|
||||
if [[ $# != 1 ]]; then
|
||||
if [[ -z "$JENKINS_USERNAME" || -z "$JENKINS_API_TOKEN" ]]; then
|
||||
echo "
|
||||
JENKINS_USERNAME or JENKINS_API_TOKEN is missing from env.
|
||||
To create a TOKEN, browse to https://jenkins.scylladb.com, then click on your username (upper right corner) and configure. Click on Add new token and set the JENKINS_USERNAME and JENKINS_API_TOKEN environment variables accordingly.
|
||||
"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
if [ -z "$1" ]; then
|
||||
echo Please provide a github pull request number
|
||||
exit 1
|
||||
fi
|
||||
@@ -36,6 +48,47 @@ curl() {
|
||||
command curl "${opts[@]}" "$@"
|
||||
}
|
||||
|
||||
set_jenkins_job() {
|
||||
branch=$(git rev-parse --abbrev-ref HEAD)
|
||||
version="${branch#next-}"
|
||||
product=$(awk -F'=' '/^PRODUCT/ {print $2}' <SCYLLA-VERSION-GEN)
|
||||
case "$product" in
|
||||
scylla) folder_prefix="scylla";;
|
||||
scylla-enterprise) folder_prefix="enterprise";;
|
||||
esac
|
||||
|
||||
case "$branch" in
|
||||
next) jenkins_job="scylla-master/job/next";;
|
||||
next-enterprise) jenkins_job="scylla-enterprise/job/next";;
|
||||
next*) jenkins_job="$folder_prefix-$version/job/next";;
|
||||
esac
|
||||
}
|
||||
|
||||
check_jenkins_job_status() {
|
||||
set_jenkins_job
|
||||
|
||||
lastCompletedJobName="$jenkins_url/job/$jenkins_job/lastCompletedBuild"
|
||||
lastCompletedBuild="$lastCompletedJobName/api/json?tree=result"
|
||||
getBuildResult=$(curl -s --user $JENKINS_USERNAME:$JENKINS_API_TOKEN $lastCompletedBuild/api/json?tree=result)
|
||||
if [[ "$getBuildResult" == "*Unauthorized*" ]]; then
|
||||
echo -e "${ORANGE}WARNING:${NC} Failed to authenticate with Jenkins. please check your JENKINS_USERNAME and JENKINS_API_TOKEN setting"
|
||||
exit 1
|
||||
fi
|
||||
lastCompleted=$(curl -s --user $JENKINS_USERNAME:$JENKINS_API_TOKEN $lastCompletedBuild | jq -r '.result')
|
||||
|
||||
if [[ "$lastCompleted" == "SUCCESS" ]]; then
|
||||
echo "$lastCompletedJobName is stable"
|
||||
else
|
||||
echo -e "${ORANGE}WARNING:${NC} $lastCompletedJobName is not stable"
|
||||
if [[ "$FORCE" != "--force" ]]; then
|
||||
echo "exiting script since $lastCompletedJobName is unstable, you can force it by running ./script/pull_github_pr.sh <pr num> --force"
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
check_jenkins_job_status
|
||||
|
||||
NL=$'\n'
|
||||
|
||||
PR_NUM=$1
|
||||
|
||||
Reference in New Issue
Block a user