-
Notifications
You must be signed in to change notification settings - Fork 6
/
github_mon
executable file
·138 lines (110 loc) · 4.47 KB
/
github_mon
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/bin/bash
# SPDX-Identifier: gpl-2.0-or-later
# Copyright (C) 2021, Red Hat, Inc.
#
# Monitors a github 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"
[ -f "${HOME}/.github_actions_mon_rc" ] && source "${HOME}/.github_actions_mon_rc"
[ -f "${HOME}/.pwmon-rc" ] && source "${HOME}/.pwmon-rc"
if [ "X" = "X$pw_instance" ]; then
pw_instance="$1"
shift
fi
if [ "X" = "X$github_token" ]; then
github_token="$1"
shift
fi
if [ "X" = "X$pw_project" -a "X$1" != "X" ]; then
pw_project="$1"
shift
fi
if [ "X" = "X$pw_instance" -o "X" = "X$github_token" ]; then
echo "pw_instance or github_token were not set." 1>&2
echo -n "These can be passed as an argument or set in " 1>&2
echo "${HOME}/.github_actions_mon_rc. Exiting" 1>&2
exit 1
fi
AUTH="Authorization: token ${github_token}"
APP="Accept: application/vnd.github.v3+json"
GITHUB_API="https://api.github.com"
ci_instance="gap_sync"
make_result_for_series () {
series_id="$1"
patch_id="$2"
patch_url="$3"
patch_name="$4"
sha="$5"
repo_name="$6"
# Get the name of each respective workflow
workflows="$(echo "$runs" | jq -r ".name" | sort -u)"
# Check that workflows have all completed
select="select(.head_branch==\"series_${series_id}\") | select(.head_sha==\"${sha}\")"
headers="{status, conclusion, html_url}"
run_meta="$(echo "$runs" | jq "$select | $headers")"
if [ "$(echo "$run_meta" | jq -r ".status" | sort -u)" != "completed" ]; then
echo "patch_id=$patch_id belonging to series_id=$series_id not completed. Skipping" 1>&2
return 2
fi
# Scan relevant data for each workflow
echo "$workflows" | while IFS='\n' read -r WORKFLOWNAME; do
# Get run metadata
select="select(.head_branch==\"series_${series_id}\") | select(.head_sha==\"${sha}\") | select(.name==\"${WORKFLOWNAME}\")"
headers="{status, conclusion, html_url}"
run_meta="$(echo "$runs" | jq "$select | $headers")"
# success/failure?
result="$(echo "$run_meta" | jq -r ".conclusion")"
build_url="$(echo "$run_meta" | jq -r ".html_url")"
if [ "$result" == "success" ]; then
result="passed"
else
result="failed"
fi
test_name=$WORKFLOWNAME
echo "pw|$pw_instance|build|$series_id|SHA|$sha|$result|$build_url|$patch_name|$repo_name|$test_name"
done
set_synced_patch "$patch_id" "$pw_instance" "$ci_instance"
}
prev_series=""
prev_url=""
all_runs=""
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; do
if [ "X$pw_project" != "X" -a "X$pw_project" != "X$patchwork_project" ]; then
continue
fi
if [ "X$series_id" != "X$prev_series" ]; then
prev_series="$series_id"
# Get GHA runs
tmp_url="$GITHUB_API/repos/$repo_name/actions/runs?per_page=9000"
if [ "$tmp_url" != "$prev_url" ]; then
prev_url="$tmp_url"
all_runs="$(curl -A "(pw-ci) github-mon-${pw_project}" -s -S -H "${AUTH}" -H "${APP}" "${tmp_url}")"
fi
runs=$(echo "$all_runs" | jq -rc ".workflow_runs[] | select(.head_branch == \"series_$series_id\")")
not_found="$(echo "$runs" | jq -rc ".message")"
fi
if [ "$not_found" == "Not Found" ]; then
echo "\"$tmp_url\" could not be reached." 1>&2
continue
fi
if [ "$not_found" == "Bad credentials" ]; then
echo "Bad credentials - could not authenticate with token ${github_token}. \"$tmp_url\" could not be reached." 1>&2
continue
fi
make_result_for_series "$series_id" "$patch_id" "$patch_url" "$patch_name" "$sha" "$repo_name"
done