Repository navigation
Expand file tree
/
Copy pathTaskfile.yml
More file actions
91 lines (82 loc) · 2.78 KB
/
Copy pathTaskfile.yml
File metadata and controls
91 lines (82 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
version: '3'
tasks:
deps:
desc: Install system dependencies, swag, gotestsum, and go-test-report
cmds:
- |
if command -v apt-get > /dev/null; then
echo "Using apt-get..."
sudo apt-get update
sudo apt-get install -y build-essential libpam-dev
elif command -v dnf > /dev/null; then
echo "Using dnf..."
sudo dnf install -y pam-devel
elif command -v yum > /dev/null; then
echo "Using yum..."
sudo yum install -y pam-devel
else
echo "Unsupported package manager. Please install the dependencies manually."
exit 1
fi
- go install github.com/swaggo/swag/cmd/swag@latest
- go install gotest.tools/gotestsum@latest
- go install github.com/FloSch62/go-test2html@latest
tidy:
desc: Run go mod tidy
cmds:
- go mod tidy
swag:
desc: Generate Swagger docs
cmds:
- swag init -g cmd/server/main.go
build:
desc: Build the clab-api-server binary with version information
cmds:
- |
VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "development")
COMMIT=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
DATE=$(date -u +'%Y-%m-%dT%H:%M:%SZ')
mkdir -p dist
TARGETARCH=${TARGETARCH:-$(go env GOARCH)}
go build -ldflags="-X main.version=$VERSION -X main.commit=$COMMIT -X main.date=$DATE" -o dist/clab-api-server-linux-${TARGETARCH} ./cmd/server
create-test-dir:
desc: Create test reports directory
cmds:
- mkdir -p test-reports
run-tests:
desc: Run tests with gotestsum (may fail)
internal: true
cmds:
- |
echo "Running tests..."
export GOTEST_LOG_LEVEL=debug
set -a && [ -f tests_go/.env ] && . tests_go/.env ; set +a
gotestsum --format=standard-verbose --jsonfile=test-reports/test-output.json -- -count=1 ./... || true
generate-report:
desc: Generate HTML test report
internal: true
cmds:
- |
echo "Generating HTML report..."
go-test2html --input test-reports/test-output.json --output test-reports/test-report.html
test:
desc: Run tests with gotestsum and generate HTML report
deps: [create-test-dir]
cmds:
- task: run-tests
- task: generate-report
# Now determine the actual test result by examining the JSON file
- |
if grep -q '"Action":"fail"' test-reports/test-output.json; then
echo "Tests failed! See report at test-reports/test-report.html"
exit 1
else
echo "All tests passed! See report at test-reports/test-report.html"
exit 0
fi
default:
desc: Run all key steps (tidy, swag, build)
cmds:
- task: tidy
- task: swag
- task: build