Skip to content

Commit

Permalink
Build: Introduce shellcheck (#18081)
Browse files Browse the repository at this point in the history
* Build: introduce shellcheck

Fixes #16198
  • Loading branch information
markelog authored Jul 23, 2019
1 parent 87a794f commit 4b16cd6
Show file tree
Hide file tree
Showing 28 changed files with 161 additions and 156 deletions.
27 changes: 27 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -665,6 +676,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- build-oss-msi
Expand All @@ -677,6 +689,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
Expand All @@ -687,6 +700,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- build-all-enterprise
Expand All @@ -698,6 +712,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-master
Expand All @@ -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:
Expand All @@ -739,6 +756,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- build-oss-msi
Expand All @@ -751,6 +769,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -762,6 +781,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -772,6 +792,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
filters: *filter-only-release
Expand All @@ -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:
Expand All @@ -808,6 +833,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- cache-server-test
Expand All @@ -819,6 +845,7 @@ workflows:
- test-frontend
- codespell
- lint-go
- shellcheck
- mysql-integration-test
- postgres-integration-test
- cache-server-test
Expand Down
6 changes: 6 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

GO = GO111MODULE=on go
GO_FILES ?= ./pkg/...
SH_FILES ?= $(shell find ./scripts -name *.sh)

all: deps build

Expand Down Expand Up @@ -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

Expand Down
33 changes: 16 additions & 17 deletions scripts/build/build-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)"

Expand All @@ -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

Expand All @@ -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
Expand All @@ -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
27 changes: 12 additions & 15 deletions scripts/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"

Expand All @@ -73,17 +69,17 @@ 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() {
if [ ! -d "dist" ]; then
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
}

Expand All @@ -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"
}
Expand All @@ -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
}

Expand Down
2 changes: 1 addition & 1 deletion scripts/build/ci-build/bootstrap.sh
Original file line number Diff line number Diff line change
@@ -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
14 changes: 7 additions & 7 deletions scripts/build/ci-msi-build/ci-msi-build-oss.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
2 changes: 1 addition & 1 deletion scripts/build/ci-msi-build/oss/ci-wrapper.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 "$@"
#
Expand Down
2 changes: 1 addition & 1 deletion scripts/build/ci-msi-build/oss/wrapper.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/bin/bash
cd /oss
cd /oss || exit 1
make
3 changes: 1 addition & 2 deletions scripts/build/prepare-enterprise.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

cd ..


if [ -z "$CIRCLE_TAG" ]; then
_target="master"
else
Expand All @@ -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
Loading

0 comments on commit 4b16cd6

Please sign in to comment.