solstice-ci/.mise/tasks/run/forge-enqueue

31 lines
1.1 KiB
Text
Raw Normal View History

#!/usr/bin/env bash
set -euo pipefail
# Enqueue a sample job via the forge-integration crate.
# Detect repo URL and commit from the current git checkout unless overridden.
command -v cargo >/dev/null 2>&1 || { echo "cargo is required" >&2; exit 127; }
command -v git >/dev/null 2>&1 || { echo "git is required to autodetect repo and commit" >&2; exit 127; }
export RUST_LOG=${RUST_LOG:-info}
# AMQP defaults for local dev
export AMQP_URL=${AMQP_URL:-amqp://127.0.0.1:5672/%2f}
export AMQP_EXCHANGE=${AMQP_EXCHANGE:-solstice.jobs}
export AMQP_QUEUE=${AMQP_QUEUE:-solstice.jobs.v1}
export AMQP_ROUTING_KEY=${AMQP_ROUTING_KEY:-jobrequest.v1}
REPO_URL=${SOL_REPO_URL:-$(git remote get-url origin 2>/dev/null || true)}
COMMIT_SHA=${SOL_COMMIT_SHA:-$(git rev-parse HEAD 2>/dev/null || true)}
RUNS_ON=${SOL_RUNS_ON:-}
if [[ -z "${REPO_URL}" || -z "${COMMIT_SHA}" ]]; then
echo "Failed to detect repo URL and/or commit. Set SOL_REPO_URL and SOL_COMMIT_SHA explicitly." >&2
exit 2
fi
args=(enqueue --repo-url "${REPO_URL}" --commit-sha "${COMMIT_SHA}")
if [[ -n "${RUNS_ON}" ]]; then
args+=(--runs-on "${RUNS_ON}")
fi
exec cargo run -p forge-integration -- "${args[@]}"