feat: add web builds to CI/CD and fix version management #44
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Desktop Builds | |
| on: | |
| push: | |
| branches: [ main ] | |
| tags: | |
| - 'v*.*.*' | |
| paths: | |
| - 'frontend/**' | |
| - 'cmd/network-debugger/**' | |
| - 'cmd/network-debugger-web/**' | |
| - 'internal/**' | |
| - 'scripts/package-*.sh' | |
| - 'scripts/package-*.ps1' | |
| - '.github/workflows/build-desktop.yml' | |
| pull_request: | |
| paths: | |
| - 'frontend/**' | |
| - 'cmd/network-debugger/**' | |
| - 'cmd/network-debugger-web/**' | |
| - 'internal/**' | |
| - 'scripts/package-*.sh' | |
| - 'scripts/package-*.ps1' | |
| - '.github/workflows/build-desktop.yml' | |
| workflow_dispatch: | |
| permissions: | |
| contents: write | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }} | |
| cancel-in-progress: true | |
| jobs: | |
| build-macos: | |
| runs-on: macos-latest | |
| strategy: | |
| matrix: | |
| arch: [x86_64, arm64] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22.x' | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.x' | |
| channel: 'stable' | |
| - name: Install create-dmg | |
| run: brew install create-dmg | |
| - name: Cache Flutter dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.pub-cache | |
| frontend/.dart_tool | |
| key: ${{ runner.os }}-flutter-${{ hashFiles('frontend/pubspec.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-flutter- | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Flutter pub get | |
| working-directory: frontend | |
| run: flutter pub get | |
| - name: Enable macOS desktop | |
| working-directory: frontend | |
| run: | | |
| flutter config --enable-macos-desktop | |
| flutter create --platforms=macos . | |
| - name: Set version | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=dev-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build macOS DMG | |
| env: | |
| VERSION: ${{ steps.version.outputs.VERSION }} | |
| run: | | |
| # Override architecture for cross-compilation if needed | |
| if [ "${{ matrix.arch }}" = "x86_64" ] && [ "$(uname -m)" != "x86_64" ]; then | |
| echo "Cross-compiling for x86_64 on arm64 host" | |
| # Build Go binary for x86_64 | |
| CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" \ | |
| -o dist/server_darwin_amd64 ./cmd/network-debugger | |
| # Flutter currently doesn't support cross-compilation for macOS | |
| # So we skip x86_64 builds on arm64 runners | |
| echo "Skipping x86_64 Flutter build on arm64 runner" | |
| exit 0 | |
| elif [ "${{ matrix.arch }}" = "arm64" ] && [ "$(uname -m)" != "arm64" ]; then | |
| echo "Cannot cross-compile arm64 on x86_64 runner" | |
| exit 0 | |
| fi | |
| chmod +x scripts/package-macos.sh | |
| ./scripts/package-macos.sh | |
| - name: Upload DMG artifact | |
| if: matrix.arch == runner.arch || matrix.arch == 'arm64' && runner.arch == 'ARM64' | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: macos-${{ matrix.arch }}-dmg | |
| path: dist/*.dmg | |
| retention-days: 7 | |
| # Временно отключили windows-сборку | |
| build-windows: | |
| runs-on: windows-latest | |
| if: false | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22.x' | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.x' | |
| channel: 'stable' | |
| - name: Cache Flutter dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~\AppData\Local\Pub\Cache | |
| frontend\.dart_tool | |
| key: ${{ runner.os }}-flutter-${{ hashFiles('frontend/pubspec.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-flutter- | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~\go\pkg\mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Flutter pub get | |
| working-directory: frontend | |
| run: flutter pub get | |
| - name: Enable Windows desktop | |
| working-directory: frontend | |
| run: | | |
| flutter config --enable-windows-desktop | |
| flutter create --platforms=windows . | |
| - name: Set version | |
| id: version | |
| shell: bash | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=dev-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build Windows ZIP | |
| shell: pwsh | |
| run: | | |
| $env:VERSION = "${{ steps.version.outputs.VERSION }}" | |
| ./scripts/package-windows.ps1 -Version $env:VERSION | |
| - name: Upload ZIP artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: windows-amd64-zip | |
| path: dist/*.zip | |
| retention-days: 7 | |
| build-linux: | |
| runs-on: ubuntu-latest | |
| strategy: | |
| matrix: | |
| arch: [amd64] | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22.x' | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.x' | |
| channel: 'stable' | |
| - name: Install Linux dependencies | |
| run: | | |
| sudo apt-get update | |
| sudo apt-get install -y \ | |
| clang cmake ninja-build pkg-config \ | |
| libgtk-3-dev liblzma-dev \ | |
| libstdc++-12-dev libsecret-1-dev | |
| - name: Cache Flutter dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.pub-cache | |
| frontend/.dart_tool | |
| key: ${{ runner.os }}-flutter-${{ hashFiles('frontend/pubspec.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-flutter- | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Flutter pub get | |
| working-directory: frontend | |
| run: flutter pub get | |
| - name: Enable Linux desktop | |
| working-directory: frontend | |
| run: | | |
| flutter config --enable-linux-desktop | |
| flutter create --platforms=linux . | |
| - name: Set version | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=dev-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build Linux packages | |
| env: | |
| VERSION: ${{ steps.version.outputs.VERSION }} | |
| ARCH: ${{ matrix.arch }} | |
| run: | | |
| chmod +x scripts/package-linux.sh | |
| ./scripts/package-linux.sh | |
| - name: Upload tar.gz artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: linux-${{ matrix.arch }}-tar | |
| path: dist/*.tar.gz | |
| retention-days: 7 | |
| - name: Upload deb artifact | |
| uses: actions/upload-artifact@v4 | |
| if: hashFiles('dist/*.deb') != '' | |
| with: | |
| name: linux-${{ matrix.arch }}-deb | |
| path: dist/*.deb | |
| retention-days: 7 | |
| build-web: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: '1.22.x' | |
| - name: Setup Flutter | |
| uses: subosito/flutter-action@v2 | |
| with: | |
| flutter-version: '3.x' | |
| channel: 'stable' | |
| - name: Cache Flutter dependencies | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| ~/.pub-cache | |
| frontend/.dart_tool | |
| key: ${{ runner.os }}-flutter-${{ hashFiles('frontend/pubspec.lock') }} | |
| restore-keys: | | |
| ${{ runner.os }}-flutter- | |
| - name: Cache Go modules | |
| uses: actions/cache@v4 | |
| with: | |
| path: ~/go/pkg/mod | |
| key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | |
| restore-keys: | | |
| ${{ runner.os }}-go- | |
| - name: Flutter pub get | |
| working-directory: frontend | |
| run: flutter pub get | |
| - name: Set version | |
| id: version | |
| run: | | |
| if [[ "${{ github.ref }}" == refs/tags/v* ]]; then | |
| echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| else | |
| echo "VERSION=dev-${GITHUB_SHA::7}" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Build Flutter web | |
| working-directory: frontend | |
| run: flutter build web --release --no-tree-shake-icons --no-wasm-dry-run | |
| - name: Copy web files to embed directory | |
| run: | | |
| rm -rf cmd/network-debugger-web/_web | |
| mkdir -p cmd/network-debugger-web/_web | |
| cp -R frontend/build/web/* cmd/network-debugger-web/_web/ | |
| - name: Build Go binaries with embedded web | |
| env: | |
| VERSION: ${{ steps.version.outputs.VERSION }} | |
| run: | | |
| mkdir -p dist | |
| # Build for all platforms | |
| echo "Building for darwin/amd64..." | |
| GOOS=darwin GOARCH=amd64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_darwin_amd64 ./cmd/network-debugger-web | |
| echo "Building for darwin/arm64..." | |
| GOOS=darwin GOARCH=arm64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_darwin_arm64 ./cmd/network-debugger-web | |
| echo "Building for linux/amd64..." | |
| GOOS=linux GOARCH=amd64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_linux_amd64 ./cmd/network-debugger-web | |
| echo "Building for linux/arm64..." | |
| GOOS=linux GOARCH=arm64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_linux_arm64 ./cmd/network-debugger-web | |
| echo "Building for windows/amd64..." | |
| GOOS=windows GOARCH=amd64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_windows_amd64.exe ./cmd/network-debugger-web | |
| echo "Building for windows/386..." | |
| GOOS=windows GOARCH=386 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_windows_386.exe ./cmd/network-debugger-web | |
| echo "Building for windows/arm64..." | |
| GOOS=windows GOARCH=arm64 go build -ldflags="-s -w" \ | |
| -o dist/network-debugger-web_windows_arm64.exe ./cmd/network-debugger-web | |
| - name: Create archives | |
| working-directory: dist | |
| run: | | |
| # Create tar.gz for unix platforms | |
| tar -czf network-debugger-web_darwin_amd64.tar.gz network-debugger-web_darwin_amd64 | |
| tar -czf network-debugger-web_darwin_arm64.tar.gz network-debugger-web_darwin_arm64 | |
| tar -czf network-debugger-web_linux_amd64.tar.gz network-debugger-web_linux_amd64 | |
| tar -czf network-debugger-web_linux_arm64.tar.gz network-debugger-web_linux_arm64 | |
| # Create zip for Windows | |
| zip network-debugger-web_windows_amd64.zip network-debugger-web_windows_amd64.exe | |
| zip network-debugger-web_windows_386.zip network-debugger-web_windows_386.exe | |
| zip network-debugger-web_windows_arm64.zip network-debugger-web_windows_arm64.exe | |
| # List all archives | |
| ls -lah *.tar.gz *.zip | |
| - name: Upload web artifacts | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: web-binaries | |
| path: | | |
| dist/*.tar.gz | |
| dist/*.zip | |
| retention-days: 7 | |
| # Release job - only runs on version tags | |
| release: | |
| needs: [build-macos, build-linux, build-web] | |
| runs-on: ubuntu-latest | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: Prepare release files | |
| run: | | |
| mkdir -p release | |
| find artifacts -type f \( -name "*.dmg" -o -name "*.zip" -o -name "*.tar.gz" -o -name "*.deb" \) -exec cp {} release/ \; | |
| ls -lah release/ | |
| - name: Extract version | |
| id: version | |
| run: echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_OUTPUT | |
| - name: Generate changelog | |
| id: changelog | |
| run: | | |
| echo "## What's Changed" > CHANGELOG.md | |
| echo "" >> CHANGELOG.md | |
| git log $(git describe --tags --abbrev=0 HEAD^)..HEAD --pretty=format:"- %s (%h)" >> CHANGELOG.md || echo "- Initial release" >> CHANGELOG.md | |
| - name: Create GitHub Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| files: release/* | |
| body_path: CHANGELOG.md | |
| draft: false | |
| prerelease: false | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| # Summary job | |
| summary: | |
| needs: [build-macos, build-linux, build-web] | |
| runs-on: ubuntu-latest | |
| if: always() | |
| steps: | |
| - name: Build Summary | |
| run: | | |
| echo "## Desktop Build Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "" >> $GITHUB_STEP_SUMMARY | |
| echo "| Platform | Status |" >> $GITHUB_STEP_SUMMARY | |
| echo "|----------|--------|" >> $GITHUB_STEP_SUMMARY | |
| echo "| macOS Desktop | ${{ needs.build-macos.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Linux Desktop | ${{ needs.build-linux.result }} |" >> $GITHUB_STEP_SUMMARY | |
| echo "| Web Binaries | ${{ needs.build-web.result }} |" >> $GITHUB_STEP_SUMMARY |