|
| 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 | + esac |
| 35 | + done < "${repo_root}/Dockerfile" |
| 36 | +} |
| 37 | + |
| 38 | +update_with_docker() { |
| 39 | + local docker_repo_root="${repo_root}" |
| 40 | + local ruby_image="${BUNDLE_LOCK_RUBY_IMAGE:-}" |
| 41 | + |
| 42 | + if command -v cygpath >/dev/null 2>&1; then |
| 43 | + docker_repo_root="$(cygpath -w "${repo_root}")" |
| 44 | + fi |
| 45 | + |
| 46 | + if [[ -z "${ruby_image}" ]]; then |
| 47 | + ruby_image="$(ruby_image_from_dockerfile)" |
| 48 | + fi |
| 49 | + |
| 50 | + if [[ -z "${ruby_image}" ]]; then |
| 51 | + echo "Unable to determine the Ruby Docker image from Dockerfile." >&2 |
| 52 | + exit 1 |
| 53 | + fi |
| 54 | + |
| 55 | + MSYS_NO_PATHCONV=1 MSYS2_ARG_CONV_EXCL='*' docker run --rm \ |
| 56 | + -v "${docker_repo_root}:/work" \ |
| 57 | + -w /work \ |
| 58 | + "${ruby_image}" \ |
| 59 | + sh -lc 'bundle lock --add-platform "$@"' sh "${platforms[@]}" |
| 60 | +} |
| 61 | + |
| 62 | +if command -v docker >/dev/null 2>&1; then |
| 63 | + update_with_docker |
| 64 | +elif command -v bundle >/dev/null 2>&1; then |
| 65 | + update_with_local_bundler |
| 66 | +else |
| 67 | + echo "Unable to update Gemfile.lock: install Docker or Ruby Bundler first." >&2 |
| 68 | + exit 1 |
| 69 | +fi |
| 70 | + |
| 71 | +echo "Updated ${repo_root}/Gemfile.lock" |
0 commit comments