-
Notifications
You must be signed in to change notification settings - Fork 4.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into ui/VAULT-17968/secrets-sync
- Loading branch information
Showing
546 changed files
with
205,495 additions
and
149,051 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,151 +1,3 @@ | ||
#!/usr/bin/env bash | ||
|
||
# READ THIS BEFORE MAKING CHANGES: | ||
# | ||
# If you want to add a new pre-commit check, here are the rules: | ||
# | ||
# 1. Create a bash function for your check (see e.g. ui_lint below). | ||
# NOTE: Each function will be called in a sub-shell so you can freely | ||
# change directory without worrying about interference. | ||
# 2. Add the name of the function to the CHECKS variable. | ||
# 3. If no changes relevant to your new check are staged, then | ||
# do not output anything at all - this would be annoying noise. | ||
# In this case, call 'return 0' from your check function to return | ||
# early without blocking the commit. | ||
# 4. If any non-trivial check-specific thing has to be invoked, | ||
# then output '==> [check description]' as the first line of | ||
# output. Each sub-check should output '--> [subcheck description]' | ||
# after it has run, indicating success or failure. | ||
# 5. Call 'block [reason]' to block the commit. This ensures the last | ||
# line of output calls out that the commit was blocked - which may not | ||
# be obvious from random error messages generated in 4. | ||
# | ||
# At the moment, there are no automated tests for this hook, so please run it | ||
# locally to check you have not broken anything - breaking this will interfere | ||
# with other peoples' workflows significantly, so be sure, check everything twice. | ||
|
||
set -euo pipefail | ||
|
||
# Call block to block the commit with a message. | ||
block() { | ||
echo "$@" | ||
echo "Commit blocked - see errors above." | ||
exit 1 | ||
} | ||
|
||
# Add all check functions to this space separated list. | ||
# They are executed in this order (see end of file). | ||
CHECKS="ui_lint ui_copywrite backend_lint" | ||
|
||
# Run ui linter if changes in that dir detected. | ||
ui_lint() { | ||
local DIR=ui LINTER=node_modules/.bin/lint-staged | ||
|
||
# Silently succeed if no changes staged for $DIR | ||
if git diff --name-only --cached --exit-code -- $DIR/; then | ||
return 0 | ||
fi | ||
|
||
# Silently succeed if the linter has not been installed. | ||
# We assume that if you're doing UI dev, you will have installed the linter | ||
# by running yarn. | ||
if [ ! -x $DIR/$LINTER ]; then | ||
return 0 | ||
fi | ||
|
||
echo "==> Changes detected in $DIR/: Running linter..." | ||
|
||
# Run the linter from the UI dir. | ||
cd $DIR | ||
$LINTER || block "UI lint failed" | ||
} | ||
|
||
backend_lint() { | ||
# Silently succeed if no changes staged for Go code files. | ||
staged=$(git diff --name-only --cached --exit-code -- '*.go') | ||
ret=$? | ||
if [ $ret -eq 0 ]; then | ||
return 0 | ||
fi | ||
|
||
# Only run fmtcheck on staged files | ||
./scripts/gofmtcheck.sh "${staged}" || block "Backend linting failed; run 'make fmt' to fix." | ||
} | ||
|
||
ui_copywrite() { | ||
DIR=ui | ||
BINARY_DIR=$DIR/.copywrite | ||
DOWNLOAD_ERR="==> Copywrite tool not found and failed to downloaded. Please download manually and extract to ui/.copywrite directory to utilize in pre-commit hook." | ||
|
||
# silently succeed if no changes staged for $DIR | ||
if git diff --name-only --cached --exit-code -- $DIR/; then | ||
return 0 | ||
fi | ||
|
||
echo "==> Changes detected in $DIR/: Checking copyright headers..." | ||
|
||
# download latest version of hashicorp/copywrite if necessary | ||
if [ ! -x $BINARY_DIR/copywrite ]; then | ||
local REPO_URL=https://github.com/hashicorp/copywrite | ||
# get the latest version tag | ||
local LATEST_RELEASE_JSON=$(curl -L -s -H 'Accept: application/json' $REPO_URL/releases/latest); | ||
local LATEST_TAG=$(echo $LATEST_RELEASE_JSON | sed -e 's/.*"tag_name":"\([^"]*\)".*/\1/') | ||
|
||
if [ ! $LATEST_TAG ]; then | ||
echo $DOWNLOAD_ERR | ||
return 0; | ||
fi | ||
|
||
# get the OS/Architecture specifics to build the filename | ||
# eg. copywrite_0.16.6_darwin_x86_64.tar.gz | ||
case "$OSTYPE" in | ||
linux*) OS='linux' ;; | ||
darwin*) OS='darwin' ;; | ||
msys*) OS='windows';; | ||
esac | ||
local ARCH=$([ $(uname -m) == arm* ] && echo 'arm64' || echo 'x86_64') | ||
local EXT=$([ $OSTYPE == "msys" ] && echo '.zip' || echo '.tar.gz') | ||
local FILENAME=copywrite_"${LATEST_TAG:1}"_"$OS"_"$ARCH""$EXT" | ||
|
||
mkdir -p $BINARY_DIR | ||
echo "==> Copywrite tool not found, downloading version $LATEST_TAG from $REPO_URL..." | ||
curl -L -s $REPO_URL/releases/download/$LATEST_TAG/$FILENAME | tar -xz - -C $BINARY_DIR || { echo $DOWNLOAD_ERR; return 0; }; | ||
fi | ||
|
||
# run the copywrite tool | ||
# if a --path option is added we could apply the headers to only the staged files much easier | ||
# as of the latest version 0.16.6 there is only support for --dirPath | ||
STAGED_FILES=($(git diff --name-only --cached)) | ||
|
||
rm -rf $BINARY_DIR/.staged | ||
mkdir $BINARY_DIR/.staged | ||
|
||
# copy staged files to .staged directory | ||
echo $STAGED_FILES; | ||
for FILE_PATH in "${STAGED_FILES[@]}"; do | ||
cp $FILE_PATH $BINARY_DIR/.staged | ||
done | ||
|
||
COPYWRITE_LOG_LEVEL=info | ||
COPY_CMD="$BINARY_DIR/copywrite headers -d $BINARY_DIR/.staged --config $DIR/.copywrite.hcl" | ||
|
||
# if staged files are missing header run the tool on .staged directory | ||
VALIDATE=$(eval $COPY_CMD --plan) # assigning to var so output is suppressed since it is repeated during second run | ||
if [ $(echo $?) == 1 ]; then | ||
eval $COPY_CMD || { echo "==> Copyright check failed. Please review and add headers manually."; return 0; }; | ||
|
||
# copy files back to original locations and stage changes | ||
local TMP_FILES=$(ls $BINARY_DIR/.staged) | ||
i=0 | ||
for FILE in $TMP_FILES; do | ||
cp $BINARY_DIR/.staged/$FILE "${STAGED_FILES[$i]}" | ||
git add "${STAGED_FILES[$i]}" | ||
i=$(( i + 1 )) | ||
done | ||
fi | ||
} | ||
|
||
for CHECK in $CHECKS; do | ||
# Force each check into a subshell to avoid crosstalk. | ||
( $CHECK ) || exit $? | ||
done | ||
```release-note:improvement | ||
storage/raft: Upgrade to bbolt 1.3.8, along with an extra patch to reduce time scanning large freelist maps. | ||
``` |
Oops, something went wrong.