Files
plex-playlist/scripts/dispatch-workflow.sh
copilotcoder 61251d5f38
Some checks failed
CICD Start / Sanity and Base Decision (pull_request) Failing after 22s
Trying to unstickify the cicd from failing.
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
2026-05-28 14:56:54 -04:00

99 lines
1.8 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
if [[ -n "${GITHUB_SERVER_URL:-}" ]]; then
API_BASE="${GITHUB_SERVER_URL%/}/api/v1"
elif [[ -n "${GITEA_SERVER_URL:-}" ]]; then
API_BASE="${GITEA_SERVER_URL%/}/api/v1"
else
API_BASE="http://kankali.darkhelm.lan:3000/api/v1"
fi
TOKEN=""
REPO_FULL=""
WORKFLOW_FILE=""
TARGET_REF=""
HEAD_SHA=""
SOURCE_WORKFLOW=""
BASE_NEEDED=""
while [[ $# -gt 0 ]]; do
case "$1" in
--api-base)
API_BASE="$2"
shift 2
;;
--token)
TOKEN="$2"
shift 2
;;
--repo)
REPO_FULL="$2"
shift 2
;;
--workflow)
WORKFLOW_FILE="$2"
shift 2
;;
--ref)
TARGET_REF="$2"
shift 2
;;
--head-sha)
HEAD_SHA="$2"
shift 2
;;
--source-workflow)
SOURCE_WORKFLOW="$2"
shift 2
;;
--base-needed)
BASE_NEEDED="$2"
shift 2
;;
*)
echo "Unknown argument: $1" >&2
exit 2
;;
esac
done
if [[ -z "$TOKEN" || -z "$REPO_FULL" || -z "$WORKFLOW_FILE" || -z "$TARGET_REF" || -z "$HEAD_SHA" || -z "$SOURCE_WORKFLOW" ]]; then
echo "Missing required arguments" >&2
exit 2
fi
REPO_OWNER="${REPO_FULL%/*}"
REPO_NAME="${REPO_FULL#*/}"
if [[ -n "$BASE_NEEDED" ]]; then
PAYLOAD=$(cat <<EOF
{
"ref": "${TARGET_REF}",
"inputs": {
"head_sha": "${HEAD_SHA}",
"source_workflow": "${SOURCE_WORKFLOW}",
"base_needed": "${BASE_NEEDED}"
}
}
EOF
)
else
PAYLOAD=$(cat <<EOF
{
"ref": "${TARGET_REF}",
"inputs": {
"head_sha": "${HEAD_SHA}",
"source_workflow": "${SOURCE_WORKFLOW}"
}
}
EOF
)
fi
echo "Dispatching ${WORKFLOW_FILE} for ${HEAD_SHA} on ${TARGET_REF}"
curl -fsS -X POST \
-H "Authorization: token ${TOKEN}" \
-H "Content-Type: application/json" \
"${API_BASE}/repos/${REPO_OWNER}/${REPO_NAME}/actions/workflows/${WORKFLOW_FILE}/dispatches" \
-d "${PAYLOAD}"