Skip to content

Commit

Permalink
Added format script to simplify avoiding .semgrep directory (#2946)
Browse files Browse the repository at this point in the history
  • Loading branch information
VeronikaSolovei9 authored Jul 26, 2023
1 parent 831dd71 commit 8a96e3d
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 24 deletions.
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

all: deps test build-modules build

.PHONY: deps test build-modules build image
.PHONY: deps test build-modules build image format

# deps will clean out the vendor directory and use go mod for a fresh install
deps:
Expand All @@ -29,3 +29,7 @@ build: test
# image will build a docker image
image:
docker build -t prebid-server .

# format runs format
format:
./scripts/format.sh -f true
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,15 @@ go build .
./prebid-server
```

Run format:
```
make format
```
or
```bash
./scripts/format.sh -f true
```

Load the landing page in your browser at `http://localhost:8000/`.
For the full API reference, see [the endpoint documentation](https://docs.prebid.org/prebid-server/endpoints/pbs-endpoint-overview.html)

Expand Down
34 changes: 34 additions & 0 deletions scripts/format.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

die() { echo -e "$@" 1>&2 ; exit 1; }

AUTOFMT=true
while getopts 'f:' OPTION; do
case "$OPTION" in
f)
AUTOFMT="$OPTARG"
;;
esac
done

# Build a list of all the top-level directories in the project.
for DIRECTORY in */ ; do
GOGLOB="$GOGLOB ${DIRECTORY%/}"
done
GOGLOB="${GOGLOB/ docs/}"
GOGLOB="${GOGLOB/ vendor/}"

# Check that there are no formatting issues
GOFMT_LINES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | wc -l | xargs`
if $AUTOFMT; then
# if there are files with formatting issues, they will be automatically corrected using the gofmt -w <file> command
if [[ $GOFMT_LINES -ne 0 ]]; then
FMT_FILES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | xargs`
for FILE in $FMT_FILES; do
echo "Running: gofmt -s -w $FILE"
`gofmt -s -w $FILE`
done
fi
else
test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -s -l $GOGLOB`"
fi
24 changes: 1 addition & 23 deletions validate.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,7 @@ while true; do
esac
done

die() { echo -e "$@" 1>&2 ; exit 1; }

# Build a list of all the top-level directories in the project.
for DIRECTORY in */ ; do
GOGLOB="$GOGLOB ${DIRECTORY%/}"
done
GOGLOB="${GOGLOB/ docs/}"
GOGLOB="${GOGLOB/ vendor/}"

# Check that there are no formatting issues
GOFMT_LINES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | wc -l | xargs`
if $AUTOFMT; then
# if there are files with formatting issues, they will be automatically corrected using the gofmt -w <file> command
if [[ $GOFMT_LINES -ne 0 ]]; then
FMT_FILES=`gofmt -s -l $GOGLOB | tr '\\\\' '/' | xargs`
for FILE in $FMT_FILES; do
echo "Running: gofmt -s -w $FILE"
`gofmt -s -w $FILE`
done
fi
else
test $GOFMT_LINES -eq 0 || die "gofmt needs to be run, ${GOFMT_LINES} files have issues. Below is a list of files to review:\n`gofmt -s -l $GOGLOB`"
fi
./scripts/format.sh -f $AUTOFMT

# Run the actual tests. Make sure there's enough coverage too, if the flags call for it.
if $COVERAGE; then
Expand Down

0 comments on commit 8a96e3d

Please sign in to comment.