-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathTaskfile.yml
More file actions
330 lines (291 loc) · 10.8 KB
/
Copy pathTaskfile.yml
File metadata and controls
330 lines (291 loc) · 10.8 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
version: '3'
vars:
BIN: bin/nm-netbird-service
AUTH_DIALOG_BIN: bin/nm-netbird-auth-dialog
PROPERTIES_PLUGIN: bin/libnm-vpn-plugin-netbird.so
PROPERTIES_GTK3_EDITOR: bin/libnm-vpn-plugin-netbird-editor.so
PROPERTIES_GTK4_EDITOR: bin/libnm-gtk4-vpn-plugin-netbird-editor.so
PROPERTIES_MODEL_TEST: bin/nm-netbird-editor-model-test
PROPERTIES_PLUGIN_TEST: bin/nm-netbird-editor-plugin-test
BUS_NAME: org.freedesktop.NetworkManager.netbird
OBJECT_PATH: /org/freedesktop/NetworkManager/VPN/Plugin
PLUGIN_IFACE: org.freedesktop.NetworkManager.VPN.Plugin
SELINUX_POLICY_DIR: packaging/selinux
tasks:
deps:install:
desc: Install system build/test dependencies for this distro (set WITH_GTK4=1 for GTK 4 headers)
cmds:
- |
bash -euo pipefail <<'SH'
with_gtk4="${WITH_GTK4:-0}"
as_root() {
if [ "$(id -u)" -eq 0 ]; then
"$@"
else
command -v sudo >/dev/null 2>&1 || { echo "error: sudo is required when not running as root" >&2; exit 1; }
sudo "$@"
fi
}
is_enabled() {
case "$1" in
1|true|TRUE|yes|YES|on|ON) return 0 ;;
*) return 1 ;;
esac
}
if command -v apt-get >/dev/null 2>&1; then
packages=(
build-essential
pkg-config
libnm-dev
libgtk-3-dev
libnma-dev
libglib2.0-bin
xdg-utils
dbus
network-manager
)
if is_enabled "$with_gtk4"; then
packages+=(libgtk-4-dev libnma-gtk4-dev)
fi
as_root apt-get update
as_root apt-get install -y "${packages[@]}"
elif command -v pacman >/dev/null 2>&1; then
packages=(
base-devel
pkgconf
networkmanager
gtk3
libnma
glib2
xdg-utils
dbus
)
if is_enabled "$with_gtk4"; then
packages+=(gtk4)
if pacman -Si libnma-gtk4 >/dev/null 2>&1; then
packages+=(libnma-gtk4)
fi
fi
as_root pacman -Syu --needed "${packages[@]}"
elif command -v dnf >/dev/null 2>&1; then
packages=(
gcc
pkgconf-pkg-config
NetworkManager-libnm-devel
gtk3-devel
libnma-devel
glib2
xdg-utils
dbus-daemon
NetworkManager
)
if is_enabled "$with_gtk4"; then
packages+=(gtk4-devel libnma-gtk4-devel)
fi
as_root dnf install -y "${packages[@]}"
elif command -v yum >/dev/null 2>&1; then
packages=(
gcc
pkgconf-pkg-config
NetworkManager-libnm-devel
gtk3-devel
libnma-devel
glib2
xdg-utils
dbus-daemon
NetworkManager
)
if is_enabled "$with_gtk4"; then
packages+=(gtk4-devel libnma-gtk4-devel)
fi
as_root yum install -y "${packages[@]}"
else
echo "error: supported package manager not found (apt-get, pacman, dnf, or yum)" >&2
exit 1
fi
if command -v go >/dev/null 2>&1; then
go mod download
else
echo "warning: go is not installed; install Go 1.26.x or newer matching go.mod" >&2
fi
SH
tidy:
desc: Download modules and tidy go.mod/go.sum
cmds:
- go mod tidy
fmt:
desc: Format Go code
cmds:
- gofmt -w ./cmd ./internal
- go mod tidy
build:
desc: Build the NetworkManager VPN plugin binaries and editor plugin
deps: [build:go, build:properties]
selinux:build:
desc: Build the SELinux policy module with local SELinux policy headers
cmds:
- make -C {{.SELINUX_POLICY_DIR}}
selinux:build:fedora:
desc: Build and validate the SELinux policy module against Fedora policy
cmds:
- ./scripts/build-fedora-selinux-policy.sh
selinux:install:
desc: Install the SELinux policy module with semodule
deps: [selinux:build]
cmds:
- sudo make -C {{.SELINUX_POLICY_DIR}} install
selinux:clean:
desc: Remove generated SELinux policy build artifacts
cmds:
- make -C {{.SELINUX_POLICY_DIR}} clean
build:go:
desc: Build the Go service and auth-dialog binaries
cmds:
- mkdir -p bin
- go build -o {{.BIN}} ./cmd/nm-netbird-service
- go build -o {{.AUTH_DIALOG_BIN}} ./cmd/nm-netbird-auth-dialog
build:properties:
desc: Build the libnm VPN properties editor plugin and GTK 3 editor
cmds:
- mkdir -p bin
- cc -Wall -Wextra -fPIC -shared -o {{.PROPERTIES_PLUGIN}} properties/nm-netbird-editor-plugin.c $(pkg-config --cflags --libs libnm) -ldl
- cc -Wall -Wextra -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_3_22 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_3_22 -fPIC -shared -o {{.PROPERTIES_GTK3_EDITOR}} properties/nm-netbird-editor-model.c properties/nm-netbird-editor.c $(pkg-config --cflags --libs libnm gtk+-3.0 libnma)
build:properties:gtk4:
desc: Build the GTK 4 libnm VPN properties editor plugin
cmds:
- mkdir -p bin
- cc -Wall -Wextra -DGDK_VERSION_MIN_REQUIRED=GDK_VERSION_4_0 -DGDK_VERSION_MAX_ALLOWED=GDK_VERSION_4_0 -fPIC -shared -o {{.PROPERTIES_GTK4_EDITOR}} properties/nm-netbird-editor-model.c properties/nm-netbird-editor.c $(pkg-config --cflags --libs libnm gtk4 libnma-gtk4)
test:
desc: Run unit tests
deps: [test:go, test:properties]
test:go:
desc: Run Go unit tests
cmds:
- go test ./...
test:properties:
desc: Run properties editor model tests
deps: [build:properties]
cmds:
- mkdir -p bin
- cc -Wall -Wextra -o {{.PROPERTIES_MODEL_TEST}} properties/nm-netbird-editor-model.c properties/nm-netbird-editor-model-test.c $(pkg-config --cflags --libs libnm)
- ./{{.PROPERTIES_MODEL_TEST}}
- cc -Wall -Wextra -o {{.PROPERTIES_PLUGIN_TEST}} properties/nm-netbird-editor-plugin-test.c $(pkg-config --cflags --libs libnm)
- NETBIRD_EDITOR_PLUGIN_PATH=$(pwd)/{{.PROPERTIES_PLUGIN}} ./{{.PROPERTIES_PLUGIN_TEST}}
test:race:
desc: Run unit tests with the Go race detector
cmds:
- go test -race ./...
run:session:
desc: Run the plugin on the session bus for local development
deps: [build]
cmds:
- ./{{.BIN}} --bus=session --debug
run:system:
desc: Run the plugin on the system bus, as NetworkManager would use it
deps: [build]
cmds:
- sudo ./{{.BIN}} --bus=system --debug
dbus:introspect:
desc: Introspect the development instance on the session bus
cmds:
- gdbus introspect --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}}
dbus:state:
desc: Read the plugin State property from the session bus
cmds:
- gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method org.freedesktop.DBus.Properties.Get "'{{.PLUGIN_IFACE}}'" "'State'"
dbus:need-secrets:
desc: Call NeedSecrets with an empty NetworkManager settings map
cmds:
- gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.NeedSecrets "{}"
dbus:connect:
desc: Call Connect with an empty NetworkManager settings map
cmds:
- gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.Connect "{}"
dbus:connect-interactive:
desc: Call ConnectInteractive with empty settings and details maps
cmds:
- gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.ConnectInteractive "{}" "{}"
dbus:disconnect:
desc: Call Disconnect on the development instance
cmds:
- gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.Disconnect
dbus:monitor:
desc: Monitor plugin D-Bus traffic/signals on the session bus
cmds:
- gdbus monitor --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}}
smoke:
desc: Build, launch on the session bus, introspect, call a few methods, then stop
deps: [build]
cmds:
- |
bash -euo pipefail <<'SH'
./{{.BIN}} --bus=session --debug &
pid=$!
trap 'kill "$pid" >/dev/null 2>&1 || true; wait "$pid" 2>/dev/null || true' EXIT
for i in $(seq 1 30); do
if gdbus introspect --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} >/dev/null 2>&1; then
break
fi
sleep 0.1
done
gdbus introspect --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} >/dev/null
gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.NeedSecrets "{}"
gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.Connect "{}"
gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method org.freedesktop.DBus.Properties.Get "'{{.PLUGIN_IFACE}}'" "'State'"
gdbus call --session --dest {{.BUS_NAME}} --object-path {{.OBJECT_PATH}} --method {{.PLUGIN_IFACE}}.Disconnect
kill "$pid" >/dev/null 2>&1 || true
wait "$pid" 2>/dev/null || true
trap - EXIT
SH
vet:
desc: Run go vet
cmds:
- go vet ./...
lint:
desc: Run golangci-lint
cmds:
- golangci-lint run
patterns:
desc: Run pragmatic code-pattern review checks
cmds:
- opengrep --config ./opengrep/pragmatic-go.yml --exclude '*.pb.go' .
complexity:
desc: Run complexity-oriented checks
cmds:
- golangci-lint run --enable=gocognit --enable=gocyclo --enable=nestif --enable=funlen
quality:
desc: Run the standard local quality gate
cmds:
- task: fmt
- task: vet
- task: test
- task: lint
- task: patterns
quality:full:
desc: Run the full quality gate, including race tests
cmds:
- task: fmt
- task: vet
- task: test
- task: test:race
- task: lint
- task: patterns
hooks:install:
desc: Install local git hooks
cmds:
- chmod +x scripts/hooks/pre-commit scripts/install-hooks.sh
- ./scripts/install-hooks.sh
install:fedora:
desc: Install the application in Fedora (tested on Fedora 44)
deps: [build:go, build:properties, build:properties:gtk4]
cmds:
- |
sudo env \
SERVICE_SRC="$(pwd)/{{.BIN}}" \
AUTH_DIALOG_SRC="$(pwd)/{{.AUTH_DIALOG_BIN}}" \
PROPERTIES_PLUGIN_SRC="$(pwd)/{{.PROPERTIES_PLUGIN}}" \
PROPERTIES_GTK3_EDITOR_SRC="$(pwd)/{{.PROPERTIES_GTK3_EDITOR}}" \
PROPERTIES_GTK4_EDITOR_SRC="$(pwd)/{{.PROPERTIES_GTK4_EDITOR}}" \
./scripts/install-release.sh
- sudo pkill -f '/usr/libexec/nm-netbird-service' || true
- sudo systemctl restart NetworkManager