fix(testme-on-pr): wait for a fresh cc-ci status update
This commit is contained in:
@ -23,10 +23,31 @@ NS="${GITEA_NAMESPACE:-recipe-maintainers}"
|
||||
API="https://${GITEA_URL}/api/v1"; AUTH=(-u "${GITEA_USERNAME}:${GITEA_PASSWORD}")
|
||||
POST="${POST:-1}"; MAX_WAIT="${MAX_WAIT:-480}"; INTERVAL="${INTERVAL:-30}"
|
||||
|
||||
status_fields() {
|
||||
curl -s "${AUTH[@]}" "${API}/repos/${NS}/${RECIPE}/commits/${SHA}/status" 2>/dev/null \
|
||||
| python3 -c "import json,sys
|
||||
try: d=json.load(sys.stdin)
|
||||
except Exception: d={}
|
||||
sts=d.get('statuses') or []
|
||||
ctx=[s for s in sts if s.get('context')=='cc-ci/testme']
|
||||
cur=ctx[0] if ctx else {}
|
||||
state=cur.get('state') or d.get('state','') or 'none'
|
||||
url=cur.get('target_url','') or ((sts[0].get('target_url','') if sts else ''))
|
||||
updated=cur.get('updated_at','') or cur.get('created_at','') or ''
|
||||
print(state, url or '', updated or '')" 2>/dev/null || echo "none "
|
||||
}
|
||||
|
||||
SHA="$(curl -s "${AUTH[@]}" "${API}/repos/${NS}/${RECIPE}/pulls/${PRIDX}" \
|
||||
| python3 -c "import json,sys;print(json.load(sys.stdin)['head']['sha'])" 2>/dev/null || true)"
|
||||
[ -n "$SHA" ] || { echo "ERROR: could not resolve ${NS}/${RECIPE} PR #${PRIDX} head sha"; exit 1; }
|
||||
|
||||
baseline_state=""
|
||||
baseline_url=""
|
||||
baseline_updated=""
|
||||
if [ "$POST" = "1" ]; then
|
||||
read -r baseline_state baseline_url baseline_updated < <(status_fields)
|
||||
fi
|
||||
|
||||
if [ "$POST" = "1" ]; then
|
||||
curl -s -o /dev/null "${AUTH[@]}" -H "Content-Type: application/json" -X POST \
|
||||
"${API}/repos/${NS}/${RECIPE}/issues/${PRIDX}/comments" -d '{"body":"!testme"}'
|
||||
@ -38,15 +59,12 @@ fi
|
||||
deadline=$(( $(date +%s) + MAX_WAIT ))
|
||||
url=""
|
||||
while [ "$(date +%s)" -lt "$deadline" ]; do
|
||||
read -r state url < <(curl -s "${AUTH[@]}" "${API}/repos/${NS}/${RECIPE}/commits/${SHA}/status" 2>/dev/null \
|
||||
| python3 -c "import json,sys
|
||||
try: d=json.load(sys.stdin)
|
||||
except Exception: d={}
|
||||
# Look for cc-ci/testme context first (most specific); fall back to first status URL
|
||||
sts=d.get('statuses') or []
|
||||
ctx_url=next((s.get('target_url','') for s in sts if s.get('context')=='cc-ci/testme'), '')
|
||||
url=ctx_url or (sts[0].get('target_url','') if sts else '')
|
||||
print(d.get('state','') or 'none', url or '')" 2>/dev/null || echo "none ")
|
||||
read -r state url updated < <(status_fields)
|
||||
if [ "$POST" = "1" ] && [ "$state" = "$baseline_state" ] \
|
||||
&& [ "$url" = "$baseline_url" ] && [ "$updated" = "$baseline_updated" ]; then
|
||||
sleep "$INTERVAL"
|
||||
continue
|
||||
fi
|
||||
case "$state" in
|
||||
success) echo "VERDICT=GREEN"; echo "BUILD=${url}"; exit 0;;
|
||||
failure|error) echo "VERDICT=RED"; echo "BUILD=${url}"; exit 2;;
|
||||
|
||||
Reference in New Issue
Block a user