Skip to content

Commit

Permalink
Update dev scripts (#552)
Browse files Browse the repository at this point in the history
  • Loading branch information
mtlynch authored Feb 11, 2024
1 parent d53636f commit 0f8dabd
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 16 deletions.
3 changes: 2 additions & 1 deletion dev-scripts/check-bash
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,15 @@ set -u
BASH_SCRIPTS=()

while read -r filepath; do
# Check shebang for bash.
if head -n 1 "${filepath}" | grep --quiet --regexp 'bash'; then
BASH_SCRIPTS+=("${filepath}")
fi
done < <(git ls-files)

readonly BASH_SCRIPTS

# Echo commands to stdout.
# Echo commands before executing them, by default to stderr.
set -x

shellcheck "${BASH_SCRIPTS[@]}"
7 changes: 2 additions & 5 deletions dev-scripts/check-go-formatting
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
#!/usr/bin/env bash

# Exit build script on first failure.
# Exit on first failure.
set -e

# Echo commands to stdout.
set -x

# Exit on unset variable.
set -u

Expand All @@ -14,4 +11,4 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."

test -z "$(gofmt -d .)"
test -z "$(gofmt -s -d .)"
4 changes: 2 additions & 2 deletions dev-scripts/check-trailing-newline
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# Verify that all text files end in a trailing newline.

# Exit on first failing command.
# Exit on first failure.
set -e

# Exit on unset variable.
set -u

Expand All @@ -12,7 +13,6 @@ SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
cd "${SCRIPT_DIR}/.."


success=0

while read -r line; do
Expand Down
3 changes: 2 additions & 1 deletion dev-scripts/check-trailing-whitespace
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

# Check for trailing whitespace

# Exit on first failing command.
# Exit on first failure.
set -e

# Exit on unset variable.
set -u

Expand Down
11 changes: 7 additions & 4 deletions dev-scripts/enable-git-hooks
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
#!/usr/bin/env bash

# Run this to enable all git hooks for this project.

set -x
# Exit on first failure.
set -e

# Exit on unset variable.
set -u

# Echo commands before executing them, by default to stderr.
set -x

# Change directory to repository root.
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
readonly SCRIPT_DIR
Expand All @@ -23,4 +26,4 @@ then
rm -rf .git/hooks
fi

ln -s -f ../dev-scripts/git-hooks .git/hooks
ln --symbolic --force ../dev-scripts/git-hooks .git/hooks
10 changes: 7 additions & 3 deletions dev-scripts/run-go-tests
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,18 @@
# --full Include slower, more exhaustive tests and capture test coverage
# results (outputs to .coverage.html).

# Exit build script on first failure.
# Exit on first failure.
set -e

# Echo commands to stdout.
# Echo commands before executing them, by default to stderr.
set -x

# Fail when piped commands fail.
set -o pipefail

full_test=""
go_test_flags=()
# Without netgo and osusergo, compilation fails under Nix.
go_test_flags=("-tags=netgo,osusergo,sqlite_json")
readonly COVERAGE_FILE_RAW=".coverage.out"
readonly COVERAGE_FILE_HTML=".coverage.html"
if [[ "$1" = "--full" ]]; then
Expand Down
36 changes: 36 additions & 0 deletions dev-scripts/update-scripts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
#!/usr/bin/env bash

# Exit on first failing command.
set -e

# Exit on unset variable.
set -u

# Echo commands before executing them, by default to stderr.
set -x

# Update dev scripts in a directory to the latest version available in the
# dev-scripts repo.

readonly TARGET_DEV_SCRIPTS="${PWD}/dev-scripts"
if [[ ! -d "${TARGET_DEV_SCRIPTS}" ]]; then
echo "No dev-scripts directory found"
echo "Run this from a project with a dev-scripts directory."
exit 1
fi

cd "$(mktemp --directory)"

git clone https://github.com/mtlynch/dev-scripts .
readonly GOLDEN_DEV_SCRIPTS="${PWD}/dev-scripts"

for f in "${GOLDEN_DEV_SCRIPTS}/"*; do
FILENAME="$(basename "${f}")"
TARGET_SCRIPT="${TARGET_DEV_SCRIPTS}/${FILENAME}"
if [[ ! -f "${TARGET_SCRIPT}" ]]; then
continue
fi
GOLDEN_SCRIPT="${GOLDEN_DEV_SCRIPTS}/${FILENAME}"
cp "${GOLDEN_SCRIPT}" "${TARGET_SCRIPT}"
chmod +x "${TARGET_SCRIPT}"
done

0 comments on commit 0f8dabd

Please sign in to comment.