63 lines
1.5 KiB
Bash
63 lines
1.5 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
set -euo pipefail
|
|
|
|
if [[ "${1:-}" == "-h" || "${1:-}" == "--help" ]]; then
|
|
echo "Usage: bash scripts/trigger-gitea-pipeline.sh [remote] [branch]"
|
|
echo ""
|
|
echo "Examples:"
|
|
echo " bash scripts/trigger-gitea-pipeline.sh"
|
|
echo " bash scripts/trigger-gitea-pipeline.sh gitea main"
|
|
echo " bash scripts/trigger-gitea-pipeline.sh origin main"
|
|
exit 0
|
|
fi
|
|
|
|
resolve_default_remote() {
|
|
if git remote get-url gitea >/dev/null 2>&1; then
|
|
echo "gitea"
|
|
return 0
|
|
fi
|
|
|
|
if git remote get-url origin >/dev/null 2>&1; then
|
|
echo "origin"
|
|
return 0
|
|
fi
|
|
|
|
return 1
|
|
}
|
|
|
|
REMOTE="${1:-}"
|
|
BRANCH="${2:-main}"
|
|
|
|
if ! git rev-parse --git-dir >/dev/null 2>&1; then
|
|
echo "[ERROR] Current directory is not a git repository."
|
|
exit 1
|
|
fi
|
|
|
|
if [[ -z "$REMOTE" ]]; then
|
|
if ! REMOTE="$(resolve_default_remote)"; then
|
|
echo "[ERROR] No default remote found. Expected 'gitea' or 'origin'."
|
|
echo "Available remotes:"
|
|
git remote -v || true
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
if ! git remote get-url "$REMOTE" >/dev/null 2>&1; then
|
|
echo "[ERROR] Remote '$REMOTE' does not exist."
|
|
echo "Available remotes:"
|
|
git remote -v
|
|
exit 1
|
|
fi
|
|
|
|
HEAD_SHA="$(git rev-parse --short HEAD)"
|
|
|
|
echo "[INFO] HEAD: ${HEAD_SHA}"
|
|
echo "[INFO] Force-push HEAD to remote branch '${BRANCH}'"
|
|
git push "$REMOTE" "HEAD:refs/heads/${BRANCH}" --force
|
|
|
|
echo "[INFO] Verify remote branch reference"
|
|
git ls-remote "$REMOTE" "refs/heads/${BRANCH}"
|
|
|
|
echo "[DONE] Pipeline trigger request sent by updating branch '${BRANCH}'."
|