-
Notifications
You must be signed in to change notification settings - Fork 0
518 lines (437 loc) · 17.4 KB
/
ci.yml
File metadata and controls
518 lines (437 loc) · 17.4 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
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
name: CI/CD Pipeline
on:
push:
branches: [ main, master ]
tags:
- 'v*'
pull_request:
branches: [ main, master ]
env:
WINDOWS_APP_NAME: NetworkMonitor-Windows
LINUX_APP_NAME: NetworkMonitor-Linux
MACOS_APP_NAME: NetworkMonitor-macOS
jobs:
test:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-build.txt
- name: Install system dependencies (Linux)
if: runner.os == 'Linux'
run: |
sudo apt-get update
sudo apt-get install -y net-tools iptables tcpdump libpcap-dev
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install libpcap tcpdump
- name: Install system dependencies (Windows)
if: runner.os == 'Windows'
run: |
curl -L https://npcap.com/dist/npcap-1.60.exe -o npcap-installer.exe
.\npcap-installer.exe /S /winpcap_mode=yes
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip setuptools wheel
pip install -r requirements.txt --no-cache-dir
pip install -r requirements-build.txt --no-cache-dir
pip install pytest pytest-cov pytest-xdist mock
- name: Run tests
run: |
python -m pytest tests/ -v --cov=networkmonitor --junitxml=pytest.xml --cov-report=xml
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results-${{ matrix.os }}
path: |
pytest.xml
coverage.xml
retention-days: 30
build:
needs: test
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
cache-dependency-path: |
requirements.txt
requirements-build.txt
- name: Get version
id: get_version
shell: bash
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
SHORT_SHA=$(git rev-parse --short HEAD)
VERSION="0.1.0-alpha.${SHORT_SHA}"
fi
echo "Version will be: $VERSION"
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Generate platform icons (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Install ImageMagick if needed
if (!(Get-Command magick -ErrorAction SilentlyContinue)) {
choco install imagemagick.app -y
}
# Convert SVG to ICO
magick convert -background none assets/icon.svg -define icon:auto-resize=256,128,64,48,32,16 assets/icon.ico
- name: Generate platform icons (macOS)
if: runner.os == 'macOS'
run: |
brew install imagemagick
# Create iconset directory
mkdir icon.iconset
# Convert SVG to PNG in different sizes
convert -background none -resize 16x16 assets/icon.svg icon.iconset/icon_16x16.png
convert -background none -resize 32x32 assets/icon.svg icon.iconset/icon_16x16@2x.png
convert -background none -resize 32x32 assets/icon.svg icon.iconset/icon_32x32.png
convert -background none -resize 64x64 assets/icon.svg icon.iconset/icon_32x32@2x.png
convert -background none -resize 128x128 assets/icon.svg icon.iconset/icon_128x128.png
convert -background none -resize 256x256 assets/icon.svg icon.iconset/icon_128x128@2x.png
convert -background none -resize 256x256 assets/icon.svg icon.iconset/icon_256x256.png
convert -background none -resize 512x512 assets/icon.svg icon.iconset/icon_256x256@2x.png
convert -background none -resize 512x512 assets/icon.svg icon.iconset/icon_512x512.png
convert -background none -resize 1024x1024 assets/icon.svg icon.iconset/icon_512x512@2x.png
# Convert iconset to icns
iconutil -c icns icon.iconset
# Move to assets directory
mv icon.icns assets/icon.icns
- name: Install system dependencies (Windows)
if: runner.os == 'Windows'
run: |
choco install nsis
choco install gtk-runtime
- name: Bundle Npcap and VC++ Runtime (Windows)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Create bundled_resources directories
New-Item -ItemType Directory -Force -Path "bundled_resources/Npcap"
New-Item -ItemType Directory -Force -Path "bundled_resources/vcruntime"
# Download Npcap installer (silent/OEM version)
Write-Host "Downloading Npcap installer..."
Invoke-WebRequest -Uri "https://npcap.com/dist/npcap-1.79.exe" -OutFile "bundled_resources/Npcap/npcap-installer.exe"
# Download VC++ Runtime
Write-Host "Downloading VC++ Runtime..."
Invoke-WebRequest -Uri "https://aka.ms/vs/17/release/vc_redist.x64.exe" -OutFile "bundled_resources/vcruntime/vc_redist.x64.exe"
Write-Host "Bundled resources ready!"
Get-ChildItem bundled_resources -Recurse
- name: Install system dependencies (macOS)
if: runner.os == 'macOS'
run: |
brew install imagemagick
# Convert SVG to PNG in different sizes
convert -background none -resize 16x16 assets/icon.svg icon.iconset/icon_16x16.png
convert -background none -resize 32x32 assets/icon.svg icon.iconset/icon_16x16@2x.png
convert -background none -resize 32x32 assets/icon.svg icon.iconset/icon_32x32.png
convert -background none -resize 64x64 assets/icon.svg icon.iconset/icon_32x32@2x.png
convert -background none -resize 128x128 assets/icon.svg icon.iconset/icon_128x128.png
convert -background none -resize 256x256 assets/icon.svg icon.iconset/icon_128x128@2x.png
convert -background none -resize 256x256 assets/icon.svg icon.iconset/icon_256x256.png
convert -background none -resize 512x512 assets/icon.svg icon.iconset/icon_256x256@2x.png
convert -background none -resize 512x512 assets/icon.svg icon.iconset/icon_512x512.png
convert -background none -resize 1024x1024 assets/icon.svg icon.iconset/icon_512x512@2x.png
# Convert iconset to icns
iconutil -c icns icon.iconset
# Move to assets directory
mv icon.icns assets/icon.icns
- name: Install Python dependencies
shell: bash
run: |
python -m pip install --upgrade pip setuptools wheel
# Install core dependencies separately first to ensure they're available
pip install flask==2.0.0 flask-cors==3.0.0 click==8.0.0 scapy==2.5.0 --no-cache-dir
# Install build requirements
pip install -r requirements-build.txt --no-cache-dir || {
echo "Some build requirements failed but continuing..."
# List what was actually installed
pip list
}
# Install main requirements
pip install -r requirements.txt --no-cache-dir || {
echo "Some requirements failed but continuing..."
# List what was actually installed
pip list
}
# Verify critical packages are installed
python -c "import flask; import click; import scapy; print('Core dependencies verified')" || exit 1
- name: Build application
env:
APP_VERSION: ${{ steps.get_version.outputs.version }}
run: |
# Verify Python environment before build
python --version
which python
pip list
# Run build with more verbosity for debugging
python -v build.py
- name: Build Windows Installer (NSIS)
if: runner.os == 'Windows'
shell: pwsh
run: |
# Verify build output exists
if (!(Test-Path "dist/NetworkMonitor.exe")) {
Write-Error "NetworkMonitor.exe not found in dist/"
exit 1
}
# Find makensis - choco installs to Program Files
$nsisPath = "C:\Program Files (x86)\NSIS\makensis.exe"
if (!(Test-Path $nsisPath)) {
$nsisPath = "C:\Program Files\NSIS\makensis.exe"
}
if (!(Test-Path $nsisPath)) {
# Try to find it via where command
$nsisPath = (Get-Command makensis -ErrorAction SilentlyContinue).Source
}
if (!$nsisPath -or !(Test-Path $nsisPath)) {
Write-Error "NSIS makensis.exe not found!"
exit 1
}
Write-Host "Using NSIS at: $nsisPath"
# Build NSIS installer
Write-Host "Building NSIS installer..."
& $nsisPath installer.nsi
if ($LASTEXITCODE -ne 0) {
Write-Error "NSIS build failed with exit code $LASTEXITCODE"
exit 1
}
# Verify installer was created
if (Test-Path "dist/NetworkMonitor-Setup-*.exe") {
Write-Host "Installer created successfully!"
Get-ChildItem dist/*.exe
} else {
Write-Error "Installer not created!"
exit 1
}
- name: Package Windows artifacts
if: runner.os == 'Windows'
run: |
cd dist
7z a -tzip ${{ env.WINDOWS_APP_NAME }}-${{ steps.get_version.outputs.version }}.zip NetworkMonitor.exe
7z a -tzip ${{ env.WINDOWS_APP_NAME }}-Installer-${{ steps.get_version.outputs.version }}.zip NetworkMonitor-Setup-*.exe
- name: Package Linux artifact
if: runner.os == 'Linux'
run: |
cd dist
tar czf ${{ env.LINUX_APP_NAME }}-${{ steps.get_version.outputs.version }}.tar.gz NetworkMonitor
- name: Package macOS artifact
if: runner.os == 'macOS'
run: |
cd dist
if [ -d "NetworkMonitor.app" ]; then
# Package app bundle if it exists
zip -r ${{ env.MACOS_APP_NAME }}-${{ steps.get_version.outputs.version }}.zip NetworkMonitor.app
elif [ -f "NetworkMonitor" ]; then
# Package binary if app bundle doesn't exist
zip -r ${{ env.MACOS_APP_NAME }}-${{ steps.get_version.outputs.version }}.zip NetworkMonitor
else
echo "No build artifacts found in dist directory"
ls -la
exit 1
fi
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ runner.os }}-artifacts
path: |
dist/*.zip
dist/*.tar.gz
dist/*.dmg
retention-days: 5
create-release:
needs: build
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/master' || startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for changelog generation
- name: Get version
id: get_version
run: |
if [[ $GITHUB_REF == refs/tags/* ]]; then
VERSION=${GITHUB_REF#refs/tags/v}
else
# For main/master, use date-based version
VERSION="0.1.0-$(date +'%Y%m%d')-${GITHUB_SHA::7}"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
merge-multiple: true
- name: Display structure of downloaded files
run: ls -R artifacts/
- name: Generate Release Notes
id: changelog
run: |
# Get latest changes since last release or last 10 commits if no releases
if git describe --tags --abbrev=0 2>/dev/null; then
LAST_TAG=$(git describe --tags --abbrev=0)
CHANGES=$(git log --pretty=format:"* %s" $LAST_TAG..HEAD)
else
CHANGES=$(git log --pretty=format:"* %s" -n 10)
fi
# Save changes to file
echo "## What's New" > release_notes.md
echo "" >> release_notes.md
echo "$CHANGES" >> release_notes.md
- name: Create Release
uses: softprops/action-gh-release@v2
with:
name: NetworkMonitor v${{ steps.get_version.outputs.version }}
body_path: release_notes.md
draft: false
prerelease: ${{ !startsWith(github.ref, 'refs/tags/') }}
tag_name: v${{ steps.get_version.outputs.version }}
files: |
artifacts/**/*.zip
artifacts/**/*.tar.gz
artifacts/**/*.dmg
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
publish-to-gh-pages:
needs: create-release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-latest
permissions:
contents: read
pages: write
id-token: write
actions: write # Add this permission
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}
steps:
- uses: actions/checkout@v4
- name: Enable GitHub Pages
run: |
# Enable via API
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/pages \
-d '{"source":{"branch":"gh-pages","path":"/"}}'
continue-on-error: true # Continue even if already enabled
- name: Setup Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install mkdocs mkdocs-material jq
- name: Setup Pages
uses: actions/configure-pages@v4
- name: Build documentation
run: |
# Create required directories
mkdir -p docs/{guide,downloads}
# Copy documentation files, create if not exist
cp README.md docs/index.md || echo "# NetworkMonitor" > docs/index.md
cp DEVELOPER.md docs/guide/developer.md || echo "# Developer Guide" > docs/guide/developer.md
# Rest of your build documentation steps
VERSION="${GITHUB_REF#refs/tags/v}"
cat > docs/downloads/index.md << EOL
# Downloads
## Latest Release (v${VERSION})
### Windows
- [NetworkMonitor Setup (Installer)](https://github.com/${{ github.repository }}/releases/latest/download/NetworkMonitor-Windows-Setup-${VERSION}.zip)
- [NetworkMonitor Portable](https://github.com/${{ github.repository }}/releases/latest/download/NetworkMonitor-Windows-${VERSION}.zip)
### Linux
- [NetworkMonitor for Linux](https://github.com/${{ github.repository }}/releases/latest/download/NetworkMonitor-Linux-${VERSION}.tar.gz)
### macOS
- [NetworkMonitor for macOS](https://github.com/${{ github.repository }}/releases/latest/download/NetworkMonitor-macOS-${VERSION}.zip)
## System Requirements
### Windows
- Windows 10 or later (64-bit)
- [Npcap](https://npcap.com) installed in WinPcap compatibility mode
### Linux
- Modern Linux distribution (Ubuntu 20.04+, Debian 11+, etc.)
- libpcap installed (\`sudo apt install libpcap-dev\` or equivalent)
- Root/sudo privileges for packet capture
### macOS
- macOS 10.15 (Catalina) or later
- libpcap installed (pre-installed or via \`brew install libpcap\`)
- Root privileges for packet capture
EOL
cat > mkdocs.yml << EOL
site_name: NetworkMonitor
site_description: Network monitoring and analysis tool
repo_url: https://github.com/${{ github.repository }}
edit_uri: edit/main/docs/
theme:
name: material
palette:
scheme: slate
primary: blue
accent: light blue
features:
- navigation.instant
- navigation.tracking
- navigation.sections
- navigation.expand
- navigation.top
- toc.follow
- search.suggest
- search.highlight
nav:
- Home: index.md
- Downloads: downloads/index.md
- Documentation:
- Developer Guide: guide/developer.md
markdown_extensions:
- pymdownx.highlight:
anchor_linenums: true
- pymdownx.inlinehilite
- pymdownx.snippets
- pymdownx.superfences
- admonition
- footnotes
- attr_list
- md_in_html
EOL
mkdocs build
- name: Upload Pages artifact
uses: actions/upload-pages-artifact@v3 # Replace v4 with v3
with:
path: site
retention-days: 30 # Added retention period
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
artifact_name: github-pages
preview: false
error_count: 3 # Number of retries
timeout: 600000 # 10 minutes timeout