deploy(M00-E): 完善菜单式部署骨架
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
# shellcheck source=lib.sh
|
||||
. "${SCRIPT_DIR}/lib.sh"
|
||||
|
||||
qipai_repo_status() {
|
||||
local repo_dir
|
||||
repo_dir="$(qipai_repo_dir)"
|
||||
|
||||
if [ ! -d "${repo_dir}/.git" ]; then
|
||||
qipai_warn "repo not cloned: ${repo_dir}"
|
||||
qipai_info "expected repo: ${QIPAI_REPO_URL}"
|
||||
return 0
|
||||
fi
|
||||
|
||||
git -C "$repo_dir" remote -v
|
||||
local branch status
|
||||
branch="$(git -C "$repo_dir" branch --show-current)"
|
||||
status="$(git -C "$repo_dir" status --short --branch --untracked-files=all)"
|
||||
qipai_info "branch: ${branch}"
|
||||
printf '%s\n' "$status"
|
||||
|
||||
if [ "$branch" != "$QIPAI_BRANCH" ]; then
|
||||
qipai_fail "branch mismatch: expected ${QIPAI_BRANCH}, actual ${branch}"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if git -C "$repo_dir" diff --quiet && git -C "$repo_dir" diff --cached --quiet; then
|
||||
qipai_pass "repo is not dirty"
|
||||
else
|
||||
qipai_fail "repo is DIRTY; deployment must stop"
|
||||
return 1
|
||||
fi
|
||||
|
||||
git -C "$repo_dir" fetch origin "$QIPAI_BRANCH"
|
||||
local counts
|
||||
counts="$(git -C "$repo_dir" rev-list --left-right --count "${QIPAI_BRANCH}...origin/${QIPAI_BRANCH}")"
|
||||
qipai_info "ahead/behind: ${counts}"
|
||||
case "$counts" in
|
||||
"0 0") qipai_pass "repo matches origin/${QIPAI_BRANCH}" ;;
|
||||
0$'\t'*) qipai_warn "repo is BEHIND origin/${QIPAI_BRANCH}" ;;
|
||||
*$'\t'0) qipai_fail "repo is AHEAD origin/${QIPAI_BRANCH}; deployment must stop"; return 1 ;;
|
||||
*) qipai_fail "repo is DIVERGED; deployment must stop"; return 1 ;;
|
||||
esac
|
||||
}
|
||||
|
||||
if [ "${1:-}" = "--run" ]; then
|
||||
qipai_repo_status
|
||||
fi
|
||||
|
||||
Reference in New Issue
Block a user