Lint script files. (#3944)

* Lint script files.

This patch adds a Drone CI step that runs shellcheck on all Bash script
files.

* Install Bash in shellcheck container.

* Fix a few shelcheck errors.

* Fix build.sh

* Fix remaining shellcheck errors.
pull/3949/head
Karsten Jeschkies 5 years ago committed by GitHub
parent 5be93e0480
commit 0cde54c4dc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      .drone/drone.yml
  2. 5
      Makefile
  3. 8
      loki-build-image/build.sh
  4. 4
      tools/image-tag
  5. 17
      tools/increment_version.sh
  6. 4
      tools/promtail.sh
  7. 22
      tools/release_prepare.sh
  8. 6
      tools/scrape_config.sh

@ -41,6 +41,11 @@ steps:
- test
- lint
- name: shellcheck
image: koalaman/shellcheck-alpine:stable
commands:
- apk add make bash && make lint-scripts
---
kind: pipeline
name: docker-amd64

@ -601,6 +601,11 @@ fmt-jsonnet:
@find . -name 'vendor' -prune -o -name '*.libsonnet' -print -o -name '*.jsonnet' -print | \
xargs -n 1 -- jsonnetfmt -i
lint-scripts:
@find . -name '*.sh' -not -path '*/vendor/*' -print0 | \
xargs -0 -n1 shellcheck -x -o all
# search for dead link in our documentation.
# To avoid being rate limited by Github you can use an env variable GITHUB_TOKEN to pass a github token API.
# see https://github.com/settings/tokens

@ -8,10 +8,10 @@ SRC_PATH=/src/loki
# will have awkward ownership. So we switch to a user with the
# same user and group IDs as source directory. We have to set a
# few things up so that sudo works without complaining later on.
uid=$(stat --format="%u" $SRC_PATH)
gid=$(stat --format="%g" $SRC_PATH)
echo "grafana:x:$uid:$gid::$SRC_PATH:/bin/bash" >>/etc/passwd
uid=$(stat --format="%u" "${SRC_PATH}")
gid=$(stat --format="%g" "${SRC_PATH}")
echo "grafana:x:${uid}:${gid}::${SRC_PATH}:/bin/bash" >>/etc/passwd
echo "grafana:*:::::::" >>/etc/shadow
echo "grafana ALL=(ALL) NOPASSWD: ALL" >>/etc/sudoers
su grafana -c "PATH=$PATH make -C $SRC_PATH BUILD_IN_CONTAINER=false $*"
su grafana -c "PATH=${PATH} make -C ${SRC_PATH} BUILD_IN_CONTAINER=false $*"

@ -15,7 +15,7 @@ TAG=$((git describe --exact-match 2> /dev/null || echo "") | sed 's/v//g')
if [ -z "$TAG" ]
then
echo ${BRANCH}-${SHA}${WIP}
echo "${BRANCH}"-"${SHA}""${WIP}"
else
echo ${TAG}
echo "${TAG}"
fi

@ -31,45 +31,48 @@
while getopts ":Mmp" Option
do
case $Option in
case "${Option}" in
M ) major=true;;
m ) minor=true;;
p ) patch=true;;
* )
echo "unknown option: ${Option}"
exit 1
esac
done
shift $(($OPTIND - 1))
shift $((OPTIND - 1))
version=$1
# Build array from version string.
a=( ${version//./ } )
a=( "${version//./ }" )
# If version string is missing or has the wrong number of members, show usage message.
if [ ${#a[@]} -ne 3 ]
then
echo "usage: $(basename $0) [-Mmp] major.minor.patch"
echo "usage: $(basename "$0") [-Mmp] major.minor.patch"
exit 1
fi
# Increment version numbers as requested.
if [ ! -z $major ]
if [ -n "${major}" ]
then
((a[0]++))
a[1]=0
a[2]=0
fi
if [ ! -z $minor ]
if [ -n "${minor}" ]
then
((a[1]++))
a[2]=0
fi
if [ ! -z $patch ]
if [ -n "${patch}" ]
then
((a[2]++))
fi

@ -8,7 +8,7 @@ CONTAINERROOT="${5:-/var/lib/docker}"
PARSER="${6:-- docker:}"
VERSION="${PROMTAIL_VERSION:-2.2.0}"
if [ -z "$INSTANCEID" -o -z "$APIKEY" -o -z "$INSTANCEURL" -o -z "$NAMESPACE" -o -z "$CONTAINERROOT" -o -z "$PARSER" ]; then
if [ -z "${INSTANCEID}" ] || [ -z "${APIKEY}" ] || [ -z "${INSTANCEURL}" ] || [ -z "${NAMESPACE}" ] || [ -z "${CONTAINERROOT}" ] || [ -z "${PARSER}" ]; then
echo "usage: $0 <instanceId> <apiKey> <url> [<namespace>[<container_root_path>[<parser>]]]"
exit 1
fi
@ -360,7 +360,7 @@ subjects:
YAML
)
echo "$TEMPLATE" | sed \
echo "${TEMPLATE}" | sed \
-e "s#<instanceId>#${INSTANCEID}#" \
-e "s#<apiKey>#${APIKEY}#" \
-e "s#<instanceUrl>#${INSTANCEURL}#" \

@ -3,12 +3,12 @@
# sed-wrap runs the appropriate sed command based on the
# underlying value of $OSTYPE
sed-wrap() {
if [[ "$OSTYPE" == "linux"* ]]; then
if [[ "${OSTYPE}" == "linux"* ]]; then
# Linux
sed -i "$1" $2
sed -i "$1" "$2"
else
# macOS, BSD
sed -i '' "$1" $2
sed -i '' "$1" "$2"
fi
}
@ -17,7 +17,7 @@ echo "Last 5 tags:"
git tag --sort=-taggerdate | head -n 5
echo
read -p "Enter release version: " VERSION
read -rp "Enter release version: " VERSION
if [[ ${VERSION} =~ ^v[0-9]+\.[0-9]+\.[0-9]+.*$ ]]; then
echo "New Version: ${VERSION}"
@ -27,22 +27,22 @@ else
fi
LOKI_CURRENT=$(sed -n -e 's/^version: //p' production/helm/loki/Chart.yaml)
LOKI_SUGGESTED=$(tools/increment_version.sh -m ${LOKI_CURRENT})
LOKI_SUGGESTED=$(tools/increment_version.sh -m "${LOKI_CURRENT}")
PROMTAIL_CURRENT=$(sed -n -e 's/^version: //p' production/helm/promtail/Chart.yaml)
PROMTAIL_SUGGESTED=$(tools/increment_version.sh -m ${PROMTAIL_CURRENT})
PROMTAIL_SUGGESTED=$(tools/increment_version.sh -m "${PROMTAIL_CURRENT}")
LOKI_STACK_CURRENT=$(sed -n -e 's/^version: //p' production/helm/loki-stack/Chart.yaml)
LOKI_STACK_SUGGESTED=$(tools/increment_version.sh -m ${LOKI_STACK_CURRENT})
LOKI_STACK_SUGGESTED=$(tools/increment_version.sh -m "${LOKI_STACK_CURRENT}")
echo
echo "Current Loki helm chart version: ${LOKI_CURRENT}"
read -p "Enter new Loki helm chart version [${LOKI_SUGGESTED}]: " LOKI_VERSION
read -rp "Enter new Loki helm chart version [${LOKI_SUGGESTED}]: " LOKI_VERSION
LOKI_VERSION=${LOKI_VERSION:-${LOKI_SUGGESTED}}
echo
echo "Current Promtail helm chart version: ${PROMTAIL_CURRENT}"
read -p "Enter new Promtail helm chart version [${PROMTAIL_SUGGESTED}]: " PROMTAIL_VERSION
read -rp "Enter new Promtail helm chart version [${PROMTAIL_SUGGESTED}]: " PROMTAIL_VERSION
PROMTAIL_VERSION=${PROMTAIL_VERSION:-${PROMTAIL_SUGGESTED}}
echo
echo "Current Loki-Stack helm chart version: ${LOKI_STACK_CURRENT}"
read -p "Enter new Loki-Stack helm chart version [${LOKI_STACK_SUGGESTED}]: " LOKI_STACK_VERSION
read -rp "Enter new Loki-Stack helm chart version [${LOKI_STACK_SUGGESTED}]: " LOKI_STACK_VERSION
LOKI_STACK_VERSION=${LOKI_STACK_VERSION:-${LOKI_STACK_SUGGESTED}}
echo
@ -52,7 +52,7 @@ echo "Loki Helm Chart: ${LOKI_VERSION}"
echo "Promtail Helm Chart: ${PROMTAIL_VERSION}"
echo "Loki-Stack Helm Chart: ${LOKI_STACK_VERSION}"
echo
read -p "Is this correct? [y]: " CONTINUE
read -rp "Is this correct? [y]: " CONTINUE
CONTINUE=${CONTINUE:-y}
echo

@ -9,13 +9,13 @@
# ksonnet library.
#########################################
BASE=$(dirname $0)
BASE=$(dirname "$0")
target=${1:-shell}
case $target in
case "${target}" in
"shell")
(cd $BASE; jsonnet -e '((import "../production/ksonnet/promtail/scrape_config.libsonnet") + { _config:: { promtail_config: { pipeline_stages: ["<parser>"]}}}).promtail_config' | ytools 2>/dev/null)
(cd "${BASE}" || exit; jsonnet -e '((import "../production/ksonnet/promtail/scrape_config.libsonnet") + { _config:: { promtail_config: { pipeline_stages: ["<parser>"]}}}).promtail_config' | ytools 2>/dev/null)
;;
*)

Loading…
Cancel
Save