-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathedit_integrations_project_yml.sh
43 lines (34 loc) · 1.1 KB
/
edit_integrations_project_yml.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
#!/bin/bash
# Arguments
PACKAGE_NAME=$1
DBT_PROJECT_FILE="../dbt_$PACKAGE_NAME/integration_tests/dbt_project.yml"
#!/bin/bash
# Check if the correct number of arguments are passed
if [ "$#" -ne 2 ]; then
echo "Usage: $0 package_name 'model1,model2,...'"
exit 1
fi
# Arguments
PACKAGE_NAME=$1
MODELS_CSV=$2
DBT_PROJECT_FILE="../dbt_$PACKAGE_NAME/integration_tests/dbt_project.yml"
# Function to add a model to the dbt_project.yml
add_model() {
local model=$1
echo " ${PACKAGE_NAME}_${model}_identifier: \"${model}_data\"" >> "$DBT_PROJECT_FILE"
}
# Check if 'vars' section already exists
if ! grep -q "vars:" "$DBT_PROJECT_FILE"; then
echo "vars:" >> "$DBT_PROJECT_FILE"
fi
# Check if package section exists under 'vars'
if ! grep -q " $PACKAGE_NAME:" "$DBT_PROJECT_FILE"; then
echo " $PACKAGE_NAME:" >> "$DBT_PROJECT_FILE"
fi
# Convert CSV string to newline separated and loop over each model
echo "$MODELS_CSV" | tr ',' '\n' | while read -r model; do
if [ ! -z "$model" ]; then
add_model "$model"
fi
done
echo Updated integration_tests/dbt_project.yml with specific configs