Skip to content

Instantly share code, notes, and snippets.

@apconole
Created December 6, 2023 21:37
Show Gist options
  • Save apconole/c084f1740ccc27f048235a8d84d00040 to your computer and use it in GitHub Desktop.
Save apconole/c084f1740ccc27f048235a8d84d00040 to your computer and use it in GitHub Desktop.
cirrus monitor script
#!/bin/bash
# SPDX-Identifier: gpl-2.0-or-later
# Copyright (C) 2023, Red Hat, Inc.
#
# Monitors cirrus build history for builds in a series.
# Records the builds in the series database (and emits them on the
# stdout line for processing)
#
# Licensed under the terms of the GNU General Public License as published
# by the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version. You may obtain a copy of the
# license at
#
# https://www.gnu.org/licenses/old-licenses/gpl-2.0.html
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
[ -f "$(dirname $0)/series_db_lib.sh" ] && source "$(dirname $0)/series_db_lib.sh"
while [ "$1" != "" ]; do
if echo "$1" | grep -q -s -E ^--pw-instance= ; then
pw_instance=$(echo "$1" | sed s/^--pw-instance=//)
shift
elif echo "$1" | grep -q -s -E ^--cirrus-token= ; then
cirrus_token=$(echo "$1" | sed s/^--cirrus-token=//)
shift
elif echo "$1" | grep -E ^--help >/dev/null 2>&1; then
echo "Cirrus CI monitor script"
echo "$0: args"
echo "Required if not set in ~/.pwmon-rc file:"
echo " --pw-instance=<inst url> URL for pw"
echo ""
echo "Options:"
echo " --cirrus-token=<token> Sets tokenfor web requests"
echo ""
exit 0
else
echo "Unknown option: '$1'"
echo "Rerun with --help for details"
exit 1
fi
done
if [ "X$pw_instance" == "X" ]; then
echo "Please set the pw-instance properly"
echo "Use --help for details."
exit 1
fi
if [ "X$cirrus_token" != "X" ]; then
AUTH="-H \"Authorization: Bearer $cirrus_token\""
fi
ci_instance="cirrus_sync"
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 obs_sync cirrus_sync; do
repo_owner=$(echo "$repo_name" | cut -d/ -f1)
repo_real=$(echo "$repo_name" | cut -d/ -f2)
graph_string="{ \"query\": \"query BuildBySHAQuery(\$owner: String!, \$name: String!, \$SHA: String){ searchBuilds(repositoryOwner: \$owner, repositoryName: \$name, SHA: \$SHA) { id, status } }\", \"variables\": { \"owner\": \"$repo_owner\", \"name\": \"$repo_real\", \"SHA\": \"$sha\" } }"
build_details=$(curl -s "$AUTH" -X POST --data "$graph_string" https://api.cirrus-ci.com/graphql)
id=$(echo "$build_details" | jq -rc '.data.searchBuilds[-1].id')
status=$(echo "$build_details" | jq '.data.searchBuilds[-1].status')
result="in-progress"
if [ "$status" == "COMPLETED" ]; then
result="passed"
elif [ "$status" == "FAILED" ]; then
result="failed"
elif [ "$status" == "ABORTED" -o "$status" == "ERRORED" ]; then
result="warn"
fi
if [ "$result" == "in-progress" ]; then
echo "patch_id=$patch_id belonging to series=$series_id is not completed. Skipping" 1>&2
continue
fi
# now get each task - this way we can publish the task details
# TODO
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment