ci: Add shellcheck for scripts (#20631)

Fixes shellcheck errors in script/*
Adds a couple trailing newlines.
Adds `script/shellcheck-scripts` and associated CI machinery.
Current set ultra-conservative, does not output warnings, only errors.
This commit is contained in:
Peter Tripp 2024-11-18 21:41:22 +00:00 committed by GitHub
parent 5b317f60df
commit 5b9916e34b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 48 additions and 12 deletions

21
.github/workflows/script_checks.yml vendored Normal file
View file

@ -0,0 +1,21 @@
name: Script
on:
pull_request:
paths:
- "script/**"
push:
branches:
- main
jobs:
shellcheck:
name: "ShellCheck Scripts"
if: github.repository_owner == 'zed-industries'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4
- name: Shellcheck ./scripts
run: |
./script/shellcheck-scripts error

View file

@ -1,3 +1,4 @@
#!/usr/bin/env python3
"""
This script analyzes all the highlight.scm files in our embedded languages and extensions.
It counts the number of unique instances of @{name} and the languages in which they are used.

View file

@ -69,7 +69,9 @@ strip --strip-debug "${target_dir}/${remote_server_triple}/release/remote_server
# Ensure that remote_server does not depend on libssl nor libcrypto, as we got rid of these deps.
! ldd "${target_dir}/${remote_server_triple}/release/remote_server" | grep -q 'libcrypto\|libssl'
if ldd "${target_dir}/${remote_server_triple}/release/remote_server" | grep -q 'libcrypto\|libssl'; then
echo "Error: remote_server still depends on libssl or libcrypto" && exit 1
fi
suffix=""
if [ "$channel" != "stable" ]; then
@ -89,8 +91,8 @@ cp "${target_dir}/${target_triple}/release/cli" "${zed_dir}/bin/zed"
# Libs
find_libs() {
ldd ${target_dir}/${target_triple}/release/zed |\
cut -d' ' -f3 |\
grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\|libpthread.so\|libdl.so\)'
cut -d' ' -f3 |\
grep -v '\<\(libstdc++.so\|libc.so\|libgcc_s.so\|libm.so\|libpthread.so\|libdl.so\)'
}
mkdir -p "${zed_dir}/lib"

View file

@ -2,7 +2,7 @@
set -eu
if [[ $# < 1 ]]; then
if [[ $# -ne 1 ]]; then
echo "usage: $0 <MAX_SIZE_IN_GB>"
exit 1
fi

View file

@ -3,7 +3,7 @@
set -eu
source script/lib/deploy-helpers.sh
if [[ $# < 1 ]]; then
if [[ $# != 1 ]]; then
echo "Usage: $0 <production|staging> (postgrest not needed on preview or nightly)"
exit 1
fi

View file

@ -2,7 +2,7 @@
set -eu
if [[ $# < 1 ]]; then
if [[ $# -ne 1 ]]; then
echo "Usage: $0 <crate_name>" >&2
exit 1
fi
@ -14,4 +14,4 @@ cargo metadata \
--format-version=1 \
| jq \
--raw-output \
".packages[] | select(.name == \"${CRATE_NAME}\") | .version"
".packages[] | select(.name == \"${CRATE_NAME}\") | .version"

View file

@ -1,6 +1,6 @@
#!/bin/bash
if [[ $# < 1 ]]; then
if [[ $# -ne 1 ]]; then
echo "Usage: $0 [production|staging|...]"
exit 1
fi
@ -8,4 +8,4 @@ fi
export ZED_KUBE_NAMESPACE=$1
pod=$(kubectl --namespace=${ZED_KUBE_NAMESPACE} get pods --selector=app=zed --output=jsonpath='{.items[*].metadata.name}')
exec kubectl --namespace $ZED_KUBE_NAMESPACE exec --tty --stdin $pod -- /bin/bash
exec kubectl --namespace $ZED_KUBE_NAMESPACE exec --tty --stdin $pod -- /bin/bash

View file

@ -10,4 +10,4 @@ export GPUProfilerEnabled="YES"
export METAL_DEBUG_ERROR_MODE=0
export LD_LIBRARY_PATH="/Applications/Xcode.app/Contents/Developer/../SharedFrameworks/"
cargo run $@
cargo run "$@"

12
script/shellcheck-scripts Executable file
View file

@ -0,0 +1,12 @@
#!/usr/bin/env bash
set -euo pipefail
mode=${1:-error}
[[ "$mode" =~ ^(error|warning)$ ]] || { echo "Usage: $0 [error|warning]"; exit 1; }
cd "$(dirname "$0")/.." || exit 1
find script -maxdepth 1 -type f -print0 |
xargs -0 grep -l -E '^#!(/bin/|/usr/bin/env )(sh|bash|dash)' |
xargs -r shellcheck -x -S "$mode" -C

View file

@ -19,12 +19,12 @@ if [[ -n "${1:-}" ]]; then
target="$1"
else
echo "Error: Target '$1' is not allowed"
echo "Usage: $0 [${allowed_targets[@]}]"
echo "Usage: $0 [${allowed_targets[*]}]"
exit 1
fi
else
echo "Error: Target is not specified"
echo "Usage: $0 [${allowed_targets[@]}]"
echo "Usage: $0 [${allowed_targets[*]}]"
exit 1
fi
echo "Uploading nightly for target: $target"