-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path.envrc.jinja2
More file actions
executable file
·199 lines (182 loc) · 6.44 KB
/
.envrc.jinja2
File metadata and controls
executable file
·199 lines (182 loc) · 6.44 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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# This script should not be called directly. It is called by direnv
# In your IDE, you can associate the shell language to the extension .envrc.jinja2 for full bash support
# Strict Bash
set -TCEeuo pipefail
echo ""
###################
# Project Env
# Project Environment are common project variables used in script
###################
# Project Root
export ORGANIZATION_NAME="{{ organization_name }}"
# Name used in env
export ORGANIZATION_ENV_NAME="{{ organization_name | replace('-', '_') | upper }}"
# Name used in path
export ORGANIZATION_PATH_NAME="{{ organization_name | replace('_', '-') | lower }}"
# Name of the project use as identifier with the organization name
export PROJECT_NAME="{{ project_name | replace('_', '-') | lower }}"
# Used by script to get the root
export PROJECT_ROOT="$PWD"
# ProjectId
export PROJECT_ID="$ORGANIZATION_NAME/$PROJECT_NAME"
# The package manager
export PACKAGE_MANAGER="{{ package_manager }}"
# Common function
source "$PROJECT_ROOT/.envrc.devf.sh"
# Feedback
echo "Project:"
export COL_PROP_LENGTH=17
devf_print_props "Project Root" "${PROJECT_ROOT}"
devf_print_props "Organization Name" "${ORGANIZATION_NAME}"
devf_print_props "Package Manager" "${PACKAGE_MANAGER}"
#################
# DEVF
# Bin script installation
# The installation is done by cloning the repo to a well-known location.
#################
echo ""
echo "Devfiles: "
export DEVF_PREFIX="DEVF"
DEVF_DIR_VAR_NAME="${DEVF_PREFIX}_${ORGANIZATION_ENV_NAME}_DIR"
export DEVF_DIR
DEVF_DIR="${!DEVF_DIR_VAR_NAME:-}"
if [ "$DEVF_DIR" != "" ]; then
devf_print_props "Repo Directory" "$DEVF_DIR (from var $DEVF_DIR_VAR_NAME)"
else
DEVF_DIR=$(realpath "$PWD/../devfiles")
devf_print_props "Repo Directory" "$DEVF_DIR (default)"
fi
if [ ! -d "$DEVF_DIR" ]; then
devf_echo_yellow "DEVF_DIR ($DEVF_DIR) does not exist."
DEVF_REPO_URI_VAR_NAME="${DEVF_PREFIX}_${ORGANIZATION_ENV_NAME}_URI"
DEVF_REPO_URI="${!DEVF_REPO_URI_VAR_NAME:-https://github.com/combostrap/devfiles}"
devf_echo_yellow "Clone $DEVF_REPO_URI to $DEVF_DIR? Y(Yes-Default)/N(No)"
read -r CLONE
if [ "$CLONE" == "" ] || [ "$CLONE" == "Y" ]; then
git clone "$DEVF_REPO_URI" "$DEVF_DIR"
devf_echo_yellow "Repo Manager repo cloned"
fi
fi
############################
# Pre-commit setup
# Install pre-commit hooks
############################
if command -v pre-commit &> /dev/null; then
echo ""
echo "Pre-commit:"
export COL_PROP_LENGTH=17
if [ ! -f "$PROJECT_ROOT/.git/hooks/pre-commit" ]; then
pre-commit install
devf_print_props "Pre-commit hooks" "installed"
else
devf_print_props "Pre-commit hooks" "enabled"
fi
if [ ! -f "$PROJECT_ROOT/.git/hooks/commit-msg" ]; then
pre-commit install --hook-type commit-msg
devf_print_props "Commit-msg hooks" "installed"
else
devf_print_props "Commit-msg hooks" "enabled"
fi
if [ ! -f "$PROJECT_ROOT/.git/hooks/post-commit" ]; then
pre-commit install --hook-type post-commit
devf_print_props "Post-commit hooks" "installed"
else
devf_print_props "Post-commit hooks" "enabled"
fi
else
echo "⚠️ pre-commit not found. Install with: pip install pre-commit"
exit 1
fi
# In case, the repo was not installed
if [ -d "$DEVF_DIR" ]; then
#################
# Bin
#################
echo ""
echo "Devfiles Scripts in PATH:"
export COL_PROP_LENGTH=28
# Project Root is first as it has less priority than the others
# For instance, we create a mvnw wrapper to inject secrets
# so it should be use first and not the project mvnw script
export PATH="$PROJECT_ROOT:$PATH" # script such as mvnw are in this path
devf_print_props "Project Root Path" "$PROJECT_ROOT"
DEV_SCRIPT_PATH="$DEVF_DIR/dev-scripts"
PACKAGE_MANAGER_PATH="$DEV_SCRIPT_PATH/package-manager/$PACKAGE_MANAGER"
export PATH="$PACKAGE_MANAGER_PATH:$PATH" # script path first as it has a higher priority
devf_print_props "Package Manager Scripts Path" "$PACKAGE_MANAGER_PATH"
GIT_HOOKS="$DEV_SCRIPT_PATH/git-hooks"
export PATH="$GIT_HOOKS:$PATH" # script path first as it has a higher priority
devf_print_props "Git Hooks Path" "$GIT_HOOKS"
SETUP_PATH="$DEV_SCRIPT_PATH/setup"
export PATH="$SETUP_PATH:$PATH" # script path first as it has a higher priority
devf_print_props "Setup Scripts Path" "$SETUP_PATH"
WRAPPERS_PATH="$DEV_SCRIPT_PATH/wrappers"
export PATH="$WRAPPERS_PATH:$PATH" # script path first as it has a higher priority
devf_print_props "Wrapper Scripts Path" "$WRAPPERS_PATH"
echo ""
echo "Git: "
source "$SETUP_PATH"/git-config.sh
############################
# Maven Setup
# We need the sdkman setup script
############################
if [ "$PACKAGE_MANAGER" == "maven" ]; then
echo ""
echo "Maven: "
SDKMAN_MAVEN_VERSION=$(grep -oP 'apache-maven/\K[0-9]+\.[0-9]+\.[0-9]+' .mvn/wrapper/maven-wrapper.properties)
echo " Version: $SDKMAN_MAVEN_VERSION"
# mvn setup
if ! command -v mvn &> /dev/null; then
echo "Maven mvn command not found in the path. Installing it with sdkman"
if [[ $(type -t sdk) == "" ]]; then
# Sdk man init
source "$DEV_SCRIPT_PATH/setup/sdkman.sh"
fi
if ! sdk home maven "${SDKMAN_MAVEN_VERSION}" > /dev/null; then
devf_echo_yellow "Maven installation with sdkman"
sdk install maven "${SDKMAN_MAVEN_VERSION}"
fi
# Putting maven in the path
sdk use maven "${SDKMAN_MAVEN_VERSION}"
fi
# mvnw setup
# Does maven wrapper is installed ?
if [ ! -f "$PROJECT_ROOT/mvnw" ]; then
devf_echo_yellow "mvn wrapper not found, installing it"
mvn wrapper:wrapper
fi
fi
else
devf_echo_yellow "WARNING: devfiles repo not installed: git, maven and common script not configured"
fi
##############################
# Load sub envrc project script
##############################
ENVRCD="$PROJECT_ROOT/.envrc.d"
echo ""
echo "Envrc.d scripts: "
if [ -d "$ENVRCD" ]; then
# All file loaded in a directory should have a sh extension
# This is how /etc/profile also work
count=0
export COL_PROP_LENGTH=1
for file in "$ENVRCD"/*.sh; do
count=$((count + 1))
# shellcheck disable=SC1090
if [ -r "$file" ]; then
source "$file"
devf_print_props "$count" "$(realpath --relative-to="$ENVRCD" "$file")"
fi
done
unset file
else
echo " Not found"
fi
echo ""
echo "Env: "
export COL_PROP_LENGTH=17
devf_print_props "PROJECT_ROOT" "$PROJECT_ROOT"
devf_print_props "ORGANIZATION_NAME" "$ORGANIZATION_NAME"
devf_print_props "DEVF_DIR" "$DEVF_DIR"
# Last EOL before direnv output
echo ""