Skip to content

Commit

Permalink
🔧 chore: add go_deps.sh #2
Browse files Browse the repository at this point in the history
  • Loading branch information
pnguyen215 committed Dec 11, 2024
1 parent 0ab07ca commit 9ac648b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,8 @@ deps-upgrade:
# Removes all items from the Go module cache
deps-clean-cache:
go clean -modcache

# Running code coverage
# Generates code coverage report and logs the results
coverage:
sh ./sh/go_deps.sh
28 changes: 28 additions & 0 deletions sh/go_deps.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env bash

# Set up directories and files
LOG_DIR="logs"
COVERAGE_FILE="$LOG_DIR/coverage.txt"
PROFILE_FILE="profile.out"

# Ensure the logs directory exists
mkdir -p "$LOG_DIR"

# Exit immediately if a command exits with a non-zero status
set -e

# Initialize the coverage file
>"$COVERAGE_FILE"

# Run tests with race detection and coverage for each package
for package in $(go list ./... | grep -v vendor); do
go test -race -coverprofile="$PROFILE_FILE" -covermode=atomic "$package"

# Append profile output to the coverage file if it exists
if [ -f "$PROFILE_FILE" ]; then
cat "$PROFILE_FILE" >>"$COVERAGE_FILE"
rm "$PROFILE_FILE"
fi
done

echo "🟢 Coverage results written to $COVERAGE_FILE"

0 comments on commit 9ac648b

Please sign in to comment.