diff --git a/apps/financial-aid/api/scripts/run-xroad-proxy.sh b/apps/financial-aid/api/scripts/run-xroad-proxy.sh index edb2e6ef14f5..ba1fd41f25f8 100755 --- a/apps/financial-aid/api/scripts/run-xroad-proxy.sh +++ b/apps/financial-aid/api/scripts/run-xroad-proxy.sh @@ -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 diff --git a/apps/services/search-indexer/bin/generate-es-config.sh b/apps/services/search-indexer/bin/generate-es-config.sh index dd9ebe9d0a63..fa3c86eb0649 100755 --- a/apps/services/search-indexer/bin/generate-es-config.sh +++ b/apps/services/search-indexer/bin/generate-es-config.sh @@ -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" \ No newline at end of file +main "$1" "$2" diff --git a/infra/scripts/build-docker-container.sh b/infra/scripts/build-docker-container.sh index 60ab6f876241..460fb419fd26 100755 --- a/infra/scripts/build-docker-container.sh +++ b/infra/scripts/build-docker-container.sh @@ -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} @@ -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 diff --git a/infra/scripts/ci/diff-chart-values-all-charts.sh b/infra/scripts/ci/diff-chart-values-all-charts.sh index 992655ad4019..b38d583f238e 100755 --- a/infra/scripts/ci/diff-chart-values-all-charts.sh +++ b/infra/scripts/ci/diff-chart-values-all-charts.sh @@ -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 \ No newline at end of file +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 diff --git a/infra/scripts/ci/diff-chart-values.sh b/infra/scripts/ci/diff-chart-values.sh index 5748c8425308..4eb0e39d3e25 100755 --- a/infra/scripts/ci/diff-chart-values.sh +++ b/infra/scripts/ci/diff-chart-values.sh @@ -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 diff --git a/infra/scripts/ci/git-check-dirty.sh b/infra/scripts/ci/git-check-dirty.sh index f15b15843022..8bbf2a5c2a9b 100755 --- a/infra/scripts/ci/git-check-dirty.sh +++ b/infra/scripts/ci/git-check-dirty.sh @@ -34,4 +34,3 @@ if [[ $(git diff --stat "$abs_path") != '' ]]; then else echo "found no unstaged files from $action, nothing to commit" fi - diff --git a/infra/scripts/ci/test-unit.sh b/infra/scripts/ci/test-unit.sh index 960e68957b07..9e2ed8fe9844 100755 --- a/infra/scripts/ci/test-unit.sh +++ b/infra/scripts/ci/test-unit.sh @@ -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 +) diff --git a/infra/scripts/container-scripts/destroy-dbs.sh b/infra/scripts/container-scripts/destroy-dbs.sh index e410925d8155..c52d1b226a51 100755 --- a/infra/scripts/container-scripts/destroy-dbs.sh +++ b/infra/scripts/container-scripts/destroy-dbs.sh @@ -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"- diff --git a/infra/scripts/format-yaml.sh b/infra/scripts/format-yaml.sh index 809cd91f36a3..b77cfe44af01 100755 --- a/infra/scripts/format-yaml.sh +++ b/infra/scripts/format-yaml.sh @@ -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" diff --git a/infra/scripts/helm-diff.sh b/infra/scripts/helm-diff.sh index 94252e806779..b856f6b13ab5 100755 --- a/infra/scripts/helm-diff.sh +++ b/infra/scripts/helm-diff.sh @@ -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 diff --git a/scripts/ci/00_prepare-base-tags.sh b/scripts/ci/00_prepare-base-tags.sh index 0646576795c9..00f58ac95dae 100755 --- a/scripts/ci/00_prepare-base-tags.sh +++ b/scripts/ci/00_prepare-base-tags.sh @@ -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') @@ -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" @@ -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'" diff --git a/scripts/ci/10_prepare-docker-deps.sh b/scripts/ci/10_prepare-docker-deps.sh index d0513560c150..e35bd21c9891 100755 --- a/scripts/ci/10_prepare-docker-deps.sh +++ b/scripts/ci/10_prepare-docker-deps.sh @@ -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 diff --git a/scripts/ci/10_prepare-host-deps.sh b/scripts/ci/10_prepare-host-deps.sh index 8a879ba4415d..878e49b66b0d 100755 --- a/scripts/ci/10_prepare-host-deps.sh +++ b/scripts/ci/10_prepare-host-deps.sh @@ -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 \ No newline at end of file +yarn install --immutable diff --git a/scripts/ci/20_check-formatting.sh b/scripts/ci/20_check-formatting.sh index d43b2b4f403c..6759377120b4 100755 --- a/scripts/ci/20_check-formatting.sh +++ b/scripts/ci/20_check-formatting.sh @@ -1,4 +1,4 @@ #!/bin/bash set -euxo pipefail action=${1:-"check"} -yarn nx format:"${action}" --all \ No newline at end of file +yarn nx format:"${action}" --all diff --git a/scripts/ci/30_test.sh b/scripts/ci/30_test.sh index 1d760b6e021d..1e41c58fd19d 100755 --- a/scripts/ci/30_test.sh +++ b/scripts/ci/30_test.sh @@ -25,7 +25,6 @@ else IS_FLAKY_TEST=false fi - projects_uncollectible_coverage=( "application-templates-no-debt-certificate" "api-domains-email-signup" @@ -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 \ No newline at end of file +exit 1 diff --git a/scripts/ci/50_upload-coverage.sh b/scripts/ci/50_upload-coverage.sh index 2db6866bee36..cbc62bb8d0e3 100755 --- a/scripts/ci/50_upload-coverage.sh +++ b/scripts/ci/50_upload-coverage.sh @@ -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 @@ -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 diff --git a/scripts/ci/90_docker-express.sh b/scripts/ci/90_docker-express.sh index ebc6212b9584..3c81fe76b117 100755 --- a/scripts/ci/90_docker-express.sh +++ b/scripts/ci/90_docker-express.sh @@ -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 diff --git a/scripts/ci/90_docker-jest.sh b/scripts/ci/90_docker-jest.sh index 90ffe36b9bfa..df31e7d441e1 100755 --- a/scripts/ci/90_docker-jest.sh +++ b/scripts/ci/90_docker-jest.sh @@ -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 diff --git a/scripts/ci/90_docker-next.sh b/scripts/ci/90_docker-next.sh index f7b46e824465..ce6a35c27015 100755 --- a/scripts/ci/90_docker-next.sh +++ b/scripts/ci/90_docker-next.sh @@ -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 diff --git a/scripts/ci/90_docker-playwright.sh b/scripts/ci/90_docker-playwright.sh index c26ce2ab7e8f..eb7bd5bb0fc0 100755 --- a/scripts/ci/90_docker-playwright.sh +++ b/scripts/ci/90_docker-playwright.sh @@ -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 diff --git a/scripts/ci/90_docker-static.sh b/scripts/ci/90_docker-static.sh index 8dfec28c98ce..d859c0750451 100755 --- a/scripts/ci/90_docker-static.sh +++ b/scripts/ci/90_docker-static.sh @@ -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 diff --git a/scripts/ci/_common.sh b/scripts/ci/_common.sh index 5f16494aebc4..ae0ad87ffe3a 100755 --- a/scripts/ci/_common.sh +++ b/scripts/ci/_common.sh @@ -1,6 +1,6 @@ #!/bin/bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" BRANCH=${BRANCH:-$(git branch --show-current)} export DOCKER_REGISTRY=${DOCKER_REGISTRY:-} @@ -9,4 +9,4 @@ export DOCKER_BUILDKIT=1 export CHUNK_SIZE=${CHUNK_SIZE:-2} export NODE_OPTIONS="--max-old-space-size=8192" PROJECT_ROOT=$(git -C "$DIR" rev-parse --show-toplevel) -export PROJECT_ROOT BRANCH \ No newline at end of file +export PROJECT_ROOT BRANCH diff --git a/scripts/ci/_nx-affected-targets.sh b/scripts/ci/_nx-affected-targets.sh index 3d861a2a0194..e8d346f9729d 100755 --- a/scripts/ci/_nx-affected-targets.sh +++ b/scripts/ci/_nx-affected-targets.sh @@ -14,7 +14,7 @@ TEST_EVERYTHING=${TEST_EVERYTHING:-} AFFECTED_ALL=${AFFECTED_ALL:-} # Could be used for forcing all projects to be affected (set or create `secret` in GitHub with the name of this variable set to the name of the branch that should be affected, prefixed with the magic string `7913-`) BRANCH=${BRANCH:-$GITHUB_HEAD_REF} -if [[ (-n "$BRANCH" && -n "$AFFECTED_ALL" && "$AFFECTED_ALL" == "7913-$BRANCH") || (-n "$NX_AFFECTED_ALL" && "$NX_AFFECTED_ALL" == "true") || (-n "$TEST_EVERYTHING" && "$TEST_EVERYTHING" == "true")]]; then +if [[ (-n "$BRANCH" && -n "$AFFECTED_ALL" && "$AFFECTED_ALL" == "7913-$BRANCH") || (-n "$NX_AFFECTED_ALL" && "$NX_AFFECTED_ALL" == "true") || (-n "$TEST_EVERYTHING" && "$TEST_EVERYTHING" == "true") ]]; then EXTRA_ARGS="" else EXTRA_ARGS=(--affected --base "$BASE" --head "$HEAD") diff --git a/scripts/ci/cache/generate-files.sh b/scripts/ci/cache/generate-files.sh index c87b4de95536..41bf3fe8f006 100755 --- a/scripts/ci/cache/generate-files.sh +++ b/scripts/ci/cache/generate-files.sh @@ -3,4 +3,4 @@ set -euo pipefail export NODE_OPTIONS=--max-old-space-size=4096 # shellcheck disable=SC2046 -tar zcvf generated_files.tar.gz $(./scripts/ci/get-files-touched-by.sh yarn codegen --skip-cache | xargs realpath --relative-to $(pwd)) \ No newline at end of file +tar zcvf generated_files.tar.gz $(./scripts/ci/get-files-touched-by.sh yarn codegen --skip-cache | xargs realpath --relative-to $(pwd)) diff --git a/scripts/ci/ci.sh b/scripts/ci/ci.sh index 91c0c107be9a..bd20f541479a 100755 --- a/scripts/ci/ci.sh +++ b/scripts/ci/ci.sh @@ -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 diff --git a/scripts/ci/docker-login-ecr.sh b/scripts/ci/docker-login-ecr.sh index a08e8309161b..f3f491abc514 100755 --- a/scripts/ci/docker-login-ecr.sh +++ b/scripts/ci/docker-login-ecr.sh @@ -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 diff --git a/scripts/ci/generate-build-chunks.sh b/scripts/ci/generate-build-chunks.sh index 9fab557ebcd9..41840bf9395a 100755 --- a/scripts/ci/generate-build-chunks.sh +++ b/scripts/ci/generate-build-chunks.sh @@ -1,17 +1,16 @@ #!/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 chunks='[]' -for target in "$@" -do - affected_chunks=$("$PROJECT_ROOT"/scripts/ci/generate-chunks.sh $target) - if [[ "$affected_chunks" != "" ]]; then - chunks=$(echo "$chunks" | jq -cM --argjson target "$affected_chunks" '. + ($target | map({projects: ., docker_type: "'$target'"}))') - fi +for target in "$@"; do + affected_chunks=$("$PROJECT_ROOT"/scripts/ci/generate-chunks.sh $target) + if [[ "$affected_chunks" != "" ]]; then + chunks=$(echo "$chunks" | jq -cM --argjson target "$affected_chunks" '. + ($target | map({projects: ., docker_type: "'$target'"}))') + fi done >&2 echo "Map: ${chunks}" diff --git a/scripts/ci/generate-chunks.sh b/scripts/ci/generate-chunks.sh index 502104728e34..c3ca04673ea4 100755 --- a/scripts/ci/generate-chunks.sh +++ b/scripts/ci/generate-chunks.sh @@ -1,15 +1,14 @@ #!/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 BRANCH=${BRANCH:-$GITHUB_HEAD_REF} SKIP_TESTS_ON_BRANCH=${SKIP_TESTS_ON_BRANCH:-} -if [[ "$SKIP_TESTS_ON_BRANCH" == "7913-$BRANCH" ]] -then +if [[ "$SKIP_TESTS_ON_BRANCH" == "7913-$BRANCH" ]]; then #Skipping tests echo "[]" else @@ -19,4 +18,3 @@ else >&2 echo "Chunks: $CHUNKS" echo "$CHUNKS" fi - diff --git a/scripts/ci/list-unaffected.sh b/scripts/ci/list-unaffected.sh index ecfdbe7d8b95..3e1500b66549 100755 --- a/scripts/ci/list-unaffected.sh +++ b/scripts/ci/list-unaffected.sh @@ -2,18 +2,18 @@ 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)" # This script re-tags all unaffected Docker images with the newest tag. UNAFFECTED="" -for TARGET in "$@" -do - AFFECTED=$("$DIR"/_nx-affected-targets.sh $TARGET | tr -d '\n') - ALL=$(AFFECTED_ALL=7913-${BRANCH} "$DIR"/_nx-affected-targets.sh $TARGET | tr -d '\n') +for TARGET in "$@"; do + AFFECTED=$("$DIR"/_nx-affected-targets.sh $TARGET | tr -d '\n') + ALL=$(AFFECTED_ALL=7913-${BRANCH} "$DIR"/_nx-affected-targets.sh $TARGET | tr -d '\n') - UNAFFECTED_ADD=$(node << EOM + UNAFFECTED_ADD=$( + node < e.trim()).filter(e => e.length > 0) const allProjects = "$ALL".split(",").map(e => e.trim()).filter(e => e.length > 0) console.error('All projects: [' + allProjects + ']') @@ -22,10 +22,10 @@ do if (unaffected.length === 0) console.error('Everything is affected') console.log(unaffected.join(' ')) EOM -) - if [[ -n $UNAFFECTED_ADD ]] ; then - UNAFFECTED="$UNAFFECTED $UNAFFECTED_ADD" - fi + ) + if [[ -n $UNAFFECTED_ADD ]]; then + UNAFFECTED="$UNAFFECTED $UNAFFECTED_ADD" + fi done >&2 echo "Unaffected Docker images: ${UNAFFECTED}" diff --git a/scripts/ci/retag-unaffected.sh b/scripts/ci/retag-unaffected.sh index 411b9d5f270a..b9b88c9f4f7a 100755 --- a/scripts/ci/retag-unaffected.sh +++ b/scripts/ci/retag-unaffected.sh @@ -2,7 +2,7 @@ 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)" # This script re-tags all unaffected Docker images with the newest tag. echo "$1" | tr ' ' '\n' | xargs -P 8 -n 1 -I {} bash -c "IMAGE={} $DIR/_retag.sh" # exit code 255 makes xargs fail fast diff --git a/scripts/ci/run-affected-in-parallel.sh b/scripts/ci/run-affected-in-parallel.sh index fd381313ee60..0834a429ec37 100755 --- a/scripts/ci/run-affected-in-parallel.sh +++ b/scripts/ci/run-affected-in-parallel.sh @@ -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 diff --git a/scripts/ci/run-in-parallel-native.sh b/scripts/ci/run-in-parallel-native.sh index b9f17de8bdd4..2427f5afdae0 100755 --- a/scripts/ci/run-in-parallel-native.sh +++ b/scripts/ci/run-in-parallel-native.sh @@ -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 @@ -9,8 +9,7 @@ MAX_JOBS=${MAX_JOBS:-2} AFFECTED_PROJECTS=$(echo "${AFFECTED_PROJECTS}" | tr -d '\n[:space:]') echo "Running '$AFFECTED_PROJECTS' in parallel of ${MAX_JOBS} for target $1" -if [ -n "$AFFECTED_PROJECTS" ] -then +if [ -n "$AFFECTED_PROJECTS" ]; then echo "Affected projects for target $1 are '$AFFECTED_PROJECTS'" yarn run nx run-many --target="$1" --projects="$AFFECTED_PROJECTS" --parallel --maxParallel="$MAX_JOBS" else diff --git a/scripts/ci/run-in-parallel.sh b/scripts/ci/run-in-parallel.sh index e39a41cefeab..53bedb1fc4db 100755 --- a/scripts/ci/run-in-parallel.sh +++ b/scripts/ci/run-in-parallel.sh @@ -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 @@ -10,7 +10,7 @@ MAX_JOBS=${MAX_JOBS:-2} AFFECTED_PROJECTS=$(echo "${AFFECTED_PROJECTS}" | tr '\n,' ' ') echo "Running '$AFFECTED_PROJECTS' in parallel of ${MAX_JOBS} for target $1" -IFS=" " read -ra AFFECTED_PROJECTS <<< "$AFFECTED_PROJECTS" +IFS=" " read -ra AFFECTED_PROJECTS <<<"$AFFECTED_PROJECTS" # This is a helper script to run in parallel a list of provided projects for a specific target exec parallel --halt soon,fail=1 --lb -j "$MAX_JOBS" APP={} "$DIR"/"$1".sh ::: "${AFFECTED_PROJECTS[@]}" diff --git a/scripts/create-secret.sh b/scripts/create-secret.sh index 54165f7f8074..113dff697dd2 100755 --- a/scripts/create-secret.sh +++ b/scripts/create-secret.sh @@ -29,45 +29,45 @@ HAS_SLASH_END="[^\/]" # Complete pattern # PATTERN=$ALPHANUMERIC_DASH$MIN_LENGTH$HAS_SLASH_END$END -__error_exit () { +__error_exit() { # printf "${RED}[ERROR]: $*${NOSTYLE}" >&2; exit 1; - printf "%s[ERROR]: $*%s" "$RED" "$RESET" >&2; exit 1; + printf "%s[ERROR]: $*%s" "$RED" "$RESET" >&2 + exit 1 } -error_empty () { +error_empty() { printf "%sNo empty values %s\n" "$RED" "$RESET" exit 0 } -validate_empty () { - [[ -d $1 ]] || { printf "%sNo empty values%s" "$RED" "$RESET" >&2; exit 1; } +validate_empty() { + [[ -d $1 ]] || { + printf "%sNo empty values%s" "$RED" "$RESET" >&2 + exit 1 + } } -validate_slash () { +validate_slash() { [[ ! $1 =~ $HAS_SLASH_END ]] printf "%sNo ending slash: Ok!%s" "$GREEN" "$RESET" } -validate_whitespace () { - if [ ! ${1+x} ] - then +validate_whitespace() { + if [ ! ${1+x} ]; then error_empty fi # No whitespace - if [[ $1 = "$ILLEGAL_CHARS" ]] - then + if [[ $1 = "$ILLEGAL_CHARS" ]]; then printf "%sWhitespaces are not allowed%s\n" "$RED" "$RESET" exit 0 fi - } +} -validate_chars () { - if [ ! ${1+x} ] - then +validate_chars() { + if [ ! ${1+x} ]; then error_empty fi - if [[ $1 =~ $ALPHANUMERIC_DASH$ONE_OR_MORE ]] - then + if [[ $1 =~ $ALPHANUMERIC_DASH$ONE_OR_MORE ]]; then printf "%sName: Ok! %s\n" "$GREEN" "$RESET" else printf "%sSecret name can only contain letters, numbers, hyphens and underscores %s\n" "$RED" "$RESET" @@ -75,16 +75,14 @@ validate_chars () { fi } -validate_length () { +validate_length() { # Unset parameter is an empty user input - if [ ! ${1+x} ] - then + if [ ! ${1+x} ]; then error_empty fi # Validate minimum length - if ((${#1} < MIN_LENGTH || ${#1} > MAX_LENGTH)) - then + if ((${#1} < MIN_LENGTH || ${#1} > MAX_LENGTH)); then printf "%sToo short, should be 6-256 characters long.%s\n" "$RED" "$RESET" exit 0 else @@ -93,7 +91,7 @@ validate_length () { } #-------------------CREATE SECRET--------------------------# -prepare_secret () { +prepare_secret() { # Prompt user for secret name read -erp "${BLUE}Secret name: ${RESET}${SSM_PREFIX}" SECRET_NAME validate_whitespace "$SECRET_NAME" @@ -107,8 +105,7 @@ prepare_secret () { # Prompt user for secret type read -erp "${BLUE}SecureString [Y/n]? ${RESET}" - if [[ $REPLY =~ ^[Nn]$ ]] - then + if [[ $REPLY =~ ^[Nn]$ ]]; then SECRET_TYPE="String" else SECRET_TYPE="SecureString" @@ -118,13 +115,11 @@ prepare_secret () { # Prompt user for adding tags TAGS="" read -erp "${BLUE}Add tags? [y/N]? ${RESET}" - if [[ $REPLY =~ ^[Yy]$ ]] - then + if [[ $REPLY =~ ^[Yy]$ ]]; then read -erp "${YELLOW}Example: Key=Foo,Value=Bar Key=Another,Value=Tag: ${RESET}" TAGS fi read -erp "${YELLOW}Are you sure [Y/n]? ${RESET}" - if [[ $REPLY =~ ^[Nn]$ ]] - then + if [[ $REPLY =~ ^[Nn]$ ]]; then printf "%sAborting...%s" "$RED" "$RESET" else printf "%sCreating secret....%s\n" "$GREEN" "$RESET" @@ -132,15 +127,14 @@ prepare_secret () { fi } -create_secret () { +create_secret() { SECRET_NAME=$1 SECRET_VALUE=$2 SECRET_TYPE=$3 TAGS=$4 CMD="aws ssm put-parameter --name $SSM_PREFIX$SECRET_NAME --value $SECRET_VALUE --type $SECRET_TYPE" - if [ -n "$TAGS" ] - then + if [ -n "$TAGS" ]; then CMD="$CMD --tags $TAGS" fi eval "$CMD" @@ -148,11 +142,26 @@ create_secret () { } case $1 in - validate_length) "$@"; exit;; - validate_chars) "$@"; exit;; - validate_whitespace) "$@"; exit;; - validate_empty) "$@"; exit;; - __error_exit) "$@"; exit;; +validate_length) + "$@" + exit + ;; +validate_chars) + "$@" + exit + ;; +validate_whitespace) + "$@" + exit + ;; +validate_empty) + "$@" + exit + ;; +__error_exit) + "$@" + exit + ;; esac prepare_secret diff --git a/scripts/dockerfile-assets/bash/extract-environment.sh b/scripts/dockerfile-assets/bash/extract-environment.sh index de404e339b13..45fdfd95efc1 100755 --- a/scripts/dockerfile-assets/bash/extract-environment.sh +++ b/scripts/dockerfile-assets/bash/extract-environment.sh @@ -1,5 +1,5 @@ #!/bin/bash -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" +DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd)" node "$DIR/extract-environment.js" "$@" diff --git a/scripts/stop-test-proxies.sh b/scripts/stop-test-proxies.sh index 51b852eab4ff..e209e5bb32f2 100755 --- a/scripts/stop-test-proxies.sh +++ b/scripts/stop-test-proxies.sh @@ -12,9 +12,8 @@ function stop_proxy() { builder=${1:-docker} -array=( socat-xroad es-proxy ) +array=(socat-xroad es-proxy) -for proxy in "${array[@]}" -do +for proxy in "${array[@]}"; do stop_proxy "${proxy}" "${builder}" || true done