More CICD fixes again again again again
All checks were successful
CICD Start / Sanity and Base Decision (pull_request) Successful in 1m38s
All checks were successful
CICD Start / Sanity and Base Decision (pull_request) Successful in 1m38s
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
This commit is contained in:
@@ -127,64 +127,51 @@ jobs:
|
|||||||
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_IP}:3001/api/v1")
|
CANDIDATE_API_BASES+=("http://${GITEA_REGISTRY_IP}:3001/api/v1")
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ensure_curl() {
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v apt-get >/dev/null 2>&1; then
|
||||||
|
export DEBIAN_FRONTEND=noninteractive
|
||||||
|
apt-get update -qq
|
||||||
|
apt-get install -y -qq curl ca-certificates
|
||||||
|
fi
|
||||||
|
|
||||||
|
if command -v curl >/dev/null 2>&1; then
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "❌ curl is required for dispatch and could not be installed"
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
ensure_curl
|
||||||
|
|
||||||
dispatched=false
|
dispatched=false
|
||||||
for API_BASE in "${CANDIDATE_API_BASES[@]}"; do
|
for API_BASE in "${CANDIDATE_API_BASES[@]}"; do
|
||||||
DISPATCH_URL="${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/${TARGET_WORKFLOW}/dispatches"
|
DISPATCH_URL="${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/${TARGET_WORKFLOW}/dispatches"
|
||||||
|
|
||||||
HTTP_RESULT=$(
|
RESPONSE_FILE="/tmp/dispatch-response.txt"
|
||||||
printf '%s\n' \
|
: > "${RESPONSE_FILE}"
|
||||||
'import os' \
|
|
||||||
'import sys' \
|
|
||||||
'import urllib.error' \
|
|
||||||
'import urllib.request' \
|
|
||||||
'' \
|
|
||||||
'url = os.environ["DISPATCH_URL"]' \
|
|
||||||
'token = os.environ["DISPATCH_TOKEN"]' \
|
|
||||||
'payload = os.environ["DISPATCH_PAYLOAD"]' \
|
|
||||||
'' \
|
|
||||||
'request = urllib.request.Request(' \
|
|
||||||
' url,' \
|
|
||||||
' data=payload.encode("utf-8"),' \
|
|
||||||
' headers={' \
|
|
||||||
' "Authorization": "token " + token,' \
|
|
||||||
' "Content-Type": "application/json" ,' \
|
|
||||||
' "User-Agent": "plex-playlist-cicd-start" ,' \
|
|
||||||
' },' \
|
|
||||||
' method="POST",' \
|
|
||||||
')' \
|
|
||||||
'' \
|
|
||||||
'try:' \
|
|
||||||
' with urllib.request.urlopen(request, timeout=20) as response:' \
|
|
||||||
' sys.stdout.write(f"{response.status}\\n")' \
|
|
||||||
' body = response.read().decode("utf-8", "replace")' \
|
|
||||||
' if body:' \
|
|
||||||
' sys.stdout.write(body)' \
|
|
||||||
'except urllib.error.HTTPError as error:' \
|
|
||||||
' sys.stdout.write(f"{error.code}\\n")' \
|
|
||||||
' body = error.read().decode("utf-8", "replace")' \
|
|
||||||
' if body:' \
|
|
||||||
' sys.stdout.write(body)' \
|
|
||||||
'except Exception as error:' \
|
|
||||||
' sys.stdout.write(f"000\\n{error}\\n")' \
|
|
||||||
| DISPATCH_URL="${DISPATCH_URL}" \
|
|
||||||
DISPATCH_TOKEN="${DISPATCH_TOKEN}" \
|
|
||||||
DISPATCH_PAYLOAD="${payload}" \
|
|
||||||
python3 -
|
|
||||||
)
|
|
||||||
|
|
||||||
HTTP_CODE=$(printf '%s\n' "${HTTP_RESULT}" | sed -n '1p')
|
HTTP_CODE=$(curl -sS --connect-timeout 5 --max-time 20 -o "${RESPONSE_FILE}" -w "%{http_code}" -X POST \
|
||||||
RESPONSE_BODY=$(printf '%s\n' "${HTTP_RESULT}" | sed '1d')
|
-H "Authorization: token ${DISPATCH_TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-H "User-Agent: plex-playlist-cicd-start" \
|
||||||
|
"${DISPATCH_URL}" \
|
||||||
|
-d "${payload}" || true)
|
||||||
|
|
||||||
if [ "${HTTP_CODE}" -ge 200 ] && [ "${HTTP_CODE}" -lt 300 ]; then
|
if [[ "${HTTP_CODE}" =~ ^[0-9]+$ ]] && [ "${HTTP_CODE}" -ge 200 ] && [ "${HTTP_CODE}" -lt 300 ]; then
|
||||||
echo "✓ Dispatch succeeded via ${API_BASE}"
|
echo "✓ Dispatch succeeded via ${API_BASE}"
|
||||||
dispatched=true
|
dispatched=true
|
||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Dispatch attempt failed via ${API_BASE} (HTTP ${HTTP_CODE})"
|
echo "Dispatch attempt failed via ${API_BASE} (HTTP ${HTTP_CODE})"
|
||||||
if [ -n "${RESPONSE_BODY}" ]; then
|
if [ -s "${RESPONSE_FILE}" ]; then
|
||||||
echo "Response body:"
|
echo "Response body:"
|
||||||
printf '%s\n' "${RESPONSE_BODY}"
|
cat "${RESPONSE_FILE}"
|
||||||
fi
|
fi
|
||||||
done
|
done
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user