Skip to content

Commit 8853ecf

Browse files
authored
setup devcontainer
1 parent c47d967 commit 8853ecf

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"name": "choosealicense.com",
3+
"postCreateCommand": "bash .devcontainer/post-create.sh"
4+
}

.devcontainer/post-create.sh

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
if ! command -v curl >/dev/null 2>&1; then
5+
echo "curl is required to fetch GitHub Pages versions metadata"
6+
exit 1
7+
fi
8+
9+
if ! command -v ruby >/dev/null 2>&1; then
10+
echo "ruby is required to parse GitHub Pages versions metadata"
11+
exit 1
12+
fi
13+
14+
pages_ruby_version="$({
15+
curl -fsSL https://pages.github.com/versions.json
16+
} | ruby -rjson -e 'print JSON.parse(STDIN.read).fetch("ruby")')"
17+
18+
if [[ -z "${pages_ruby_version}" ]]; then
19+
echo "Could not determine Ruby version from https://pages.github.com/versions.json"
20+
exit 1
21+
fi
22+
23+
echo "GitHub Pages Ruby version: ${pages_ruby_version}"
24+
25+
if ! command -v git >/dev/null 2>&1; then
26+
echo "git is required to initialize submodules"
27+
exit 1
28+
fi
29+
30+
echo "Initializing/updating git submodules"
31+
git submodule update --init --recursive
32+
33+
# RVM scripts can reference internal variables before they are initialized,
34+
# which fails under `set -u` (for example: `_system_name: unbound variable`).
35+
# Temporarily disable nounset while sourcing and invoking RVM.
36+
nounset_was_set=0
37+
if [[ $- == *u* ]]; then
38+
nounset_was_set=1
39+
set +u
40+
fi
41+
42+
if [[ -s /usr/local/rvm/scripts/rvm ]]; then
43+
source /usr/local/rvm/scripts/rvm
44+
elif [[ -s "$HOME/.rvm/scripts/rvm" ]]; then
45+
source "$HOME/.rvm/scripts/rvm"
46+
else
47+
echo "RVM was not found; unable to auto-install Ruby ${pages_ruby_version}"
48+
exit 1
49+
fi
50+
51+
rvm install "${pages_ruby_version}" --quiet-curl
52+
rvm use "${pages_ruby_version}"
53+
rvm alias create default "${pages_ruby_version}"
54+
55+
if [[ "${nounset_was_set}" -eq 1 ]]; then
56+
set -u
57+
fi
58+
59+
gem install bundler --no-document
60+
bundle install

0 commit comments

Comments
 (0)