Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lint script files. #3944

Merged
merged 5 commits into from
Jul 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .drone/drone.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ steps:
- test
- lint

- name: shellcheck
image: koalaman/shellcheck-alpine:stable
commands:
- apk add make bash && make lint-scripts
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've follow the pattern make lint-jsonnet and make lint-markdown. However, it would be easier to just have a shellcheck script file and avoid installing make and bash here.


---
kind: pipeline
name: docker-amd64
Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,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
Expand Down
8 changes: 4 additions & 4 deletions loki-build-image/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 $*"
4 changes: 2 additions & 2 deletions tools/image-tag
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 10 additions & 7 deletions tools/increment_version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions tools/promtail.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -360,7 +360,7 @@ subjects:
YAML
)

echo "$TEMPLATE" | sed \
echo "${TEMPLATE}" | sed \
-e "s#<instanceId>#${INSTANCEID}#" \
-e "s#<apiKey>#${APIKEY}#" \
-e "s#<instanceUrl>#${INSTANCEURL}#" \
Expand Down
22 changes: 11 additions & 11 deletions tools/release_prepare.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

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

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

Expand Down
6 changes: 3 additions & 3 deletions tools/scrape_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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)
;;

*)
Expand Down