Files
plex-playlist/scripts/dispatch-workflow.sh
copilotcoder c95fea0946
Some checks failed
CICD Start / Sanity and Base Decision (pull_request) Failing after 13m38s
Forgot a script.
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
2026-05-28 13:02:54 -04:00

93 lines
1.7 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
API_BASE="http://kankali.darkhelm.lan:3000/api/v1"
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}"