Skip to content

Commit 99d6361

Browse files
committed
Fix misc shellcheck complaints and run shellcheck on CI
1 parent b30dd5e commit 99d6361

File tree

15 files changed

+101
-52
lines changed

15 files changed

+101
-52
lines changed

.github/workflows/shellcheck.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
name: ShellCheck
3+
on:
4+
push:
5+
branches:
6+
- 'main'
7+
- 'release-*'
8+
pull_request:
9+
jobs:
10+
shellcheck:
11+
runs-on: ubuntu-latest
12+
name: ShellCheck
13+
steps:
14+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
15+
- name: Run shellcheck on all .sh files
16+
shell: bash
17+
run: |
18+
failures=0
19+
while IFS= read -r -d '' file; do
20+
if ! shellcheck "${file}"; then
21+
failures=$((failures + 1))
22+
fi
23+
done < <(find . -type f -name '*.sh' -print0)
24+
if [[ "${failures}" -gt 0 ]]; then
25+
echo "Shellcheck failed for ${failures} files."
26+
fi
27+
exit "${failures}"

.shellcheckrc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Allow opening any 'source'd file, even if not specified as input
2+
external-sources=true

debugging/bughunt/core_dump.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ COREFILE="$(corefile)"
66

77
# Read in all directories under `src/` and `base/` in the julia checkout;
88
# we'll add these as source search paths in `gdb`
9-
readarray -t -d '' JULIA_SRC_DIRS < <(find /build/julia.git/src /build/julia.git/base -type d -print0)
9+
# readarray -t -d '' JULIA_SRC_DIRS < <(find /build/julia.git/src /build/julia.git/base -type d -print0)
1010

1111
# Try `gdb` first, as it is less likely to freeze on us for some reason
1212
if [[ -n "$(which gdb)" ]]; then

debugging/bughunt/rr_trace.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ function fixup_trace_path() {
3232
}
3333

3434
function any_failures_in_ps() {
35-
[[ $("${RR}" ps "$(fixup_trace_path "${1}")" | awk "{sum+=\$3} END {print sum;}") > 0 ]]
35+
[[ $("${RR}" ps "$(fixup_trace_path "${1}")" | awk "{sum+=\$3} END {print sum;}") -gt 0 ]]
3636
}
3737

3838
function grep_ps() {
@@ -42,12 +42,18 @@ function grep_ps() {
4242
}
4343

4444

45+
# `ls` but using `find` to make shellcheck happy
46+
# (https://www.shellcheck.net/wiki/SC2012)
47+
lsfind() {
48+
find "${1}" ! -name "$(basename "${1}")" -prune -exec basename {} \;
49+
}
50+
4551
if [[ "$1" == "list" ]]; then
46-
for trace in $(ls ${SCRIPT_DIR}/rr_traces | sort -V); do
52+
for trace in $(lsfind "${SCRIPT_DIR}/rr_traces" | sort -V); do
4753
if any_failures_in_ps "${trace}"; then
4854
echo_red "$(basename "${trace}")"
4955
else
50-
echo "$(basename "${trace}")"
56+
basename "${trace}"
5157
fi
5258
done
5359
exit 0
@@ -60,12 +66,12 @@ if [[ "$1" == "grep" ]]; then
6066
fi
6167
shift 1
6268

63-
for trace in $(ls ${SCRIPT_DIR}/rr_traces | sort -V); do
69+
for trace in $(lsfind "${SCRIPT_DIR}/rr_traces" | sort -V); do
6470
if grep_ps "${trace}" "$@"; then
6571
if any_failures_in_ps "${trace}"; then
6672
echo_red "$(basename "${trace}")"
6773
else
68-
echo "$(basename "${trace}")"
74+
basename "${trace}"
6975
fi
7076
fi
7177
done
@@ -77,7 +83,7 @@ if [[ "$1" == "ps" ]]; then
7783
echo "Usage: ${SCRIPT} ps <trace>" >&2
7884
exit 1
7985
fi
80-
TRACE_PATH="$(fixup_trace_path ${2})"
86+
TRACE_PATH="$(fixup_trace_path "${2}")"
8187
shift 2
8288
exec "${RR}" ps "${TRACE_PATH}" "$@"
8389
fi
@@ -87,11 +93,11 @@ if [[ "$1" == "replay" ]]; then
8793
echo "Usage: ${SCRIPT} replay <trace>" >&2
8894
exit 1
8995
fi
90-
TRACE_PATH="$(fixup_trace_path ${2})"
96+
TRACE_PATH="$(fixup_trace_path "${2}")"
9197
shift 2
9298
exec "${RR}" replay -x /build/.gdbinit.src --serve-files "${TRACE_PATH}" "$@"
9399
fi
94100

95-
echo "Unknown command: $@"
101+
echo "Unknown command: $*"
96102
print_usage
97103
exit 1

utilities/arches_env.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ for idx in "${!default_mapping_lines[@]}"; do
3636
defaults_map["${key}"]="${value}"
3737
done
3838

39-
cat "${ARCHES_FILE}" | while read line; do
39+
while read -r line; do
4040
# Remove whitespace from the beginning and end of each line
4141
line="$(tr -s ' ' <<<"${line}")"
4242

@@ -77,4 +77,4 @@ cat "${ARCHES_FILE}" | while read line; do
7777
echo -n "${name}=\"${value}\" "
7878
done
7979
echo
80-
done
80+
done <"${ARCHES_FILE}"

utilities/arches_pipeline_upload.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ if [[ ! -f "${YAML_FILE}" ]] ; then
2121
fi
2222

2323
SCRIPT_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
24-
"${BASH}" "${SCRIPT_DIR}/arches_env.sh" "${ARCHES_FILE}" | while read env_map; do
24+
"${BASH}" "${SCRIPT_DIR}/arches_env.sh" "${ARCHES_FILE}" | while read -r env_map; do
2525
# Export the environment mappings, then launch the yaml file
2626
eval "export ${env_map}"
2727
buildkite-agent pipeline upload "${YAML_FILE}"

utilities/build_envs.sh

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env bash
22

33
# First, extract information from our triplet
4+
# shellcheck source=SCRIPTDIR/extract_triplet.sh
45
source .buildkite/utilities/extract_triplet.sh
56

67
# Figure out what GNU Make is on this system
@@ -14,7 +15,8 @@ export MAKE
1415
# Apply fixups to our environment for when we're running on julia-buildkite pipeline
1516
if buildkite-agent meta-data exists BUILDKITE_JULIA_BRANCH; then
1617
# `BUILDKITE_BRANCH` should refer to `julia.git`, not `julia-buildkite.git`
17-
export BUILDKITE_BRANCH=$(buildkite-agent meta-data get BUILDKITE_JULIA_BRANCH)
18+
BUILDKITE_BRANCH=$(buildkite-agent meta-data get BUILDKITE_JULIA_BRANCH)
19+
export BUILDKITE_BRANCH
1820
fi
1921

2022
# Determine JULIA_CPU_TARGETS for different architectures
@@ -108,13 +110,16 @@ export JULIA_IMAGE_THREADS="$JULIA_CPU_THREADS"
108110

109111
# Extract git information
110112
SHORT_COMMIT_LENGTH=10
111-
export LONG_COMMIT="$(git rev-parse HEAD)"
112-
export SHORT_COMMIT="$(echo ${LONG_COMMIT} | cut -c1-${SHORT_COMMIT_LENGTH})"
113+
LONG_COMMIT="$(git rev-parse HEAD)"
114+
SHORT_COMMIT="$(echo "${LONG_COMMIT}" | cut -c1-${SHORT_COMMIT_LENGTH})"
115+
export LONG_COMMIT SHORT_COMMIT
113116

114117
# Extract information about the current julia version number
115-
export JULIA_VERSION="$(cat VERSION)"
116-
export MAJMIN="$(cut -d. -f1-2 <<<"${JULIA_VERSION}")"
117-
export MAJMINPAT="$(cut -d- -f1 <<<"${JULIA_VERSION}")"
118+
JULIA_VERSION="$(cat VERSION)"
119+
MAJMIN="$(cut -d. -f1-2 <<<"${JULIA_VERSION}")"
120+
MAJMINPAT="$(cut -d- -f1 <<<"${JULIA_VERSION}")"
121+
export JULIA_VERSION MAJMIN MAJMINPAT
122+
118123
# If we're on a tag, then our "tar version" will be the julia version.
119124
# Otherwise, it's the short commit.
120125
if git describe --tags --exact-match >/dev/null 2>/dev/null; then
@@ -128,7 +133,8 @@ export TAR_VERSION
128133
# Build the filename that we'll upload as, and get the filename that will be built
129134
# These are not the same in situations such as `musl`, where the build system doesn't
130135
# differentiate but we need to give it a different name.
131-
export JULIA_BINARYDIST_FILENAME="$(${MAKE} print-JULIA_BINARYDIST_FILENAME | cut -c27- | tr -s ' ')"
136+
JULIA_BINARYDIST_FILENAME="$(${MAKE} print-JULIA_BINARYDIST_FILENAME | cut -c27- | tr -s ' ')"
137+
export JULIA_BINARYDIST_FILENAME
132138

133139
export JULIA_INSTALL_DIR="julia-${TAR_VERSION}"
134140
JULIA_BINARY="${JULIA_INSTALL_DIR}/bin/julia${EXE}"
@@ -227,6 +233,6 @@ echo "Detected Julia version: ${MAJMIN} (${JULIA_VERSION})"
227233
echo "Detected build platform: ${TRIPLET} (${ARCH}, ${OS})"
228234
echo "Julia will be uploaded to: s3://${UPLOAD_TARGETS[0]}.tar.gz"
229235
echo "With additional upload targets:"
230-
for UPLOAD_TARGET in ${UPLOAD_TARGETS[@]:1}; do
236+
for UPLOAD_TARGET in "${UPLOAD_TARGETS[@]:1}"; do
231237
echo " -> s3://${UPLOAD_TARGET}.tar.gz"
232238
done

utilities/build_julia.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
set -euo pipefail
88

99
# First, get things like `SHORT_COMMIT`, `JULIA_CPU_TARGET`, `UPLOAD_TARGETS`, etc...
10+
# shellcheck source=SCRIPTDIR/build_envs.sh
1011
source .buildkite/utilities/build_envs.sh
12+
# shellcheck source=SCRIPTDIR/word.sh
1113
source .buildkite/utilities/word.sh
1214

1315
echo "--- Print software versions"
@@ -54,7 +56,8 @@ fi
5456
MFLAGS+=( "JULIA_CPU_TARGET=${JULIA_CPU_TARGET}" )
5557

5658
# Finish off with any extra make flags from the `.arches` file
57-
MFLAGS+=( $(tr "," " " <<<"${MAKE_FLAGS}") )
59+
IFS=',' read -ra ARCHES_FLAGS <<<"${MAKE_FLAGS}"
60+
MFLAGS+=( "${ARCHES_FLAGS[@]}" )
5861

5962
echo "Make Options:"
6063
for FLAG in "${MFLAGS[@]}"; do

utilities/deploy_docs.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
set -euo pipefail
44

55
# Get the `.buildkite/utilities/docs` folder path
6-
DOCS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
6+
# DOCS_DIR="$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
77

88
echo "--- Download built docs"
99
buildkite-agent artifact download --step "doctest" "julia-*-htmldocs.tar.gz"
1010

1111
echo "--- Deploy docs"
12-
export DOCUMENTER_KEY="$(cat .buildkite/secrets/ssh_docs_deploy)"
12+
DOCUMENTER_KEY="$(cat .buildkite/secrets/ssh_docs_deploy)"
13+
export DOCUMENTER_KEY
1314
echo "Do something here!"

utilities/extract_triplet.sh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Extract information from our triplet
44
# Here is an example of a triplet: `x86_64-linux-gnu`
5-
export ARCH="$(cut -d- -f1 <<<"${TRIPLET}")"
5+
ARCH="$(cut -d- -f1 <<<"${TRIPLET}")"
6+
export ARCH
67
case "${TRIPLET}" in
78
# Linux
89
*-gnu)

0 commit comments

Comments
 (0)