🔧 chore(ci): harden superpowers dispatch
Trigger Superpowers Sync / Dispatch main workflow (push) Failing after 5s
Details
Trigger Superpowers Sync / Dispatch main workflow (push) Failing after 5s
Details
This commit is contained in:
parent
437a2c7f19
commit
301956b14a
|
|
@ -27,12 +27,53 @@ jobs:
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
API_BASE="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
REPO_FULL="${{ github.repository }}"
|
||||||
WORKFLOW_FILE="sync-superpowers.yml"
|
WORKFLOW_FILE="sync-superpowers.yml"
|
||||||
API="${API_BASE}/repos/${GITHUB_REPOSITORY}/actions/workflows/${WORKFLOW_FILE}/dispatches"
|
WORKFLOW_PATH=".gitea/workflows/${WORKFLOW_FILE}"
|
||||||
|
|
||||||
curl -sSf -X POST \
|
if [ -n "${GITHUB_API_URL:-}" ]; then
|
||||||
-H "Authorization: token ${TOKEN}" \
|
API_BASE="$GITHUB_API_URL"
|
||||||
-H "Content-Type: application/json" \
|
elif [ -n "${GITEA_API_URL:-}" ]; then
|
||||||
-d '{"ref":"main"}' \
|
API_BASE="$GITEA_API_URL"
|
||||||
"$API"
|
else
|
||||||
|
API_BASE="${GITHUB_SERVER_URL}/api/v1"
|
||||||
|
fi
|
||||||
|
|
||||||
|
payload='{"ref":"main"}'
|
||||||
|
tmp_resp="$(mktemp)"
|
||||||
|
|
||||||
|
try_dispatch() {
|
||||||
|
local url="$1"
|
||||||
|
local code
|
||||||
|
code=$(curl -sS -o "$tmp_resp" -w "%{http_code}" -X POST \
|
||||||
|
-H "Authorization: token ${TOKEN}" \
|
||||||
|
-H "Content-Type: application/json" \
|
||||||
|
-d "$payload" \
|
||||||
|
"$url" || true)
|
||||||
|
|
||||||
|
if [ "$code" -ge 200 ] && [ "$code" -lt 300 ]; then
|
||||||
|
echo "Dispatched: $url"
|
||||||
|
rm -f "$tmp_resp"
|
||||||
|
return 0
|
||||||
|
fi
|
||||||
|
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
|
||||||
|
urls=(
|
||||||
|
"${API_BASE}/repos/${REPO_FULL}/actions/workflows/${WORKFLOW_FILE}/dispatches"
|
||||||
|
"${API_BASE}/repos/${REPO_FULL}/actions/workflows/${WORKFLOW_PATH}/dispatches"
|
||||||
|
"${API_BASE}/repos/${REPO_FULL}/actions/workflows/${WORKFLOW_FILE}/dispatch"
|
||||||
|
"${API_BASE}/repos/${REPO_FULL}/actions/workflows/${WORKFLOW_PATH}/dispatch"
|
||||||
|
)
|
||||||
|
|
||||||
|
for url in "${urls[@]}"; do
|
||||||
|
if try_dispatch "$url"; then
|
||||||
|
exit 0
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
echo "ERROR: failed to dispatch workflow" >&2
|
||||||
|
cat "$tmp_resp" >&2
|
||||||
|
rm -f "$tmp_resp"
|
||||||
|
exit 1
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue