forked from coder/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_template_versions.sh
More file actions
executable file
·37 lines (29 loc) · 1.1 KB
/
update_template_versions.sh
File metadata and controls
executable file
·37 lines (29 loc) · 1.1 KB
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
#!/bin/bash
set -euo pipefail
EXAMPLES_DIR=$(dirname "${BASH_SOURCE[0]}")
PROJECT_ROOT=$(cd "$EXAMPLES_DIR" && git rev-parse --show-toplevel)
# shellcheck source=scripts/lib.sh
source "$PROJECT_ROOT/scripts/lib.sh"
dependencies curl jq sed
sed_args=(-i)
if isdarwin; then
sed_args=(-i '')
fi
main() {
pushd "$EXAMPLES_DIR/templates"
# Fetch the latest release of terraform-provider-coder from GitHub.
latest_provider_coder="$(curl --fail -sSL https://api.github.com/repos/coder/terraform-provider-coder/releases/latest | jq -r .tag_name)"
latest_provider_coder=${latest_provider_coder#v}
# Update all terraform files that contain ~ the following lines:
# source = "coder/coder"
# version = "[version]"
find . -type f -name "*.tf" -print0 | while read -r -d $'\0' f; do
current_version_raw="$(grep -n -A 1 'source *= *"coder/coder"' "$f" | tail -n 1)"
if [[ $current_version_raw = *version* ]]; then
line="${current_version_raw%%-*}"
sed "${sed_args[@]}" "$line s/\".*\"/\"$latest_provider_coder\"/" "$f"
fi
done
}
# Wrap the main function in a subshell to restore the working directory.
(main)