diff --git a/.circleci/config.yml b/.circleci/config.yml index 3eb422fce59..afc73c7ace2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -127,6 +127,15 @@ jobs: name: Lint Go command: 'make lint-go' + shellcheck: + machine: true + working_directory: ~/go/src/github.com/grafana/grafana + steps: + - checkout + - run: + name: ShellCheck + command: 'make shellcheck' + test-frontend: docker: - image: circleci/node:10 @@ -650,6 +659,8 @@ workflows: filters: *filter-only-master - lint-go: filters: *filter-only-master + - shellcheck: + filters: *filter-only-master - test-frontend: filters: *filter-only-master - test-backend: @@ -665,6 +676,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test - build-oss-msi @@ -677,6 +689,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test filters: *filter-only-master @@ -687,6 +700,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test - build-all-enterprise @@ -698,6 +712,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test filters: *filter-only-master @@ -724,6 +739,8 @@ workflows: filters: *filter-only-release - lint-go: filters: *filter-only-release + - shellcheck: + filters: *filter-only-release - test-frontend: filters: *filter-only-release - test-backend: @@ -739,6 +756,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test - build-oss-msi @@ -751,6 +769,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test filters: *filter-only-release @@ -762,6 +781,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test filters: *filter-only-release @@ -772,6 +792,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test filters: *filter-only-release @@ -791,6 +812,10 @@ workflows: filters: *filter-not-release-or-master - lint-go: filters: *filter-not-release-or-master + - lint-go: + filters: *filter-not-release-or-master + - shellcheck: + filters: *filter-not-release-or-master - test-frontend: filters: *filter-not-release-or-master - test-backend: @@ -808,6 +833,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test - cache-server-test @@ -819,6 +845,7 @@ workflows: - test-frontend - codespell - lint-go + - shellcheck - mysql-integration-test - postgres-integration-test - cache-server-test diff --git a/Makefile b/Makefile index e0f1eec84cc..1e895186b79 100644 --- a/Makefile +++ b/Makefile @@ -4,6 +4,7 @@ GO = GO111MODULE=on go GO_FILES ?= ./pkg/... +SH_FILES ?= $(shell find ./scripts -name *.sh) all: deps build @@ -111,6 +112,11 @@ go-vet: lint-go: go-vet golangci-lint revive revive-alerting gosec +# with disabled SC1071 we are ignored some TCL,Expect `/usr/bin/env expect` scripts +shellcheck: $(SH_FILES) + @docker run --rm -v "$$PWD:/mnt" koalaman/shellcheck:stable \ + $(SH_FILES) -e SC1071 + run: scripts/go/bin/bra @scripts/go/bin/bra run diff --git a/scripts/build/build-all.sh b/scripts/build/build-all.sh index 2d71c21dc69..f45bc73b5b2 100755 --- a/scripts/build/build-all.sh +++ b/scripts/build/build-all.sh @@ -6,6 +6,7 @@ set -e +# shellcheck disable=SC2124 EXTRA_OPTS="$@" CCARMV6=/opt/rpi-tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-gcc @@ -15,9 +16,6 @@ CCOSX64=/tmp/osxcross/target/bin/o64-clang CCWIN64=x86_64-w64-mingw32-gcc CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc -GOPATH=/go -REPO_PATH=$GOPATH/src/github.com/grafana/grafana - cd /go/src/github.com/grafana/grafana echo "current dir: $(pwd)" @@ -34,16 +32,16 @@ echo "current dir: $(pwd)" # build only amd64 for enterprise if echo "$EXTRA_OPTS" | grep -vq enterprise ; then - go run build.go -goarch armv6 -cc ${CCARMV6} ${OPT} build - go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build - go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build - go run build.go -goos darwin -cc ${CCOSX64} ${OPT} build + go run build.go -goarch armv6 -cc "${CCARMV6}" "${OPT}" build + go run build.go -goarch armv7 -cc "${CCARMV7}" "${OPT}" build + go run build.go -goarch arm64 -cc "${CCARM64}" "${OPT}" build + go run build.go -goos darwin -cc "${CCOSX64}" "${OPT}" build fi -go run build.go -goos windows -cc ${CCWIN64} ${OPT} build +go run build.go -goos windows -cc "${CCWIN64}" "${OPT}" build # Do not remove CC from the linux build, its there for compatibility with Centos6 -CC=${CCX64} go run build.go ${OPT} build +CC=${CCX64} go run build.go "${OPT}" build yarn install --pure-lockfile --no-progress @@ -53,35 +51,36 @@ else echo "Building frontend and packaging incremental build for $CIRCLE_BRANCH" fi echo "Building frontend" -go run build.go ${OPT} build-frontend +go run build.go "${OPT}" build-frontend if [ -d "dist" ]; then rm -rf dist fi mkdir dist -go run build.go -gen-version ${OPT} > dist/grafana.version +go run build.go -gen-version "${OPT}" > dist/grafana.version # Load ruby, needed for packing with fpm +# shellcheck disable=SC1091 source /etc/profile.d/rvm.sh echo "Packaging" -go run build.go -goos linux -pkg-arch amd64 ${OPT} package-only +go run build.go -goos linux -pkg-arch amd64 "${OPT}" package-only #removing amd64 phantomjs bin for armv7/arm64 packages rm tools/phantomjs/phantomjs # build only amd64 for enterprise if echo "$EXTRA_OPTS" | grep -vq enterprise ; then - go run build.go -goos linux -pkg-arch armv6 ${OPT} -skipRpm package-only - go run build.go -goos linux -pkg-arch armv7 ${OPT} package-only - go run build.go -goos linux -pkg-arch arm64 ${OPT} package-only + go run build.go -goos linux -pkg-arch armv6 "${OPT}" -skipRpm package-only + go run build.go -goos linux -pkg-arch armv7 "${OPT}" package-only + go run build.go -goos linux -pkg-arch arm64 "${OPT}" package-only if [ -d '/tmp/phantomjs/darwin' ]; then cp /tmp/phantomjs/darwin/phantomjs tools/phantomjs/phantomjs else echo 'PhantomJS binaries for darwin missing!' fi - go run build.go -goos darwin -pkg-arch amd64 ${OPT} package-only + go run build.go -goos darwin -pkg-arch amd64 "${OPT}" package-only fi if [ -d '/tmp/phantomjs/windows' ]; then @@ -90,6 +89,6 @@ if [ -d '/tmp/phantomjs/windows' ]; then else echo 'PhantomJS binaries for Windows missing!' fi -go run build.go -goos windows -pkg-arch amd64 ${OPT} package-only +go run build.go -goos windows -pkg-arch amd64 "${OPT}" package-only go run build.go latest diff --git a/scripts/build/build.sh b/scripts/build/build.sh index b6bbbccedaf..539c095df4e 100755 --- a/scripts/build/build.sh +++ b/scripts/build/build.sh @@ -9,10 +9,6 @@ CCARMV6=/opt/rpi-tools/arm-bcm2708/arm-linux-gnueabihf/bin/arm-linux-gnueabihf-g CCARMV7=arm-linux-gnueabihf-gcc CCARM64=aarch64-linux-gnu-gcc CCX64=/tmp/x86_64-centos6-linux-gnu/bin/x86_64-centos6-linux-gnu-gcc -########## -GOPATH=/go -REPO_PATH=$GOPATH/src/github.com/grafana/grafana -########## BUILD_FAST=0 BUILD_BACKEND=1 @@ -51,9 +47,9 @@ while [ "$1" != "" ]; do esac done +# shellcheck disable=SC2124 EXTRA_OPTS="$@" - cd /go/src/github.com/grafana/grafana echo "current dir: $(pwd)" @@ -73,7 +69,7 @@ function build_backend_linux_amd64() { if [ ! -d "dist" ]; then mkdir dist fi - CC=${CCX64} go run build.go ${OPT} build + CC=${CCX64} go run build.go "${OPT}" build } function build_backend() { @@ -81,9 +77,9 @@ function build_backend() { mkdir dist fi - go run build.go -goarch armv6 -cc ${CCARMV6} ${OPT} build - go run build.go -goarch armv7 -cc ${CCARMV7} ${OPT} build - go run build.go -goarch arm64 -cc ${CCARM64} ${OPT} build + go run build.go -goarch armv6 -cc ${CCARMV6} "${OPT}" build + go run build.go -goarch armv7 -cc ${CCARMV7} "${OPT}" build + go run build.go -goarch arm64 -cc ${CCARM64} "${OPT}" build build_backend_linux_amd64 } @@ -93,22 +89,22 @@ function build_frontend() { fi yarn install --pure-lockfile --no-progress echo "Building frontend" - go run build.go ${OPT} build-frontend + go run build.go "${OPT}" build-frontend echo "FRONTEND: finished" } function package_linux_amd64() { echo "Packaging Linux AMD64" - go run build.go -goos linux -pkg-arch amd64 ${OPT} package-only + go run build.go -goos linux -pkg-arch amd64 "${OPT}" package-only go run build.go latest echo "PACKAGE LINUX AMD64: finished" } function package_all() { echo "Packaging ALL" - go run build.go -goos linux -pkg-arch armv6 ${OPT} -skipRpm package-only - go run build.go -goos linux -pkg-arch armv7 ${OPT} package-only - go run build.go -goos linux -pkg-arch arm64 ${OPT} package-only + go run build.go -goos linux -pkg-arch armv6 "${OPT}" -skipRpm package-only + go run build.go -goos linux -pkg-arch armv7 "${OPT}" package-only + go run build.go -goos linux -pkg-arch arm64 "${OPT}" package-only package_linux_amd64 echo "PACKAGE ALL: finished" } @@ -119,8 +115,9 @@ function package_setup() { rm -rf dist fi mkdir dist - go run build.go -gen-version ${OPT} > dist/grafana.version + go run build.go -gen-version "${OPT}" > dist/grafana.version # Load ruby, needed for packing with fpm + # shellcheck disable=SC1091 source /etc/profile.d/rvm.sh } diff --git a/scripts/build/ci-build/bootstrap.sh b/scripts/build/ci-build/bootstrap.sh index 2eda345b5ab..0c4f5ac876e 100755 --- a/scripts/build/ci-build/bootstrap.sh +++ b/scripts/build/ci-build/bootstrap.sh @@ -1,5 +1,5 @@ #!/bin/bash -cd /tmp +cd /tmp || exit 1 tar xfJ x86_64-centos6-linux-gnu.tar.xz tar xfJ osxcross.tar.xz diff --git a/scripts/build/ci-msi-build/ci-msi-build-oss.sh b/scripts/build/ci-msi-build/ci-msi-build-oss.sh index 02f015dae23..5e63b5d931d 100755 --- a/scripts/build/ci-msi-build/ci-msi-build-oss.sh +++ b/scripts/build/ci-msi-build/ci-msi-build-oss.sh @@ -1,6 +1,6 @@ #!/bin/bash set -e -WORKING_DIRECTORY=`pwd` +WORKING_DIRECTORY=$(pwd) # copy zip file to /tmp/dist mkdir -p /tmp/dist cp ./dist/*.zip /tmp/dist @@ -23,12 +23,12 @@ echo "Building MSI" python3 generator/build.py "$@" chmod a+x /tmp/scratch/*.msi echo "MSI: Copy to $WORKING_DIRECTORY/dist" -cp /tmp/scratch/*.msi $WORKING_DIRECTORY/dist +cp /tmp/scratch/*.msi "$WORKING_DIRECTORY/dist" echo "MSI: Generate SHA256" -MSI_FILE=`ls $WORKING_DIRECTORY/dist/*.msi` -SHA256SUM=`sha256sum $MSI_FILE | cut -f1 -d' '` -echo $SHA256SUM > $MSI_FILE.sha256 +MSI_FILE=$(ls "$WORKING_DIRECTORY/dist/*.msi") +SHA256SUM=$(sha256sum "$MSI_FILE" | cut -f1 -d' ') +echo "$SHA256SUM" > "$MSI_FILE.sha256" echo "MSI: SHA256 file content:" -cat $MSI_FILE.sha256 +cat "$MSI_FILE.sha256" echo "MSI: contents of $WORKING_DIRECTORY/dist" -ls -al $WORKING_DIRECTORY/dist +ls -al "$WORKING_DIRECTORY/dist" diff --git a/scripts/build/ci-msi-build/oss/ci-wrapper.sh b/scripts/build/ci-msi-build/oss/ci-wrapper.sh index b91b323191d..7b71c9a409a 100755 --- a/scripts/build/ci-msi-build/oss/ci-wrapper.sh +++ b/scripts/build/ci-msi-build/oss/ci-wrapper.sh @@ -21,7 +21,7 @@ ls -al /home/xclient/wix/light.exe.config cat /home/xclient/wix/light.exe.config cp /master/light.exe.config /home/xclient/wix/light.exe.config cat /home/xclient/wix/light.exe.config -cd /master +cd /master || exit 1 echo "Building MSI" python3 generator/build.py "$@" # diff --git a/scripts/build/ci-msi-build/oss/wrapper.sh b/scripts/build/ci-msi-build/oss/wrapper.sh index c92835a4b45..d8da096772d 100755 --- a/scripts/build/ci-msi-build/oss/wrapper.sh +++ b/scripts/build/ci-msi-build/oss/wrapper.sh @@ -1,3 +1,3 @@ #!/bin/bash -cd /oss +cd /oss || exit 1 make diff --git a/scripts/build/prepare-enterprise.sh b/scripts/build/prepare-enterprise.sh index a2ab269d1cb..77ed8ce8bf4 100755 --- a/scripts/build/prepare-enterprise.sh +++ b/scripts/build/prepare-enterprise.sh @@ -2,7 +2,6 @@ cd .. - if [ -z "$CIRCLE_TAG" ]; then _target="master" else @@ -11,5 +10,5 @@ fi git clone -b "$_target" --single-branch git@github.com:grafana/grafana-enterprise.git --depth 1 -cd grafana-enterprise +cd grafana-enterprise || exit ./build.sh diff --git a/scripts/build/publish.sh b/scripts/build/publish.sh index 785f46f22a0..fc312d0f404 100755 --- a/scripts/build/publish.sh +++ b/scripts/build/publish.sh @@ -2,6 +2,8 @@ # no relation to publish.go +# shellcheck disable=SC2124 + EXTRA_OPTS="$@" # Right now we hack this in into the publish script. @@ -10,7 +12,7 @@ _releaseNoteUrl="https://community.grafana.com/t/release-notes-v6-0-x/14010" _whatsNewUrl="http://docs.grafana.org/guides/whats-new-in-v6-0/" ./scripts/build/release_publisher/release_publisher \ - --wn ${_whatsNewUrl} \ - --rn ${_releaseNoteUrl} \ - --version ${CIRCLE_TAG} \ - --apikey ${GRAFANA_COM_API_KEY} ${EXTRA_OPTS} + --wn "${_whatsNewUrl}" \ + --rn "${_releaseNoteUrl}" \ + --version "${CIRCLE_TAG}" \ + --apikey "${GRAFANA_COM_API_KEY}" "${EXTRA_OPTS}" diff --git a/scripts/build/sign_packages.sh b/scripts/build/sign_packages.sh index c53c2f70ca3..89581e0f274 100755 --- a/scripts/build/sign_packages.sh +++ b/scripts/build/sign_packages.sh @@ -8,5 +8,5 @@ cp ./scripts/build/rpmmacros ~/.rpmmacros for package in dist/*.rpm; do [ -e "$package" ] || continue - ./scripts/build/sign_expect $GPG_KEY_PASSWORD $package + ./scripts/build/sign_expect "$GPG_KEY_PASSWORD" "$package" done diff --git a/scripts/build/update_repo/update-deb.sh b/scripts/build/update_repo/update-deb.sh index a70af5b8b5c..f7fe0c349d2 100755 --- a/scripts/build/update_repo/update-deb.sh +++ b/scripts/build/update_repo/update-deb.sh @@ -9,7 +9,7 @@ GCP_REPO_BUCKET="${6:-grafana-repo}" REPO="grafana" -if [ -z "$RELEASE_TYPE" -o -z "$GPG_PASS" -o -z "$DIST_PATH" ]; then +if [ -z "$RELEASE_TYPE" ] || [ -z "$GPG_PASS" ] || [ -z "$DIST_PATH" ]; then echo "Both RELEASE_TYPE (arg 1), GPG_PASS (arg 2) and DIST_PATH (arg 4) has to be set" exit 1 fi @@ -36,7 +36,7 @@ mkdir -p /deb-repo/db \ gsutil -m rsync -r -d "gs://$GCP_DB_BUCKET/$RELEASE_TYPE" /deb-repo/db # Add the new release to the repo -cp $DIST_PATH/*.deb /deb-repo/tmp +cp "$DIST_PATH/*.deb" /deb-repo/tmp rm /deb-repo/tmp/grafana_latest*.deb || true aptly repo add "$REPO" /deb-repo/tmp #adds too many packages in enterprise @@ -64,5 +64,5 @@ gsutil -m rsync -r /deb-repo/repo/grafana/pool "gs://$GCP_REPO_BUCKET/$RELEASE_T gsutil -m rsync -r -d /deb-repo/repo/grafana "gs://$GCP_REPO_BUCKET/$RELEASE_TYPE/deb" # usage: -# +# # deb https://packages.grafana.com/oss/deb stable main diff --git a/scripts/build/update_repo/update-rpm.sh b/scripts/build/update_repo/update-rpm.sh index f02647f55a0..028773d5069 100755 --- a/scripts/build/update_repo/update-rpm.sh +++ b/scripts/build/update_repo/update-rpm.sh @@ -8,7 +8,7 @@ GCP_REPO_BUCKET="${5:-grafana-repo}" REPO="rpm" -if [ -z "$RELEASE_TYPE" -o -z "$GPG_PASS" -o -z "$DIST_PATH" ]; then +if [ -z "$RELEASE_TYPE" ] || [ -z "$GPG_PASS" ] || [ -z "$DIST_PATH" ]; then echo "Both RELEASE_TYPE (arg 1), GPG_PASS (arg 2) and DIST_PATH (arg 4) has to be set" exit 1 fi @@ -33,7 +33,7 @@ mkdir -p /rpm-repo gsutil -m rsync -r "$BUCKET" /rpm-repo # Add the new release to the repo -cp $DIST_PATH/*.rpm /rpm-repo # adds to many files for enterprise +cp "$DIST_PATH/*.rpm" /rpm-repo # adds to many files for enterprise rm /rpm-repo/grafana-latest-1*.rpm || true createrepo /rpm-repo diff --git a/scripts/build/verify_signed_packages.sh b/scripts/build/verify_signed_packages.sh index c3e5b09afc2..f4f9e73fbd3 100755 --- a/scripts/build/verify_signed_packages.sh +++ b/scripts/build/verify_signed_packages.sh @@ -1,15 +1,15 @@ #!/bin/bash + _files=$* ALL_SIGNED=0 for file in $_files; do - rpm -K "$file" | grep "pgp.*OK" -q - if [[ $? != 0 ]]; then + if rpm -K "$file" | grep "pgp.*OK" -q; then ALL_SIGNED=1 - echo $file NOT SIGNED + echo "$file" NOT SIGNED else - echo $file OK + echo "$file" OK fi done diff --git a/scripts/ci-frontend-metrics.sh b/scripts/ci-frontend-metrics.sh index 93bb05c3984..63370f50bab 100755 --- a/scripts/ci-frontend-metrics.sh +++ b/scripts/ci-frontend-metrics.sh @@ -11,19 +11,19 @@ ERROR_COUNT="$(./node_modules/.bin/tsc --project tsconfig.json --noEmit --noImpl DIRECTIVES="$(grep -r -o directive public/app/**/* | wc -l)" CONTROLLERS="$(grep -r -oP 'class .*Ctrl' public/app/**/* | wc -l)" -if [ $ERROR_COUNT -gt $ERROR_COUNT_LIMIT ]; then +if [ "$ERROR_COUNT" -gt $ERROR_COUNT_LIMIT ]; then echo -e "Typescript errors $ERROR_COUNT exceeded $ERROR_COUNT_LIMIT so failing build" - exit -1 + exit 1 fi -if [ $DIRECTIVES -gt $DIRECTIVES_LIMIT ]; then +if [ "$DIRECTIVES" -gt $DIRECTIVES_LIMIT ]; then echo -e "Directive count $DIRECTIVES exceeded $DIRECTIVES_LIMIT so failing build" - exit -1 + exit 1 fi -if [ $CONTROLLERS -gt $CONTROLLERS_LIMIT ]; then +if [ "$CONTROLLERS" -gt $CONTROLLERS_LIMIT ]; then echo -e "Controllers count $CONTROLLERS exceeded $CONTROLLERS_LIMIT so failing build" - exit -1 + exit 1 fi echo -e "Typescript errors: $ERROR_COUNT" @@ -32,7 +32,7 @@ echo -e "Controllers: $CONTROLLERS" if [ "${CIRCLE_BRANCH}" == "master" ]; then ./scripts/ci-metrics-publisher.sh \ - grafana.ci-code.noImplicitAny=$ERROR_COUNT \ - grafana.ci-code.directives=$DIRECTIVES \ - grafana.ci-code.controllers=$CONTROLLERS + grafana.ci-code.noImplicitAny="$ERROR_COUNT" \ + grafana.ci-code.directives="$DIRECTIVES" \ + grafana.ci-code.controllers="$CONTROLLERS" fi diff --git a/scripts/ci-metrics-publisher.sh b/scripts/ci-metrics-publisher.sh index bb7d042caf1..463dd1471e6 100755 --- a/scripts/ci-metrics-publisher.sh +++ b/scripts/ci-metrics-publisher.sh @@ -13,6 +13,6 @@ for ((i = 1; i <= $#; i++ )); do data=''$data'{"name": "'${first}'", "value": '${remainder}', "interval": 60, "mtype": "gauge", "time": '$(date +%s)'}' done -curl https://6371:$GRAFANA_MISC_STATS_API_KEY@graphite-us-central1.grafana.net/metrics \ +curl "https://6371:$GRAFANA_MISC_STATS_API_KEY@graphite-us-central1.grafana.net/metrics" \ -H 'Content-type: application/json' \ -d "[$data]" diff --git a/scripts/circle-release-next-packages.sh b/scripts/circle-release-next-packages.sh index 6030eab23d1..e6309211929 100755 --- a/scripts/circle-release-next-packages.sh +++ b/scripts/circle-release-next-packages.sh @@ -12,7 +12,7 @@ function prapare_version_commit () { } #Get current version from lerna.json -PACKAGE_VERSION=`grep '"version"' lerna.json | cut -d '"' -f 4` +PACKAGE_VERSION=$(grep '"version"' lerna.json | cut -d '"' -f 4) # Get short current commit's has GIT_SHA=$(parse_git_hash) @@ -20,16 +20,14 @@ echo "Commit: ${GIT_SHA}" echo "Current lerna.json version: ${PACKAGE_VERSION}" # check if there were any changes to packages between current and previous commit -count=`git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}'` +count=$(git diff HEAD~1..HEAD --name-only -- packages | awk '{c++} END {print c}') - - -if [ -z $count ]; then +if [ -z "$count" ]; then echo "No changes in packages, skipping packages publishing" else echo "Changes detected in ${count} packages" echo "Releasing packages under ${PACKAGE_VERSION}-${GIT_SHA}" - npx lerna version ${PACKAGE_VERSION}-${GIT_SHA} --no-git-tag-version --no-push --force-publish -y + npx lerna version "${PACKAGE_VERSION}-${GIT_SHA}" --no-git-tag-version --no-push --force-publish -y echo $'\nGit status:' git status -s diff --git a/scripts/circle-test-backend.sh b/scripts/circle-test-backend.sh index 4f853ec55fd..147603276c0 100755 --- a/scripts/circle-test-backend.sh +++ b/scripts/circle-test-backend.sh @@ -1,14 +1,7 @@ #!/bin/bash -function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi -} + +# shellcheck source=./scripts/helpers/exit-if-fail.sh +source "$(dirname "$0")/helpers/exit-if-fail.sh" echo "building backend with install to cache pkgs" exit_if_fail time go install ./pkg/cmd/grafana-server @@ -16,5 +9,5 @@ exit_if_fail time go install ./pkg/cmd/grafana-server echo "running go test" set -e time for d in $(go list ./pkg/...); do - exit_if_fail go test -tags=integration -covermode=atomic $d + exit_if_fail go test -tags=integration -covermode=atomic "$d" done diff --git a/scripts/circle-test-cache-servers.sh b/scripts/circle-test-cache-servers.sh index bacd9928362..3d70a7ac2f4 100755 --- a/scripts/circle-test-cache-servers.sh +++ b/scripts/circle-test-cache-servers.sh @@ -1,14 +1,7 @@ #!/bin/bash -function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi -} + +# shellcheck source=./scripts/helpers/exit-if-fail.sh +source "$(dirname "$0")/helpers/exit-if-fail.sh" echo "running redis and memcache tests" diff --git a/scripts/circle-test-frontend.sh b/scripts/circle-test-frontend.sh index df5ef24ccba..07eab50d85f 100755 --- a/scripts/circle-test-frontend.sh +++ b/scripts/circle-test-frontend.sh @@ -1,15 +1,7 @@ #!/bin/bash -function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi -} +# shellcheck source=./scripts/helpers/exit-if-fail.sh +source "$(dirname "$0")/helpers/exit-if-fail.sh" start=$(date +%s) diff --git a/scripts/circle-test-mysql.sh b/scripts/circle-test-mysql.sh index 4d2fea90c4d..01b2af79ceb 100755 --- a/scripts/circle-test-mysql.sh +++ b/scripts/circle-test-mysql.sh @@ -1,17 +1,10 @@ #!/bin/bash -function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi -} + +# shellcheck source=./scripts/helpers/exit-if-fail.sh +source "$(dirname "$0")/helpers/exit-if-fail.sh" export GRAFANA_TEST_DB=mysql time for d in $(go list ./pkg/...); do - exit_if_fail go test -tags=integration $d -done \ No newline at end of file + exit_if_fail go test -tags=integration "$d" +done diff --git a/scripts/circle-test-postgres.sh b/scripts/circle-test-postgres.sh index 7dc6232b1f2..6e6867c2877 100755 --- a/scripts/circle-test-postgres.sh +++ b/scripts/circle-test-postgres.sh @@ -1,17 +1,10 @@ #!/bin/bash -function exit_if_fail { - command=$@ - echo "Executing '$command'" - eval $command - rc=$? - if [ $rc -ne 0 ]; then - echo "'$command' returned $rc." - exit $rc - fi -} + +# shellcheck source=./scripts/helpers/exit-if-fail.sh +source "$(dirname "$0")/helpers/exit-if-fail.sh" export GRAFANA_TEST_DB=postgres time for d in $(go list ./pkg/...); do - exit_if_fail go test -tags=integration $d -done \ No newline at end of file + exit_if_fail go test -tags=integration "$d" +done diff --git a/scripts/helpers/exit-if-fail.sh b/scripts/helpers/exit-if-fail.sh new file mode 100644 index 00000000000..37f7e3e324d --- /dev/null +++ b/scripts/helpers/exit-if-fail.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +function exit_if_fail { + # shellcheck disable=SC2124 + command=$@ + echo "Executing '$command'" + eval "$command" + rc=$? + if [ $rc -ne 0 ]; then + echo "'$command' returned $rc." + exit $rc + fi +} diff --git a/scripts/tag_release.sh b/scripts/tag_release.sh index fe047266c44..9b6d31b1f80 100755 --- a/scripts/tag_release.sh +++ b/scripts/tag_release.sh @@ -6,12 +6,12 @@ set -e _tag=$1 _branch="$(git rev-parse --abbrev-ref HEAD)" -if [ "${_tag}" == "" ]; then +if [ "${_tag}" == "" ]; then echo "Missing version param. ex './scripts/tag_release.sh v5.1.1'" exit 1 fi -if [ "${_branch}" == "master" ]; then +if [ "${_branch}" == "master" ]; then echo "you cannot tag releases from the master branch" echo "please checkout the release branch" echo "ex 'git checkout v5.1.x'" @@ -20,9 +20,9 @@ fi # always make sure to pull latest changes from origin echo "pulling latest changes from ${_branch}" -git pull origin ${_branch} +git pull origin "${_branch}" -# create signed tag for latest commit +# create signed tag for latest commit git tag -s "${_tag}" -m "release ${_tag}" # verify the signed tag @@ -31,7 +31,7 @@ git tag -v "${_tag}" echo "Make sure the tag is signed as expected" echo "press [y] to push the tags" -read -n 1 confirm +read -n -r 1 confirm if [ "${confirm}" == "y" ]; then git push origin "${_branch}" --tags diff --git a/scripts/trigger_docker_build.sh b/scripts/trigger_docker_build.sh index 5ca9c0b88c8..0aaa3045517 100755 --- a/scripts/trigger_docker_build.sh +++ b/scripts/trigger_docker_build.sh @@ -1,9 +1,9 @@ - #!/bin/bash +#!/bin/bash _circle_token=$1 _grafana_version=$2 -trigger_build_url=https://circleci.com/api/v1/project/grafana/grafana-docker/tree/master?circle-token=${_circle_token} +trigger_build_url="https://circleci.com/api/v1/project/grafana/grafana-docker/tree/master?circle-token=${_circle_token}" post_data=$(cat <