🔧 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
|
||||
fi
|
||||
|
||||
API_BASE="${GITHUB_API_URL:-${GITHUB_SERVER_URL}/api/v1}"
|
||||
REPO_FULL="${{ github.repository }}"
|
||||
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 \
|
||||
-H "Authorization: token ${TOKEN}" \
|
||||
-H "Content-Type: application/json" \
|
||||
-d '{"ref":"main"}' \
|
||||
"$API"
|
||||
if [ -n "${GITHUB_API_URL:-}" ]; then
|
||||
API_BASE="$GITHUB_API_URL"
|
||||
elif [ -n "${GITEA_API_URL:-}" ]; then
|
||||
API_BASE="$GITEA_API_URL"
|
||||
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