Repository navigation
Expand file tree
/
Copy pathsbt-warm-seed.sh
More file actions
executable file
·98 lines (88 loc) · 3.62 KB
/
Copy pathsbt-warm-seed.sh
File metadata and controls
executable file
·98 lines (88 loc) · 3.62 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#!/usr/bin/env bash
# Warm an sbt cache for the real-sbt suites (SOCKET_PATCH_SBT_E2E_SEED) on a
# host runner, then print the variables a CI step appends to $GITHUB_ENV.
#
# scripts/sbt-warm-seed.sh <sbt.version> <seed dir>
#
# Boots <sbt.version> once through the `sbt` launcher on PATH (`sbt.bat` on
# Windows) and resolves the same tiny Java-only build tests/docker/Dockerfile.sbt
# warms its image with, into the flat seed layout `sbt_e2e_shared::Seed` reads:
# <seed>/coursier/v1, <seed>/ivy2 and <seed>/boot. Without a seed every test
# boots sbt from the network on its own (~1 min each). The suites hard-link
# the seed into each test's private caches, so it is never written by a test.
#
# Prints (stdout):
# SOCKET_PATCH_SBT_E2E_SEED=<seed>
# SOCKET_PATCH_SBT_E2E_SBT=<absolute launcher path>
set -euo pipefail
if [ $# -ne 2 ]; then
sed -n '2,16p' "$0" | sed 's/^# \{0,1\}//' >&2
exit 2
fi
VERSION="$1"
SEED="$2"
windows=""
case "$(uname -s)" in MINGW*|MSYS*|CYGWIN*) windows=1 ;; esac
native() {
# A path the JVM and the Rust test binaries accept.
if [ -n "$windows" ]; then cygpath -m "$1"; else printf '%s\n' "$1"; fi
}
if [ -n "$windows" ]; then
launcher="$(command -v sbt.bat || true)"
else
launcher="$(command -v sbt || true)"
fi
[ -n "$launcher" ] || { echo "sbt-warm-seed: no sbt launcher on PATH" >&2; exit 1; }
mkdir -p "$SEED"
seed="$(cd "$SEED" && pwd)"
work="$(mktemp -d)"
trap 'rm -rf "$work"' EXIT
mkdir -p "$work/project"
echo "sbt.version=$VERSION" > "$work/project/build.properties"
printf '%s\n' 'autoScalaLibrary := false' 'crossPaths := false' \
'libraryDependencies += "org.apache.commons" % "commons-lang3" % "3.11"' > "$work/build.sbt"
extra=()
case "$VERSION" in 2.*) extra=(--server) ;; esac
# The same scrub the suites apply: nothing ambient steers this boot.
unset SBT_OPTS JAVA_OPTS JVM_OPTS JAVA_TOOL_OPTIONS _JAVA_OPTIONS JDK_JAVA_OPTIONS SBT_NATIVE_CLIENT
while IFS= read -r var; do unset "$var"; done < <(env | sed -n 's/^\(COURSIER_[A-Za-z0-9_]*\)=.*/\1/p')
boot() {
(
cd "$work"
COURSIER_CACHE="$(native "$seed/coursier/v1")" "$launcher" -batch -no-colors \
-Dsbt.server.autostart=false \
"-Dsbt.global.base=$(native "$seed/global")" \
"-Dsbt.boot.directory=$(native "$seed/boot")" \
"-Dsbt.ivy.home=$(native "$seed/ivy2")" \
${extra[@]+"${extra[@]}"} update
)
}
# Maven Central blips on runners (a CDN 429, 404 or reset), and this boot
# is the leg's first fetch: one failed download used to fail the whole
# job. Retry only a boot that failed fetching (the same signatures
# sbt_vendor_build_common::FETCH_ERRORS matches: Coursier, Ivy and the
# launcher), each from an empty seed and project/target, since Coursier
# and Ivy can remember a miss. Any other failure exits at once.
fetch_errors='Error downloading|download error|Server access error|unresolved dependency|Error retrieving required libraries'
log="$work/boot.log"
attempt=1
while :; do
rm -rf "$seed/coursier" "$seed/ivy2" "$seed/boot" "$seed/global" \
"$work/project/target" "$work/target"
mkdir -p "$seed/coursier/v1" "$seed/ivy2" "$seed/boot" "$seed/global"
status=0
boot > "$log" 2>&1 || status=$?
cat "$log" >&2
[ "$status" -eq 0 ] && break
if [ "$attempt" -ge 3 ] || ! grep -Eq "$fetch_errors" "$log"; then
exit "$status"
fi
echo "sbt-warm-seed: attempt $attempt failed fetching; retrying" >&2
sleep $((attempt * 10))
attempt=$((attempt + 1))
done
# global/ holds sbt's per-machine state (server sockets, compiled plugins);
# the suites never read it from a seed.
rm -rf "$seed/global"
echo "SOCKET_PATCH_SBT_E2E_SEED=$(native "$seed")"
echo "SOCKET_PATCH_SBT_E2E_SBT=$(native "$launcher")"