-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path.init-template.sh
executable file
·69 lines (54 loc) · 2.12 KB
/
.init-template.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
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
#!/usr/bin/env bash
# This script initializes a repository deployed from this template.
# Skip prompts by setting environment variables SHORT_DESCRIPTION and/or LONG_DESCRIPTION
# If LONG_DESCRIPTION is not set then it will default to the value in SHORT_DESCRIPTION
set -e
SED_COMMAND="sed -i"
if [[ $OSTYPE == "darwin"* ]]; then
# macOS doesn't use GNU sed and has a slightly different syntax
SED_COMMAND="sed -i '' -E"
fi
function update_package_json() {
local -r github_org="$1"
local -r repository_name="$2"
local -r description="$3"
eval "$SED_COMMAND 's|cncsc/template-stacks|$github_org/$repository_name|g' package.json"
eval "$SED_COMMAND 's/{{module_description}}/$description/g' package.json"
rm package-lock.json
npm install
}
function update_github_env_file() {
local -r github_org="$1"
mv "./github/.template" "./github/$github_org"
eval "$SED_COMMAND 's/cncsc/$github_org/g' ./github/$github_org/env.yaml"
}
function update_remote_state_config() {
local tfc_org
echo 'Enter the name of the Terraform Cloud org (e.g. "cncsc-dev"):'
read -r tfc_org
eval "$SED_COMMAND 's/cncsc/$tfc_org/g' .remote-state-config.yaml"
}
function main() {
local -r repository_name=$(git remote -v | grep push | sed -e 's|.*/||' | sed -e 's/\.git.*//')
local description
echo "Initializing repository from template..."
echo "Using repository name as the module name ($repository_name)..."
until test -n "${description:=${SHORT_DESCRIPTION}}"; do
echo "Enter a short description for the repository (package.json):"
echo ' (e.g. "Monorepo for declaratively managing the infrastructure and configuration of <group>.")'
read -r description
done
repo="$(git config --get remote.origin.url | sed 's/.*://')"
github_org="$(dirname "$repo")"
update_package_json "$github_org" "$repository_name" "$description"
update_github_env_file "$github_org"
update_remote_state_config
rm -rf .init-template.sh
echo ""
echo "Initialization complete. Committing to source control..."
pre-commit install
git add -A
git commit -m "Initialize repository from template"
git push -u origin main
}
main "$@"