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

Add shellckeck pre-commit hook #6021

Merged
merged 2 commits into from
Dec 20, 2023
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
15 changes: 8 additions & 7 deletions .github/scripts/notary/lib.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
SCRIPTDIR=${SCRIPTDIR:="$(dirname $(realpath -s "$0"))"}

SCRIPTDIR=${SCRIPTDIR:="$(dirname "$(realpath -s "$0")")"}
QUERY_FOLDER=$SCRIPTDIR/graphql

# List project fields like `status`, `tag`, `labels` and other
Expand All @@ -10,7 +11,7 @@ function list_project_fields() {

gh api graphql \
-f project="$project_id" \
-f query="$(<$QUERY_FILE)" \
-f query="$(<"$QUERY_FILE")" \
--jq .data.node.fields.nodes | cat
}

Expand All @@ -23,8 +24,8 @@ function update_project_item_field() {
-f project="$1" \
-f item="$2" \
-f field="$3" \
-f field_value="$4"
-f query="$(<$QUERY_FILE)" | cat
-f field_value="$4" \
-f query="$(<"$QUERY_FILE")" | cat
}

# Retrieve the organization project identified by:
Expand All @@ -43,7 +44,7 @@ function get_project_v2() {
gh api graphql \
-f organization="$organization" \
-F number="$project_number" \
-f query="$(<${QUERY_FILE})" \
-f query="$(<"$QUERY_FILE")" \
--jq .data.organization.projectV2 | cat
}

Expand All @@ -57,7 +58,7 @@ function add_item_to_project() {
gh api graphql \
-f project="$project_id" \
-f item="$item_id" \
-f query="$(<$QUERY_FILE)" \
-f query="$(<"$QUERY_FILE")" \
--jq .data.addProjectV2ItemById.item | cat
}

Expand All @@ -66,5 +67,5 @@ function project_status_field_with_init_value() {
local project_id=$1
local init_status_name=$2

list_project_fields $project_id | jq ". | map(select(.name == \"Status\"))[0] | {\"name\": .name, \"id\": .id, \"init_status_id\": .options | map(select(.name == \"$init_status_name\"))[0].id }"
list_project_fields "$project_id" | jq ". | map(select(.name == \"Status\"))[0] | {\"name\": .name, \"id\": .id, \"init_status_id\": .options | map(select(.name == \"$init_status_name\"))[0].id }"
}
3 changes: 2 additions & 1 deletion .github/scripts/notary/script.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#!/usr/bin/env bash
SCRIPTDIR=${SCRIPTDIR:="$(dirname $(realpath -s "$0"))"}

SCRIPTDIR=${SCRIPTDIR:="$(dirname "$(realpath -s "$0")")"}
source "$SCRIPTDIR"/lib.sh

if [ $# -ne 2 ]; then
Expand Down
18 changes: 18 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,24 @@ repos:
- "@cspell/dict-shell"
- "@cspell/dict-win32"

# ShellCheck, the static analysis tool for shell scripts
#
# We do not use the official pre-commit hook [0] because it requires
# docker executable (see [1]).
# To learn more about a specific error or warning, take a look at
# shellcheck's wiki (e.g. for SC1090 directive, see [2]).
# [0] https://github.com/koalaman/shellcheck-precommit
# [1] https://github.com/koalaman/shellcheck/issues/2495
# [2] https://www.shellcheck.net/wiki/SC1090
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.6
hooks:
- id: shellcheck
args: [
--exclude=SC1090, # Do not follow non-constant sources
--severity=warning, # Optionally only show errors and warnings
]

########
# Python

Expand Down
22 changes: 10 additions & 12 deletions cli/run_testenv.sh
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
#!/usr/bin/env bash
: '
Create a temporary environment and initialize a test setup for parsec.

Run `tests/scripts/run_testenv.sh --help` for more information.

For MacOS, please install coreutils from brew to get realpath:
`brew install coreutils`
'
# Create a temporary environment and initialize a test setup for Parsec.
#
# For MacOS, please install coreutils from brew to get realpath:
#`brew install coreutils`

# Make sure this script is sourced
if [[ "${BASH_SOURCE[0]}" == "${0}" ]]
then
echo "This script must be sourced. Use --help for more information."
echo "This script must be sourced:"
echo ". ./run_testenv.sh"
exit 1
fi

# Prevent pre-commit from losing it work dir
# Prevent pre-commit from losing its work dir
if [[ -z "$PRE_COMMIT_HOME" ]]
then
if [[ -z "$XDG_CACHE_HOME" ]]
Expand All @@ -29,10 +27,10 @@ fi
# In Python we trust (aka shell's tempfile&mktemp doesn't work on all platforms)
SOURCE_FILE=$(python -c "import tempfile; print(tempfile.mkstemp()[1])")

cargo run --package parsec_cli --features testenv run-testenv --main-process-id $$ --source-file "$SOURCE_FILE" $@ || return $?
source $SOURCE_FILE
cargo run --package parsec_cli --features testenv run-testenv --main-process-id $$ --source-file "$SOURCE_FILE" "$@" || return $?
source "$SOURCE_FILE"

# Clean up
rm $SOURCE_FILE
rm "$SOURCE_FILE"
unset SOURCE_FILE
unset SCRIPT_DIR
2 changes: 1 addition & 1 deletion docs/adminguide/hosting/gen-admin-token.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

ENV_FILE=parsec-admin-token.env
if [ ! -f $ENV_FILE ]; then
Expand Down
2 changes: 1 addition & 1 deletion docs/adminguide/hosting/ping-mailhog.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

set -a
source parsec-email.env
Expand Down
6 changes: 3 additions & 3 deletions docs/adminguide/hosting/setup-tls.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/usr/bin/env bash

function generate_cert_conf() {
local name=$1
Expand Down Expand Up @@ -66,12 +66,12 @@ for service in parsec-{s3,server}; do
fi
done

if [ $(stat -c %g parsec-server.key) -ne 1234 ]; then
if [ "$(stat -c %g parsec-server.key)" -ne 1234 ]; then
echo "Changing group id of parsec-server.key to 1234"
sudo chown $USER:1234 parsec-server.key
fi

if [ $(stat -c %a parsec-server.key) -ne 640 ]; then
if [ "$(stat -c %a parsec-server.key)" -ne 640 ]; then
echo "Changing permission of parsec-server.key to 640"
chmod 640 parsec-server.key
fi
8 changes: 2 additions & 6 deletions misc/setup-rust.sh
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
#!bash
#!/usr/bin/env bash

# Script that install the specific rust toolchain
#
# It will install rust with the minimal profile
# Installs the specific rust toolchain with the minimal profile
#
# Basic usage:
#
# ```bash
# $ bash setup-rust.sh
# ```


set -eux
set -o pipefail

Expand Down
7 changes: 4 additions & 3 deletions server/packaging/server/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#! /bin/bash
#!/usr/bin/env bash

# Execute the script line `bash packaging/backend/build.sh ...`

set -e -o pipefail

# Allow the user to overwrite `SCRIPTDIR` by exporting it beforehand.
SCRIPTDIR=${SCRIPTDIR:=$(dirname $(realpath -s "$0"))}
SCRIPTDIR=${SCRIPTDIR:=$(dirname "$(realpath -s "$0")")}
# Allow the user to overwrite `ROOTDIR` by exporting it beforehand.
ROOTDIR=${ROOTDIR:=$(realpath -s "$SCRIPTDIR/../../..")}

Expand All @@ -28,7 +29,7 @@ DOCKER_BUILDKIT=1 docker build \
-f $SCRIPTDIR/server.dockerfile \
-t $PREFIX/$IMAGE_NAME:latest \
-t $PREFIX/$IMAGE_NAME:$UNIQ_TAG \
$ROOTDIR $@
$ROOTDIR "$@"

echo
echo "You can now test/use the docker image with:"
Expand Down
7 changes: 4 additions & 3 deletions server/packaging/testbed-server/build.sh
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
#! /bin/bash
#!/usr/bin/env bash

# Execute the script like `bash packaging/testbed-server/build.sh ...`

set -e -o pipefail

# Allow the user to overwrite `SCRIPTDIR` by exporting it beforehand.
SCRIPTDIR=${SCRIPTDIR:=$(dirname $(realpath -s "$0"))}
SCRIPTDIR=${SCRIPTDIR:=$(dirname "$(realpath -s "$0")")}
# Allow the user to overwrite `ROOTDIR` by exporting it beforehand.
ROOTDIR=${ROOTDIR:=$(realpath -s "$SCRIPTDIR/../../..")}

Expand Down Expand Up @@ -33,7 +34,7 @@ echo "On top of that the image will use the following prefix \`$PREFIX\`"
DOCKER_BUILDKIT=1 docker build \
-f $SCRIPTDIR/testbed-server.dockerfile \
-t $PREFIX/parsec-testbed-server:$UNIQ_TAG \
$ROOTDIR $@
$ROOTDIR "$@"

echo "You can now test/use the docker image with:"
echo "docker run --publish 6777:6777 --rm --name=parsec-testbed-server $PREFIX/parsec-testbed-server:$UNIQ_TAG"
Expand Down