Skip to content

Commit 9ac648b

Browse files
committed
🔧 chore: add go_deps.sh #2
1 parent 0ab07ca commit 9ac648b

2 files changed

Lines changed: 33 additions & 0 deletions

File tree

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,3 +38,8 @@ deps-upgrade:
3838
# Removes all items from the Go module cache
3939
deps-clean-cache:
4040
go clean -modcache
41+
42+
# Running code coverage
43+
# Generates code coverage report and logs the results
44+
coverage:
45+
sh ./sh/go_deps.sh

sh/go_deps.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#!/usr/bin/env bash
2+
3+
# Set up directories and files
4+
LOG_DIR="logs"
5+
COVERAGE_FILE="$LOG_DIR/coverage.txt"
6+
PROFILE_FILE="profile.out"
7+
8+
# Ensure the logs directory exists
9+
mkdir -p "$LOG_DIR"
10+
11+
# Exit immediately if a command exits with a non-zero status
12+
set -e
13+
14+
# Initialize the coverage file
15+
>"$COVERAGE_FILE"
16+
17+
# Run tests with race detection and coverage for each package
18+
for package in $(go list ./... | grep -v vendor); do
19+
go test -race -coverprofile="$PROFILE_FILE" -covermode=atomic "$package"
20+
21+
# Append profile output to the coverage file if it exists
22+
if [ -f "$PROFILE_FILE" ]; then
23+
cat "$PROFILE_FILE" >>"$COVERAGE_FILE"
24+
rm "$PROFILE_FILE"
25+
fi
26+
done
27+
28+
echo "🟢 Coverage results written to $COVERAGE_FILE"

0 commit comments

Comments
 (0)