Forgot a script.
Some checks failed
CICD Start / Sanity and Base Decision (pull_request) Failing after 13m38s
Some checks failed
CICD Start / Sanity and Base Decision (pull_request) Failing after 13m38s
Signed-off-by: copilotcoder <copilotcoder@darkhelm.org>
This commit is contained in:
92
scripts/dispatch-workflow.sh
Executable file
92
scripts/dispatch-workflow.sh
Executable file
@@ -0,0 +1,92 @@
|
||||
#!/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}"
|
||||
Reference in New Issue
Block a user