Skip to content

Commit

Permalink
chore(scripts): Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
AndesKrrrrrrrrrrr committed Oct 2, 2024
1 parent 0e45aa5 commit 5e883df
Show file tree
Hide file tree
Showing 36 changed files with 177 additions and 171 deletions.
18 changes: 9 additions & 9 deletions apps/financial-aid/api/scripts/run-xroad-proxy.sh
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/bin/bash

INSTANCE_ID=$(
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=Bastion Host" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--region eu-west-1 \
--output text
aws ec2 describe-instances \
--filters "Name=tag:Name,Values=Bastion Host" "Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--region eu-west-1 \
--output text
)

echo "Starting port forwarding session with instance $INSTANCE_ID for profile $AWS_PROFILE"

aws ssm start-session \
--target "$INSTANCE_ID" \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["8081"],"localPortNumber":["5050"]}' \
--region eu-west-1
--target "$INSTANCE_ID" \
--document-name AWS-StartPortForwardingSession \
--parameters '{"portNumber":["8081"],"localPortNumber":["5050"]}' \
--region eu-west-1
54 changes: 27 additions & 27 deletions apps/services/search-indexer/bin/generate-es-config.sh
Original file line number Diff line number Diff line change
@@ -1,60 +1,60 @@
#!/usr/bin/env bash

APP="$0"
APPDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
APPDIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

usage() {
echo "Usage: $APP language type [ > template.js ]"
echo -e "\tlanguage: is|en|..."
echo -e "\ttype: slim|full"
echo "Usage: $APP language type [ > template.js ]"
echo -e "\tlanguage: is|en|..."
echo -e "\ttype: slim|full"
}

if [ "$1" == "" ]; then
echo "Error: missing language"
usage
exit 1
echo "Error: missing language"
usage
exit 1
fi

if [[ "$2" != "slim" ]] && [[ "$2" != "full" ]]; then
echo "Error: wrong type: $2"
usage
exit 1
echo "Error: wrong type: $2"
usage
exit 1
fi

TEMPLATE="$APPDIR/../config/template-is.json"

if [ ! -f "$TEMPLATE" ]; then
echo "Error: could not find template file: '$TEMPLATE'"
exit 1
echo "Error: could not find template file: '$TEMPLATE'"
exit 1
fi

JQ="$(which jq)"
if [ ! -x "$JQ" ]; then
echo "Error: could not find 'jq'. Please install"
exit 1
echo "Error: could not find 'jq'. Please install"
exit 1
fi

replace_slim() {
sed -E 's@"rules_path":.*?(,?\s*)$@"rules": []\1@' | \
sed -E 's@"stopwords_path":.*?(,?\s*)$@"stopwords": []\1@' | \
sed -E 's@"keywords_path":.*?(,?\s*)$@"keywords": []\1@' | \
sed -E 's@"synonyms_path":.*?(,?\s*)$@"synonyms": []\1@'
sed -E 's@"rules_path":.*?(,?\s*)$@"rules": []\1@' |
sed -E 's@"stopwords_path":.*?(,?\s*)$@"stopwords": []\1@' |
sed -E 's@"keywords_path":.*?(,?\s*)$@"keywords": []\1@' |
sed -E 's@"synonyms_path":.*?(,?\s*)$@"synonyms": []\1@'
}

replace_full() {
sed -E 's@"rules_path":.*?(,?\s*)$@"rules_path": "analysis/stemmer.txt"\1@' | \
sed -E 's@"stopwords_path":.*?(,?\s*)$@"stopwords_path": "analysis/stopwords.txt"\1@' | \
sed -E 's@"keywords_path":.*?(,?\s*)$@"keywords_path": "analysis/keywords.txt"\1@' | \
sed -E 's@"synonyms_path":.*?(,?\s*)$@"synonyms_path": "analysis/synonyms.txt"\1@'
sed -E 's@"rules_path":.*?(,?\s*)$@"rules_path": "analysis/stemmer.txt"\1@' |
sed -E 's@"stopwords_path":.*?(,?\s*)$@"stopwords_path": "analysis/stopwords.txt"\1@' |
sed -E 's@"keywords_path":.*?(,?\s*)$@"keywords_path": "analysis/keywords.txt"\1@' |
sed -E 's@"synonyms_path":.*?(,?\s*)$@"synonyms_path": "analysis/synonyms.txt"\1@'
}

main() {
# local lang="$1"
local type="$2"
local func="replace_$type"
# local lang="$1"
local type="$2"
local func="replace_$type"

jq '.settings, .mappings' < "$TEMPLATE" | $func
jq '.settings, .mappings' <"$TEMPLATE" | $func

}

main "$1" "$2"
main "$1" "$2"
6 changes: 3 additions & 3 deletions infra/scripts/build-docker-container.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash
set -euo pipefail
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

DOCKER_REGISTRY=${DOCKER_REGISTRY:-821090935708.dkr.ecr.eu-west-1.amazonaws.com/}
PUBLISH=${PUBLISH:-false}
Expand All @@ -10,6 +10,6 @@ DOCKER_TAG=$1
# shellcheck disable=SC2086
docker build -f "$DIR"/Dockerfile ${EXTRA_DOCKER_BUILD_ARGS:-} -t "$DOCKER_IMAGE":"${DOCKER_TAG}" "$DIR"/../..

if [[ "true" = "$PUBLISH" ]] ; then
docker push "$DOCKER_IMAGE":"${DOCKER_TAG}"
if [[ "true" = "$PUBLISH" ]]; then
docker push "$DOCKER_IMAGE":"${DOCKER_TAG}"
fi
11 changes: 7 additions & 4 deletions infra/scripts/ci/diff-chart-values-all-charts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@
### Use for local testing - this will run tests for all the charts sequentially
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT=$DIR/../../..

for chart in $(cd "$ROOT" ; python -c 'import os, json; print(" ".join([os.path.splitext(f)[0] for f in os.listdir("infra/src/uber-charts/")]))'); do
"$DIR"/diff-chart-values.sh "$chart"
done
for chart in $(
cd "$ROOT"
python -c 'import os, json; print(" ".join([os.path.splitext(f)[0] for f in os.listdir("infra/src/uber-charts/")]))'
); do
"$DIR"/diff-chart-values.sh "$chart"
done
22 changes: 11 additions & 11 deletions infra/scripts/ci/diff-chart-values.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT="$DIR/../.."
export PATH=$ROOT/node_modules/.bin:$PATH

case "$1" in
"islandis" | "judicial-system" | "air-discount-scheme" | 'identity-server')
ENVS=("dev" "staging" "prod")
cd "$ROOT"
for env in "${ENVS[@]}"; do
node -r esbuild-register "$ROOT"/src/cli/cli render-env --chart="$1" --env="${env}" | diff "$ROOT"/../charts/"$1"/values."${env}".yaml -
done
;;
*)
echo "No diffing support for $1 yet or ever"
;;
"islandis" | "judicial-system" | "air-discount-scheme" | 'identity-server')
ENVS=("dev" "staging" "prod")
cd "$ROOT"
for env in "${ENVS[@]}"; do
node -r esbuild-register "$ROOT"/src/cli/cli render-env --chart="$1" --env="${env}" | diff "$ROOT"/../charts/"$1"/values."${env}".yaml -
done
;;
*)
echo "No diffing support for $1 yet or ever"
;;
esac
1 change: 0 additions & 1 deletion infra/scripts/ci/git-check-dirty.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@ if [[ $(git diff --stat "$abs_path") != '' ]]; then
else
echo "found no unstaged files from $action, nothing to commit"
fi

7 changes: 5 additions & 2 deletions infra/scripts/ci/test-unit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ set -euxo pipefail

# Run code tests

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT="$DIR/../.."

(cd "$ROOT"; "$ROOT"/node_modules/.bin/jest)
(
cd "$ROOT"
"$ROOT"/node_modules/.bin/jest
)
13 changes: 6 additions & 7 deletions infra/scripts/container-scripts/destroy-dbs.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,14 @@ export PGPASSWORD
set -x
FEATURE_NAME=$1


psql -tc "SELECT datname FROM pg_database WHERE datname like 'feature_${FEATURE_NAME}_%'" --field-separator ' ' --no-align --quiet \
| while read -r dbname; do
psql -tc "SELECT datname FROM pg_database WHERE datname like 'feature_${FEATURE_NAME}_%'" --field-separator ' ' --no-align --quiet |
while read -r dbname; do
psql -c "DROP DATABASE $dbname"
done
done

psql -tc "SELECT rolname FROM pg_roles WHERE rolname like 'feature_${FEATURE_NAME}_%'" --field-separator ' ' --no-align --quiet \
| while read -r rolname; do
psql -tc "SELECT rolname FROM pg_roles WHERE rolname like 'feature_${FEATURE_NAME}_%'" --field-separator ' ' --no-align --quiet |
while read -r rolname; do
psql -c "DROP USER $rolname"
done
done

node secrets delete /k8s/feature-"$FEATURE_NAME"-
2 changes: 1 addition & 1 deletion infra/scripts/format-yaml.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT="$DIR/.."

cd "$ROOT"
Expand Down
21 changes: 10 additions & 11 deletions infra/scripts/helm-diff.sh
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,24 @@
# - pip install --upgrade ydiff
# https://github.com/ymattw/ydiff

if ! command -v ydiff &> /dev/null
then
echo "Please install ydiff via pip or brew"
echo "https://github.com/ymattw/ydiff"
exit 1
if ! command -v ydiff &>/dev/null; then
echo "Please install ydiff via pip or brew"
echo "https://github.com/ymattw/ydiff"
exit 1
fi

if [ -z "${1}" ]; then
echo "Specify older commit/tag/branch"
exit 1
echo "Specify older commit/tag/branch"
exit 1
fi
if [ -z "${2}" ]; then
echo "Specify newer commit/tag/branch"
exit 1
echo "Specify newer commit/tag/branch"
exit 1
fi

# curl https://api.github.com/repos/island-is/island.is/contents/charts/islandis/values.prod.yaml | jq -r ".content" | base64 --decode
curl -s -H "Accept: application/json" 'https://api.github.com/repos/island-is/island.is/contents/charts/islandis/values.prod.yaml?ref='${1}'' | jq -r ".content" | base64 --decode > current-release.json
curl -s -H "Accept: application/json" 'https://api.github.com/repos/island-is/island.is/contents/charts/islandis/values.prod.yaml?ref='${2}'' | jq -r ".content" | base64 --decode > new-release.json
curl -s -H "Accept: application/json" 'https://api.github.com/repos/island-is/island.is/contents/charts/islandis/values.prod.yaml?ref='${1}'' | jq -r ".content" | base64 --decode >current-release.json
curl -s -H "Accept: application/json" 'https://api.github.com/repos/island-is/island.is/contents/charts/islandis/values.prod.yaml?ref='${2}'' | jq -r ".content" | base64 --decode >new-release.json
diff -u ./current-release.json ./new-release.json | ydiff -w 0 -s
rm -f ./new-release.json
rm -f ./current-release.json
12 changes: 6 additions & 6 deletions scripts/ci/00_prepare-base-tags.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"
ROOT="$DIR/../.."

tempRepo=$(mktemp -d 2>/dev/null || mktemp -d -t 'mytmpdir')
Expand All @@ -10,7 +10,7 @@ cp -r "$ROOT/.github/actions/dist/." "$tempRepo"
LAST_GOOD_BUILD=$(DEBUG="*,-simple-git" REPO_ROOT="$ROOT" node $tempRepo/main.js)
if echo "$LAST_GOOD_BUILD" | grep -q 'full_rebuild_needed'; then
export NX_AFFECTED_ALL=true
echo "NX_AFFECTED_ALL=$NX_AFFECTED_ALL" >> $GITHUB_ENV
echo "NX_AFFECTED_ALL=$NX_AFFECTED_ALL" >>$GITHUB_ENV
exit 0
fi
echo "Stickman done"
Expand All @@ -23,13 +23,13 @@ if [[ "$BUILD_REF" != "$LAST_GOOD_BUILD_SHA" ]]; then
echo "This will be an incremental build from a previous successful run in this PR. See parents of the commit below."
git log -1 "$BUILD_REF"
fi
LAST_GOOD_BUILD_DOCKER_BRANCH_TAG=$(echo "${LAST_GOOD_BUILD_BRANCH}" | tr "/." "-" )
LAST_GOOD_BUILD_DOCKER_BRANCH_TAG=$(echo "${LAST_GOOD_BUILD_BRANCH}" | tr "/." "-")
export LAST_GOOD_BUILD_DOCKER_TAG=${LAST_GOOD_BUILD_DOCKER_BRANCH_TAG:0:45}_${LAST_GOOD_BUILD_SHA:0:10}_${LAST_GOOD_BUILD_RUN_NUMBER}
if [[ "$BUILD_REF" == "null" || "$BUILD_REF" == "" ]]; then
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Change detection failed for $HTML_URL\"}" "$ISSUE_REPORTING_SLACK_WEBHOOK_URL"
exit 1
curl -X POST -H 'Content-type: application/json' --data "{\"text\":\"Change detection failed for $HTML_URL\"}" "$ISSUE_REPORTING_SLACK_WEBHOOK_URL"
exit 1
else
BASE="$BUILD_REF"
BASE="$BUILD_REF"
fi
export BASE
>&2 echo "Last successful docker tag '$LAST_GOOD_BUILD_DOCKER_TAG'"
2 changes: 1 addition & 1 deletion scripts/ci/10_prepare-docker-deps.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh
Expand Down
4 changes: 2 additions & 2 deletions scripts/ci/10_prepare-host-deps.sh
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh

yarn install --immutable
yarn install --immutable
2 changes: 1 addition & 1 deletion scripts/ci/20_check-formatting.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
set -euxo pipefail
action=${1:-"check"}
yarn nx format:"${action}" --all
yarn nx format:"${action}" --all
5 changes: 2 additions & 3 deletions scripts/ci/30_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ else
IS_FLAKY_TEST=false
fi


projects_uncollectible_coverage=(
"application-templates-no-debt-certificate"
"api-domains-email-signup"
Expand All @@ -48,10 +47,10 @@ export DD_CIVISIBILITY_AGENTLESS_ENABLED \

FLAKY_TEST_RETRIES=$(if [[ "$IS_FLAKY_TEST" == true ]]; then echo "$FLAKY_TEST_RETRIES"; else echo 1; fi)

for ((i=1; i<=FLAKY_TEST_RETRIES; i++)); do
for ((i = 1; i <= FLAKY_TEST_RETRIES; i++)); do
echo "Running test ${APP} (attempt: ${i}/${FLAKY_TEST_RETRIES})"
if yarn run test "${APP}" ${EXTRA_OPTS} --verbose --no-watchman "$@"; then
exit 0
fi
done
exit 1
exit 1
4 changes: 2 additions & 2 deletions scripts/ci/50_upload-coverage.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh
Expand All @@ -16,7 +16,7 @@ if [[ ! -f "$COVERAGE_FILE" ]]; then
exit 0
fi

COVERAGE_CONTENT=$(jq "." -cr < $COVERAGE_FILE)
COVERAGE_CONTENT=$(jq "." -cr <$COVERAGE_FILE)
if [[ "$COVERAGE_CONTENT" == "{}" ]]; then
echo "Coverage report is empty"
exit 0
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/90_docker-express.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/90_docker-jest.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh
Expand Down
2 changes: 1 addition & 1 deletion scripts/ci/90_docker-next.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash
set -euxo pipefail

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)"

# shellcheck disable=SC1091
source "$DIR"/_common.sh
Expand Down
Loading

0 comments on commit 5e883df

Please sign in to comment.