-
-
Notifications
You must be signed in to change notification settings - Fork 73
/
sync-exercise-project-configs
executable file
·71 lines (61 loc) · 1.76 KB
/
sync-exercise-project-configs
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
#!/usr/bin/env sh
# Download the `gleam.toml` and `manifest.toml` project files from the
# `exercism/gleam-test-runner` repository to each exercise to ensure they are
# using the correct versions of the dependencies.
#
# ./bin/sync-exercise-project-configs
#
# Alternatively you can give the `check` argument to check that the manifests
# are correct.
#
# ./bin/sync-exercise-project-configs --check
#
set -eu
download() {
file="$1"
url="$2"
curl --silent --show-error --fail --retry 3 --max-time 3 \
--output "$file" "$url"
}
update_config_name() {
project="$1"
name="$(basename "$project" | sed 's/-/_/g')"
sed -i -e "s/name = \".*\"/name = \"$name\"/" "$canonical_config"
}
check() {
project="$1"
update_config_name "$project"
if ! diff "$canonical_config" "$project"/gleam.toml ||
! diff "$canonical_manifest" "$project"/manifest.toml
then
echo "ERROR: Config files are out of sync with gleam-test-runner config" 1>&2
echo "Run \`bin/sync-exercise-project-configs\` to correct this" 1>&2
exit 1
fi
}
sync() {
project="$1"
update_config_name "$project"
cp "$canonical_config" "$project"/gleam.toml
cp "$canonical_manifest" "$project"/manifest.toml
}
packages_prefix="https://raw.githubusercontent.com/exercism/gleam-test-runner/main/packages"
project_dir="$(dirname "$(dirname "$0")")"
tmp_dir="$(mktemp -d)"
canonical_config="$tmp_dir"/gleam.toml
canonical_manifest="$tmp_dir"/manifest.toml
download "$canonical_config" "$packages_prefix"/gleam.toml
download "$canonical_manifest" "$packages_prefix"/manifest.toml
for config in "$project_dir"/exercises/*/*/gleam.toml
do
project="$(dirname "$config")"
echo "$project"
case "$@" in
*--check*)
check "$project"
;;
*)
sync "$project"
;;
esac
done