Skip to content

Commit 66c057b

Browse files
authored
enable shell linter for more scripts (#3748)
1 parent 2b6bd5f commit 66c057b

File tree

6 files changed

+29
-17
lines changed

6 files changed

+29
-17
lines changed

.github/workflows/shellcheck.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,16 @@ jobs:
2323
- name: Run ShellCheck
2424
run: |
2525
git diff --name-only -z `git merge-base origin/master HEAD` -- \
26-
'install/_lib.sh' \
26+
install/_lib.sh \
27+
'optional-modifications/**.sh' \
28+
'scripts/**.sh' \
29+
unit-test.sh \
30+
'workstation/**.sh' \
2731
| xargs -0 -r -- \
2832
shellcheck \
2933
--shell=bash \
30-
--exclude=SC1090,SC1091 \
3134
--format=json1 \
35+
--external-sources \
3236
| jq -r '
3337
.comments
3438
| map(.level |= if ([.] | inside(["info", "style"])) then "notice" else . end)

scripts/_lib.sh

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ if [ -n "${DEBUG:-}" ]; then
77
fi
88

99
function confirm() {
10-
read -p "$1 [y/n] " confirmation
10+
read -r -p "$1 [y/n] " confirmation
1111
if [ "$confirmation" != "y" ]; then
1212
echo "Canceled. 😅"
1313
exit
@@ -26,8 +26,7 @@ function reset() {
2626
# we're targeting a valid tag here. Do this early in order to fail fast.
2727
if [ -n "$version" ]; then
2828
set +e
29-
git rev-parse --verify --quiet "refs/tags/$version" >/dev/null
30-
if [ $? -gt 0 ]; then
29+
if ! git rev-parse --verify --quiet "refs/tags/$version" >/dev/null; then
3130
echo "Bad version: $version"
3231
exit
3332
fi
@@ -43,12 +42,15 @@ function reset() {
4342
echo "Okay ... good luck! 😰"
4443
fi
4544

45+
# assert that commands are defined
46+
: "${dc:?}" "${cmd:?}"
47+
4648
# Hit the reset button.
4749
$dc down --volumes --remove-orphans --rmi local
4850

4951
# Remove any remaining (likely external) volumes with name matching 'sentry-.*'.
5052
for volume in $(docker volume list --format '{{ .Name }}' | grep '^sentry-'); do
51-
docker volume remove $volume >/dev/null &&
53+
docker volume remove "$volume" >/dev/null &&
5254
echo "Removed volume: $volume" ||
5355
echo "Skipped volume: $volume"
5456
done
@@ -60,30 +62,34 @@ function reset() {
6062
}
6163

6264
function backup() {
65+
local type
66+
6367
type=${1:-"global"}
64-
touch $(pwd)/sentry/backup.json
65-
chmod 666 $(pwd)/sentry/backup.json
66-
$dc run -v $(pwd)/sentry:/sentry-data/backup --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export $type /sentry-data/backup/backup.json
68+
touch "${PWD}/sentry/backup.json"
69+
chmod 666 "${PWD}/sentry/backup.json"
70+
$dc run -v "${PWD}/sentry:/sentry-data/backup" --rm -T -e SENTRY_LOG_LEVEL=CRITICAL web export "$type" /sentry-data/backup/backup.json
6771
}
6872

6973
function restore() {
70-
type=${1:-"global"}
71-
$dc run --rm -T web import $type /etc/sentry/backup.json
74+
local type
75+
76+
type="${1:-global}"
77+
$dc run --rm -T web import "$type" /etc/sentry/backup.json
7278
}
7379

7480
# Needed variables to source error-handling script
7581
MINIMIZE_DOWNTIME="${MINIMIZE_DOWNTIME:-}"
76-
STOP_TIMEOUT=60
82+
export STOP_TIMEOUT=60
7783

7884
# Save logs in order to send envelope to Sentry
79-
log_file=sentry_"${cmd%% *}"_log-$(date +'%Y-%m-%d_%H-%M-%S').txt
85+
log_file="sentry_${cmd%% *}_log-$(date +%Y-%m-%d_%H-%M-%S).txt"
8086
exec &> >(tee -a "$log_file")
8187
version=""
8288

8389
while (($#)); do
8490
case "$1" in
85-
--report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=1 ;;
86-
--no-report-self-hosted-issues) REPORT_SELF_HOSTED_ISSUES=0 ;;
91+
--report-self-hosted-issues) export REPORT_SELF_HOSTED_ISSUES=1 ;;
92+
--no-report-self-hosted-issues) export REPORT_SELF_HOSTED_ISSUES=0 ;;
8793
*) version=$1 ;;
8894
esac
8995
shift

scripts/bump-version.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ NEW_VERSION="$2"
77
sed -i -e "s/^\(SENTRY\|SNUBA\|RELAY\|SYMBOLICATOR\|TASKBROKER\|VROOM\)_IMAGE=\([^:]\+\):.\+\$/\1_IMAGE=\2:$NEW_VERSION/" .env
88
sed -i -e "s/^\# Self-Hosted Sentry .*/# Self-Hosted Sentry $NEW_VERSION/" README.md
99

10+
[ -z "$OLD_VERSION" ] || echo "Previous version: $OLD_VERSION"
1011
echo "New version: $NEW_VERSION"

scripts/restore.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env bash
22
cmd="restore $1"
33
source scripts/_lib.sh
4+
45
$cmd

unit-test.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ export REPORT_SELF_HOSTED_ISSUES=0 # will be over-ridden in the relevant test
55
FORCE_CLEAN=1 "./scripts/reset.sh"
66
fail=0
77
for test_file in _unit-test/*-test.sh; do
8-
if [ "$1" -a "$1" != "$test_file" ]; then
8+
if [ -n "$1" ] && [ "$1" != "$test_file" ]; then
99
echo "🙊 Skipping $test_file ..."
1010
continue
1111
fi

workstation/200_download-self-hosted.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#!/bin/bash
2-
#
2+
set -eo pipefail
33

44
# Create getsentry folder and enter.
55
mkdir /home/user/getsentry

0 commit comments

Comments
 (0)