-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
style: unify Bash code style #5568
Open
jaskfla
wants to merge
27
commits into
dev
Choose a base branch
from
shellharden
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
27 commits
Select commit
Hold shift + click to select a range
80a8957
delete unused variable
jaskfla 0a80dbe
portable shebang for Bash scripts
jaskfla bd6f024
prefer `.` to `source`
jaskfla fa29c90
prefer `echo` without `""` for blank lines
jaskfla 3807364
`download-env-vars`: log in to Bitwarden first
jaskfla 92433da
simplify loop over `*.env.example` files
jaskfla d34a646
convenience variables for ANSI codes/sequences
jaskfla 64b9ac7
inline `then` in `if` header
jaskfla 2213a9a
update env var message to refer to Bitwarden
jaskfla 8702ea2
prettify `download-env-vars` output
jaskfla 73e1797
prettify `backendStartDev.sh` output
jaskfla a1db38f
prettify `dumpDatabase.sh` output
jaskfla 77b76b2
prefer ``[[`` over `[`, and `=` over `==` in Bash
jaskfla 1d10de0
prefer `$(…)` over backtick command substitution
jaskfla 0be5e6f
prettify `patchMvRefereshModule.sh` output
jaskfla 15b43de
prefer single quotes when no variables
jaskfla 507fa83
prefer ``(( ))`` over `[[ ]]` for arithmetic
jaskfla 1160b28
prefer array over string in `buildNonInternalDeps`
jaskfla 0ba73f1
prefer array for `getDeployablePackages.sh`
jaskfla ca00437
refactor: clearer way to get current branch
jaskfla 97c51d6
double-quote variables, avoiding `${…}`
jaskfla 090d23c
prefer array in `mergeEnvForDB.sh`
jaskfla 8da68e4
exit on error
jaskfla cca8b59
Merge branch 'dev' into shellharden
jaskfla 65907a7
Merge branch 'dev' into shellharden
jaskfla 65bc43b
Merge branch 'dev' into shellharden
jaskfla 8cd0e8f
Merge branch 'dev' into shellharden
jaskfla File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
13 changes: 7 additions & 6 deletions
13
packages/data-api/scripts/buildAnalyticsMaterializedView.sh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,17 @@ | ||
#!/bin/bash -e | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
cd scripts | ||
export PGPASSWORD=$DB_PASSWORD | ||
if [[ "$1" == "--force" || "$1" == "-f" ]]; then | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT build_analytics_table(true);" | ||
if [[ $1 = '--force' || $1 = '-f' ]]; then | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT build_analytics_table(true);" | ||
else | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT build_analytics_table();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT build_analytics_table();" | ||
fi | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT create_analytics_table_indexes();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT create_analytics_table_indexes();" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
#!/bin/bash -e | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
cd scripts | ||
export PGPASSWORD=$DB_PASSWORD | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT drop_analytics_table();" | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT drop_analytics_log_tables();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT drop_analytics_table();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT drop_analytics_log_tables();" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
#!/bin/bash -e | ||
echo "Fast refreshing analytics table" | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo 'Fast refreshing analytics table' | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
cd scripts | ||
export PGPASSWORD=$DB_PASSWORD | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT mv\$refreshMaterializedView('analytics', 'public', true);" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT mv\$refreshMaterializedView('analytics', 'public', true);" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,16 @@ | ||
#!/bin/bash -e | ||
echo "Fully refreshing analytics table" | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
echo 'Fully refreshing analytics table' | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
cd scripts | ||
export PGPASSWORD=$DB_PASSWORD | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT drop_analytics_table_indexes();" | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT mv\$refreshMaterializedView('analytics', 'public');" | ||
psql -p $DB_PORT -h $DB_URL -d $DB_NAME -U $DB_USER -tc "SELECT create_analytics_table_indexes();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT drop_analytics_table_indexes();" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT mv\$refreshMaterializedView('analytics', 'public');" | ||
psql -p "$DB_PORT" -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -tc "SELECT create_analytics_table_indexes();" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,42 +1,43 @@ | ||
#!/bin/bash | ||
#!/usr/bin/env bash | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/ansiControlSequences.sh" | ||
|
||
COMMAND=$1 | ||
|
||
if [[ "$COMMAND" == "" ]]; then | ||
echo "Error: missing patch command! Must be one of: up, down, create" | ||
if [[ $COMMAND = '' ]]; then | ||
echo "${RED}Error: missing patch command! Must be one of: up, down, create${RESET}" | ||
exit 1 | ||
fi | ||
|
||
if [[ "$COMMAND" == "create" ]]; then | ||
echo "Enter patch name: " | ||
if [[ $COMMAND = create ]]; then | ||
echo 'Enter patch name: ' | ||
read PATCH_NAME | ||
fi | ||
|
||
VERSION=$2 | ||
|
||
if [[ "$VERSION" == "" ]]; then | ||
echo "Version unspecified, defaulting to database mvrefresh version" | ||
if [[ $VERSION = '' ]]; then | ||
echo 'Version unspecified, defaulting to database mvrefresh version' | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
export PGPASSWORD=$DB_PASSWORD | ||
VERSION_SQL_FUNC="SELECT mv\$version()" | ||
VERSION=`psql -p $DB_PORT -X -A -h $DB_URL -d $DB_NAME -U $DB_USER -t -c "$VERSION_SQL_FUNC"` | ||
VERSION=$(psql -p "$DB_PORT" -X -A -h "$DB_URL" -d "$DB_NAME" -U "$DB_USER" -t -c "$VERSION_SQL_FUNC") | ||
|
||
if [[ "$VERSION" == "" ]]; then | ||
echo "Error: failed to detect mvrefresh version from database" | ||
if [[ $VERSION = '' ]]; then | ||
echo "${RED}Error: failed to detect mvrefresh version from database${RESET}" | ||
exit 1 | ||
fi | ||
|
||
echo "Using version: $VERSION" | ||
echo "Using version: ${BOLD}${GREEN}$VERSION${RESET}" | ||
fi | ||
|
||
if [[ ! -d "./scripts/patches/$VERSION" && ! "$COMMAND" == "create" ]]; then | ||
if [[ ! -d ./scripts/patches/$VERSION && $COMMAND != create ]]; then | ||
echo "No patches exist for version: $VERSION, skipping" | ||
else | ||
ts-node ./scripts/patchMvRefresh.ts $COMMAND:$VERSION $PATCH_NAME --migrations-dir "./scripts/patches" --table "patches" -v --config-file "../../babel.config.json" | ||
ts-node ./scripts/patchMvRefresh.ts $COMMAND:$VERSION $PATCH_NAME --migrations-dir './scripts/patches' --table 'patches' -v --config-file '../../babel.config.json' | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,22 @@ | ||
#!/bin/bash -e | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/ansiControlSequences.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DATA_LAKE_DB_PORT:=5432}" | ||
|
||
if [ "$(PGPASSWORD=$DB_PG_PASSWORD psql -p $DATA_LAKE_DB_PORT -X -A -h $DATA_LAKE_DB_URL -U $DB_PG_USER -t -c "SELECT 1 FROM pg_database WHERE datname='$DATA_LAKE_DB_NAME'" )" = '1' ] | ||
then | ||
if [[ "$(PGPASSWORD=$DB_PG_PASSWORD psql -p $DATA_LAKE_DB_PORT -X -A -h $DATA_LAKE_DB_URL -U $DB_PG_USER -t -c "SELECT 1 FROM pg_database WHERE datname='$DATA_LAKE_DB_NAME'" )" = '1' ]]; then | ||
exit 0 | ||
fi | ||
|
||
echo -e "Error: $DATA_LAKE_DB_NAME database does not exist!\n\nTo create it, please get the .env file from Bitwarden then run:\nyarn workspace @tupaia/data-lake-api setup-test-data-lake\n" | ||
echo -e "${RED}Error: $DATA_LAKE_DB_NAME database does not exist!${RESET}" | ||
echo 'To create it, make sure you have the environment variables from Bitwarden and run:' | ||
echo | ||
echo -e " ${BOLD}yarn workspace @tupaia/data-lake-api setup-test-data-lake${RESET}" | ||
echo | ||
echo -e "If you’re missing environment variables, see ${MAGENTA}https://beyond-essential.slab.com/posts/tupaia-monorepo-setup-v5egpdpq#hvfnz-set-environment-variables${RESET}." | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,22 @@ | ||
#!/bin/bash -e | ||
#!/usr/bin/env bash | ||
set -e | ||
|
||
DIR=$(pwd "$0") | ||
source "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
. "$DIR/../../scripts/bash/ansiControlSequences.sh" | ||
. "$DIR/../../scripts/bash/mergeEnvForDB.sh" | ||
|
||
# Set default port in case it wasn't in .env | ||
: "${DB_PORT:=5432}" | ||
|
||
if [ "$(PGPASSWORD=$DB_PG_PASSWORD psql -p $DB_PORT -X -A -h $DB_URL -U $DB_PG_USER -t -c "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" )" = '1' ] | ||
then | ||
if [ "$(PGPASSWORD=$DB_PG_PASSWORD psql -p $DB_PORT -X -A -h $DB_URL -U $DB_PG_USER -t -c "SELECT 1 FROM pg_database WHERE datname='$DB_NAME'" )" = '1' ]; then | ||
exit 0 | ||
fi | ||
|
||
echo -e "\033[31mError: $DB_NAME database does not exist!\033[m" | ||
echo "To create it, get the .env file from Bitwarden then run:" | ||
echo "" | ||
echo -e " \033[1myarn workspace @tupaia/database setup-test-database\033[m" | ||
echo "" | ||
echo -e "${RED}Error: $DB_NAME database does not exist!${RESET}" | ||
echo 'To create it, make sure you have the environment variables from Bitwarden and run:' | ||
echo | ||
echo -e " ${BOLD}yarn workspace @tupaia/database setup-test-database${RESET}" | ||
echo | ||
echo -e "If you’re missing environment variables, see ${MAGENTA}https://beyond-essential.slab.com/posts/tupaia-monorepo-setup-v5egpdpq#hvfnz-set-environment-variables${RESET}." | ||
|
||
exit 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Immediately overwritten in line 4