-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgemfile-to-bundle-add.sh
29 lines (24 loc) · 1.12 KB
/
gemfile-to-bundle-add.sh
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
#!/usr/bin/env bash
# shellcheck disable=SC2086
# Implementation details:
# - doesn't support patterns with spaces like "~> 1.2.3" or "= 1.2.3" mus be ~>1.2.3 or =1.2.3
GEMFILE=${1:-./Gemfile}
CALLER=${2:-bash}
if [[ "${CALLER}" = "bash" ]]
then
echo "[WARNING] Avoid use this script directly use metanorma/docker-gem-install@main action instead"
fi
while IFS= read -r line; do
if [[ $line =~ ^gem ]]; then
GEM=$(echo "$line" | cut -f1 -d"#" | sed -e 's/^gem[[:space:]]*//g' \
-e "s/[[:space:]]*,[[:space:]]*git:[[:space:]]*[\"']\([A-Za-z0-9\:@\.\/\_-]*\)[\"']/ --git \1/g" \
-e "s/[[:space:]]*,[[:space:]]*github:[[:space:]]*[\"']\([A-Za-z0-9\:@\.\/\_-]*\)[\"']/ --github \1/g" \
-e "s/[[:space:]]*,[[:space:]]*branch:[[:space:]]*[\"']\([A-Za-z0-9\:@\.\/\_-]*\)[\"']/ --branch \1/g" \
-e "s/[[:space:]]*,[[:space:]]*source:[[:space:]]*[\"']\([A-Za-z0-9\:@\.\/\_-]*\)[\"']/ --source \1/g" \
-e "s/[[:space:]]*,[[:space:]]*[\"']\([0-9a-z\.~>=<\-]*\)[\"']/ --version \1/g" )
GEM=$(eval echo $GEM) # drop quotes
echo "> bundle add $GEM"
env --unset=RUBYOPT bundle add ${GEM}
fi
done < "$GEMFILE"
bundle update