-
Notifications
You must be signed in to change notification settings - Fork 13
Update style checks #902
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
Merged
Merged
Update style checks #902
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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,11 +1,21 @@ | ||
#!/usr/bin/env bash | ||
|
||
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")"/../../.. && pwd)" | ||
source "$ROOT/scripts/ci/lib.sh" | ||
|
||
set -euo pipefail | ||
|
||
style_checks() { | ||
info "Starting style checks" | ||
|
||
make style | ||
make style || touch FAIL | ||
|
||
info "Saving junit XML report" | ||
mkdir -p junit-reports | ||
cp -a report.xml "junit-reports/" || true | ||
store_test_results junit-reports reports | ||
|
||
[[ ! -f FAIL ]] || die "Style checks failed" | ||
} | ||
|
||
style_checks "$*" |
File renamed without changes.
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,47 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Checks if all files given as arguments are either empty or end with newline characters. | ||
|
||
join_by() { local IFS="$1"; shift; echo "$*"; } | ||
|
||
# File extensions to apply the "file must end with a newline character" rule to. | ||
EXTENSIONS=(go sh yml yaml proto ts tsx) | ||
|
||
EXT_REGEX="\\.($(join_by '|' "${EXTENSIONS[@]}"))\$" | ||
|
||
fix=0 | ||
|
||
check_or_fix_newlines() { | ||
file="$1" | ||
[[ -s "$file" ]] || return 0 # skip check for empty files | ||
if [[ -n "$(tail -c 1 "$file")" ]]; then | ||
if (( fix )); then | ||
echo >&2 "Added missing newline at end of file: $file" | ||
echo >>"$file" | ||
return 0 | ||
fi | ||
echo >&2 "Missing newline at end of file: $file" | ||
return 1 | ||
fi | ||
} | ||
|
||
# Do nothing if no arguments given | ||
[[ "$#" -gt 0 ]] || exit 0 | ||
|
||
if [[ "$1" == "--fix" ]]; then | ||
fix=1 | ||
shift | ||
fi | ||
|
||
all_files=("$@") | ||
|
||
IFS=$'\n' read -d '' -r -a files < <( | ||
printf '%s\n' "${all_files[@]}" | grep -E "$EXT_REGEX" | ||
) | ||
|
||
status=0 | ||
for file in "${files[@]}"; do | ||
check_or_fix_newlines "$file" || status=1 | ||
done | ||
|
||
exit "$status" |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#!/usr/bin/env bash | ||
# Flag service protos files which include "google/api/annotations.proto" but do not have their file names end with _service.proto | ||
all_protos=$(git ls-files *.proto) | ||
IFS=$'\n' read -d '' -r -a all_service_protos_without_service_in_name < <( | ||
git grep -l 'import .*"google/api/annotations.proto";' -- '*.proto' | grep -vE '_service\.proto$' | ||
) | ||
|
||
[[ "${#all_service_protos_without_service_in_name[@]}" == 0 ]] || { | ||
echo "Found service proto files that do not end with _service.proto" | ||
echo "Files were: " | ||
printf " %s\n" ${all_service_protos_without_service_in_name[@]} | ||
exit 1 | ||
} >&2 |
This file contains hidden or 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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#!/usr/bin/env bash | ||
# Finds large files that have been checked in to Git. | ||
set -euo pipefail | ||
|
||
GIT_REPO_TOP="$(git rev-parse --show-toplevel)" | ||
|
||
allowlist_path="" | ||
if [[ $# -eq 1 ]] | ||
then | ||
allowlist_path="$1" | ||
fi | ||
|
||
allowed_files="" | ||
if [[ -n "$allowlist_path" ]] | ||
then | ||
LC_ALL=C LC_COLLATE=C sort --check "${allowlist_path}" | ||
allowed_files=$(egrep -v '^\s*(#.*)$' "${allowlist_path}" | xargs git -C "$GIT_REPO_TOP" ls-files --) | ||
fi | ||
|
||
large_files=$(git ls-tree --full-tree -l -r HEAD "$GIT_REPO_TOP" | awk '$4 > 50*1024 {print$5}') | ||
|
||
|
||
IFS=$'\n' read -d '' -r -a non_allowed_files < <( | ||
{ | ||
echo "${large_files}" | ||
echo "${allowed_files}" | ||
echo "${allowed_files}" | ||
} | sort | uniq -u | ||
) || true | ||
|
||
|
||
[[ "${#non_allowed_files[@]}" == 0 ]] || { | ||
echo "Found large files in the working tree. Please remove them!" | ||
echo "If you must add them, you need to explicitly add them to the allow list file ${allowlist_path:-and provide it as an argument to this script.}" | ||
echo "Files were: " | ||
printf ' %s\n' "${non_allowed_files[@]}" | ||
exit 1 | ||
} >&2 |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.