-
Notifications
You must be signed in to change notification settings - Fork 12
145 lines (124 loc) · 4.04 KB
/
Copy pathpr-tests.yml
File metadata and controls
145 lines (124 loc) · 4.04 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
name: Pull Request Tests
on:
pull_request:
types:
- opened
- synchronize
- reopened
- ready_for_review
workflow_dispatch:
permissions:
contents: read
jobs:
tests-go:
name: API + containerlab tests
runs-on: ubuntu-24.04
timeout-minutes: 60
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Ensure runner workspace env (act compatibility)
if: env.RUNNER_WORKSPACE == ''
run: echo "RUNNER_WORKSPACE=${GITHUB_WORKSPACE}/.runner-workspace" >> "$GITHUB_ENV"
- name: Generate tests_go/.env
run: |
if [ ! -f tests_go/.env ]; then
cp tests_go/.env.example tests_go/.env
fi
- name: Generate root .env
run: |
if [ ! -f .env ]; then
cp .env.example .env
fi
- name: Set up Go
uses: WillAbides/setup-go-faster@v1.14.0
with:
go-version: '1.24.x'
- name: Cache Go modules
uses: actions/cache@v5
with:
path: |
~/go/pkg/mod
~/.cache/go-build
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Install go-task
run: |
curl -sSL https://taskfile.dev/install.sh | sudo sh -s -- -b /usr/local/bin
task --version
- name: Install Go test tooling
run: |
go install gotest.tools/gotestsum@latest
go install github.com/FloSch62/go-test2html@latest
- name: Install system dependencies
run: |
sudo apt-get update
sudo apt-get install -y --no-install-recommends libpam0g-dev curl
- name: Install containerlab
run: |
curl -fsSL https://get.containerlab.dev | sudo -E bash
containerlab version
- name: Containerlab CLI smoke test
run: |
cat <<'EOF' >/tmp/pr-smoke.clab.yml
name: pr-smoke
topology:
nodes:
srl1:
kind: linux
image: ghcr.io/srl-labs/network-multitool:latest
srl2:
kind: linux
image: ghcr.io/srl-labs/network-multitool:latest
links:
- endpoints: ["srl1:eth1", "srl2:eth1"]
EOF
sudo containerlab deploy \
--network act-pr-smoke \
--ipv4-subnet 172.31.20.0/24 \
--ipv6-subnet 2001:db8:ac:20::/64 \
-t /tmp/pr-smoke.clab.yml
sudo containerlab inspect -t /tmp/pr-smoke.clab.yml
sudo containerlab destroy -t /tmp/pr-smoke.clab.yml --cleanup --yes
- name: Prepare Linux users for tests_go
run: sudo scripts/setup-tests-go-env.sh
- name: Build API server
env:
CGO_ENABLED: 1
run: |
go build -trimpath -o dist/clab-api-server ./cmd/server
- name: Start API server
run: |
sudo bash -c "cd '$PWD' && env API_SERVER_HOST=127.0.0.1 ./dist/clab-api-server -env-file .env > server.log 2>&1 & echo \$! > server.pid"
sudo chown "$USER:$USER" server.log server.pid
sleep 5
- name: Wait for API readiness
run: timeout 60 bash -c 'until curl -fsS http://127.0.0.1:8080/health >/dev/null; do sleep 2; done'
- name: Run Task tests
env:
GOTEST_LOG_LEVEL: debug
run: task test
- name: Stop API server
if: always()
run: |
if [ -f server.pid ]; then
sudo kill "$(cat server.pid)" || true
fi
- name: Dump API server logs
if: always()
run: |
if [ -f server.log ]; then
cat server.log
fi
- name: Upload HTML test report
if: always()
uses: actions/upload-artifact@v6
with:
name: go-test-report
path: test-reports/test-report.html
if-no-files-found: warn
- name: Cleanup leftover labs
if: always()
run: |
sudo containerlab destroy --all --cleanup --yes || true