Skip to content

Commit 6c47070

Browse files
Create .bundle-lock.sh
1 parent a711e7f commit 6c47070

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

scripts/.bundle-lock.sh

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
script_dir="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" && pwd -P)"
5+
repo_root="$(cd -- "${script_dir}/.." && pwd -P)"
6+
cd "${repo_root}"
7+
8+
platforms=(
9+
ruby
10+
x86_64-linux
11+
arm64-darwin
12+
x86_64-darwin
13+
x64-mingw-ucrt
14+
x64-mingw32
15+
x86-mingw32
16+
)
17+
18+
update_with_local_bundler() {
19+
bundle lock --add-platform "${platforms[@]}"
20+
}
21+
22+
ruby_image_from_dockerfile() {
23+
local line image
24+
25+
while IFS= read -r line; do
26+
case "${line}" in
27+
FROM\ ruby:*)
28+
image="${line#FROM }"
29+
image="${image%% AS *}"
30+
image="${image%% as *}"
31+
printf '%s\n' "${image}"
32+
return 0
33+
;;
34+
*)
35+
;;
36+
esac
37+
done < "${repo_root}/Dockerfile"
38+
}
39+
40+
update_with_docker() {
41+
local docker_repo_root="${repo_root}"
42+
local ruby_image="${BUNDLE_LOCK_RUBY_IMAGE:-}"
43+
44+
if command -v cygpath >/dev/null 2>&1; then
45+
docker_repo_root="$(cygpath -w "${repo_root}")"
46+
fi
47+
48+
if [[ -z "${ruby_image}" ]]; then
49+
ruby_image="$(ruby_image_from_dockerfile)"
50+
fi
51+
52+
if [[ -z "${ruby_image}" ]]; then
53+
echo "Unable to determine the Ruby Docker image from Dockerfile." >&2
54+
exit 1
55+
fi
56+
57+
MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='*' docker run --rm \
58+
-v "${docker_repo_root}:/work" \
59+
-w /work \
60+
"${ruby_image}" \
61+
sh -lc 'bundle lock --add-platform "$@"' sh "${platforms[@]}"
62+
}
63+
64+
if command -v docker >/dev/null 2>&1; then
65+
update_with_docker
66+
elif command -v bundle >/dev/null 2>&1; then
67+
update_with_local_bundler
68+
else
69+
echo "Unable to update Gemfile.lock: install Docker or Ruby Bundler first." >&2
70+
exit 1
71+
fi
72+
73+
echo "Updated ${repo_root}/Gemfile.lock"

0 commit comments

Comments
 (0)