generated from ministryofjustice/hmpps-template-typescript
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rename-project.bash
executable file
·88 lines (70 loc) · 3.9 KB
/
rename-project.bash
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
#!/usr/bin/env bash
set -e
if ! echo "$BASH_VERSION" | grep -E "^[45]" &>/dev/null; then
echo "Found bash version: $BASH_VERSION"
echo "Ensure you are using bash version 4 or 5"
exit 1
fi
if [[ $# -ge 1 ]]; then
PROJECT_INPUT=$1
SLACK_RELEASES_CHANNEL=$2
SECURITY_ALERTS_SLACK_CHANNEL_ID=$3
NON_PROD_ALERTS_SEVERITY_LABEL=$4
PROD_ALERTS_SEVERITY_LABEL=$5
PRODUCT_ID=$6
else
read -rp "New project name e.g. prison-visits >" PROJECT_INPUT
read -rp "Slack channel for release notifications >" SLACK_RELEASES_CHANNEL
read -rp "Slack channel for pipeline security notifications >" SECURITY_ALERTS_SLACK_CHANNEL_ID
echo "For configurating alert severity labels, please first see https://user-guide.cloud-platform.service.justice.gov.uk/documentation/monitoring-an-app/how-to-create-alarms.html#creating-your-own-custom-alerts"
read -rp "Non-prod k8s alerts. The severity label used by prometheus to route alert notifications to slack >" NON_PROD_ALERTS_SEVERITY_LABEL
read -rp "Production k8s alerts. The severity label used by prometheus to route alert notifications to slack >" PROD_ALERTS_SEVERITY_LABEL
echo "Refer to the developer portal at https://developer-portal.hmpps.service.justice.gov.uk/products to find your product id."
read -rp "Provide an ID for the product this app/component belongs too >" PRODUCT_ID
fi
PROJECT_NAME_LOWER=${PROJECT_INPUT,,} # lowercase
PROJECT_NAME_HYPHENS=${PROJECT_NAME_LOWER// /-} # spaces to hyphens
PROJECT_NAME=${PROJECT_NAME_HYPHENS//[^a-z0-9-]/} # remove all other characters
PROJECT_NAME_WITHOUT_HMPPS=${PROJECT_NAME/hmpps-/} # remove hmpps prefix
read -ra PROJECT_NAME_ARRAY <<<"${PROJECT_NAME//-/ }" # convert to array
PROJECT_DESCRIPTION_HMPPS_LOWER=${PROJECT_NAME_ARRAY[*]^} # convert array back to string thus capitalising first character
PROJECT_DESCRIPTION=${PROJECT_DESCRIPTION_HMPPS_LOWER/Hmpps/HMPPS} # ensure that HMPPS is capitalised
echo "Found: Project of $PROJECT_DESCRIPTION"
echo " Project name of $PROJECT_NAME"
echo "Performing search and replace"
# exclude files that get in the way and don't make any difference
EXCLUDES="( -path ./dist -o -path ./node_modules -o -path ./assets -o -path ./.git -o -path ./rename-project.bash )"
# shellcheck disable=SC2086
find . $EXCLUDES -prune -o -type f -exec sed -i \
-e "s/hmpps-allocate-key-workers-ui/$PROJECT_NAME/g" \
-e "s/allocate-key-workers-ui/$PROJECT_NAME_WITHOUT_HMPPS/g" \
-e "s/HMPPS Allocate Key Workers Ui/$PROJECT_DESCRIPTION/g" {} \;
echo "Performing directory renames"
# move helm stuff to new name
mv "helm_deploy/hmpps-allocate-key-workers-ui" "helm_deploy/$PROJECT_NAME"
# Update helm values.yaml with product ID.
sed -i -z -E \
-e "s/UNASSIGNED/$PRODUCT_ID/" \
helm_deploy/$PROJECT_NAME/values.yaml
# Update helm values files with correct slack channels.
sed -i -z -E \
-e "s/NON_PROD_ALERTS_SEVERITY_LABEL/$NON_PROD_ALERTS_SEVERITY_LABEL/" \
helm_deploy/values-dev.yaml helm_deploy/values-preprod.yaml
sed -i -z -E \
-e "s/PROD_ALERTS_SEVERITY_LABEL/$PROD_ALERTS_SEVERITY_LABEL/" \
helm_deploy/values-prod.yaml
echo "NEEDS TO BE SET MANUALLY"
echo "========================"
echo "DAILY CRON: ${RANDOM_MINUTE} ${RANDOM_HOUR}"
echo "WEEKLY CRON: ${RANDOM_MINUTE2} ${RANDOM_HOUR}"
echo "SLACK CHANNEL: ${SECURITY_ALERTS_SLACK_CHANNEL_ID}"
# TEMPORARILY REMOVED - THIS WILL NEED TO BE DONE MANUALLY UNTIL WE MOVE TO GITHUB ACTIONS BOOTSTRAP
# sed -i -z -E \
# -e "s/on:\n workflow_dispatch:\n schedule:\n - cron: \"19 6/on:\n workflow_dispatch:\n schedule:\n - cron: \"$RANDOM_MINUTE $RANDOM_HOUR/" \
# -e "s/on:\n workflow_dispatch:\n schedule:\n - cron: \"34 6/on:\n workflow_dispatch:\n schedule:\n - cron: \"$RANDOM_MINUTE2 $RANDOM_HOUR/" \
# -e "s/C05J915DX0Q/$SECURITY_ALERTS_SLACK_CHANNEL_ID/" \
# .github/workflows/*
# lastly remove ourselves
rm rename-project.bash
echo "Completed."
echo "Please now review changes"