Repository navigation
Expand file tree
/
Copy pathprogress.sh
More file actions
executable file
·83 lines (74 loc) · 2.79 KB
/
Copy pathprogress.sh
File metadata and controls
executable file
·83 lines (74 loc) · 2.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/bin/bash
set -euo pipefail
# Show recent commits on agent-work and the swarm's containers.
if [ "${1:-}" = "-h" ] || [ "${1:-}" = "--help" ]; then
cat <<HELP
Usage: $0
Show recent commits on agent-work and the swarm's containers.
Displays the last 15 commits on the bare repo's agent-work and lists
the containers with their state.
HELP
exit 0
fi
SWARM_DIR="$(cd "$(dirname "$0")" && pwd)"
source "$SWARM_DIR/lib/check-deps.sh"
check_deps git jq docker
# shellcheck source=lib/project.sh
source "$SWARM_DIR/lib/project.sh"
REPO_ROOT="$(git rev-parse --show-toplevel)"
PROJECT="$(swarm_project_resolve "$REPO_ROOT")" || exit 1
RUNTIME_DIR="$(swarm_runtime_dir "$PROJECT")" || exit 1
BARE_REPO="${RUNTIME_DIR}/upstream.git"
if [ ! -d "$BARE_REPO" ]; then
echo "ERROR: ${BARE_REPO} not found. Are agents running?" >&2
exit 1
fi
swarm_runtime_check "$RUNTIME_DIR" || exit 1
swarm_runtime_owner_check "$RUNTIME_DIR" "$REPO_ROOT" "$PROJECT" || exit 1
# Containers are read only when the Docker daemon answers; the commit
# history needs only git.
DOCKER_UP=false
if docker info >/dev/null 2>&1; then
DOCKER_UP=true
swarm_containers_verify "$PROJECT" "$REPO_ROOT" || exit 1
fi
# Set when the run gets to its end (its last line).
PROGRESS_EXIT_OK=false
# The EXIT trap: where Bash needs it (swarm_stop_guard_needed), never
# let a run that stopped short end with status 0. Bash can also run
# this trap with $? at 0 when a signal ends the script, so the check is
# only made where Bash can end a stopped run with 0 itself; there a
# signal can print the line too. Any other status stays, a signal's
# too.
progress_exit_trap() {
local rc=$?
if [ "$rc" -eq 0 ] && ! $PROGRESS_EXIT_OK \
&& swarm_stop_guard_needed "${BASH_VERSINFO[0]}" \
"${BASH_VERSINFO[1]}"; then
echo "ERROR: progress.sh stopped before the end of its run." >&2
exit 1
fi
}
trap progress_exit_trap EXIT
# Read the bare repo, which agents write, in place: no pager (core.pager
# there would run on the host), no transport (a missing object must not
# make it fetch from a remote the repo names) and no signature check
# (log.showSignature would run the repo's gpg.program).
echo "=== Recent commits ==="
swarm_no_fetch git --no-pager -c log.showSignature=false \
--git-dir="$BARE_REPO" log --oneline -15 refs/heads/agent-work
echo ""
echo "=== Status ==="
if [ "$DOCKER_UP" = true ] \
&& own=$(swarm_own_containers "$PROJECT" "$REPO_ROOT" \
2>/dev/null); then
printf '%s\n' "$own" | while read -r name id; do
[ -n "$name" ] || continue
docker container inspect -f "${name}: {{.State.Status}}" \
"$id" 2>/dev/null || true
done
else
echo "(docker not available)"
fi
# The run got to its end (see progress_exit_trap).
PROGRESS_EXIT_OK=true