fix: include frontend/dist in correct path for release packages #3
Workflow file for this run
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: Build and Release | |
| on: | |
| push: | |
| tags: | |
| - 'v*' | |
| workflow_dispatch: | |
| inputs: | |
| version: | |
| description: 'Version tag (e.g., v1.0.0)' | |
| required: false | |
| default: 'dev' | |
| env: | |
| GO_VERSION: '1.24' | |
| NODE_VERSION: '20' | |
| jobs: | |
| build-frontend: | |
| name: Build Frontend | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: ${{ env.NODE_VERSION }} | |
| cache: 'npm' | |
| cache-dependency-path: frontend/package-lock.json | |
| - name: Install dependencies | |
| working-directory: frontend | |
| run: npm ci | |
| - name: Build frontend | |
| working-directory: frontend | |
| run: npm run build | |
| - name: Upload frontend artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: frontend-dist | |
| path: frontend/dist | |
| retention-days: 1 | |
| build-binaries: | |
| name: Build ${{ matrix.name }} | |
| runs-on: ubuntu-latest | |
| needs: build-frontend | |
| strategy: | |
| matrix: | |
| include: | |
| - name: Linux x64 | |
| goos: linux | |
| goarch: amd64 | |
| artifact: nettool-linux-amd64 | |
| - name: Linux x32 | |
| goos: linux | |
| goarch: '386' | |
| artifact: nettool-linux-386 | |
| - name: Linux Pi Zero (ARMv6) | |
| goos: linux | |
| goarch: arm | |
| goarm: '6' | |
| artifact: nettool-linux-arm6 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup Go | |
| uses: actions/setup-go@v5 | |
| with: | |
| go-version: ${{ env.GO_VERSION }} | |
| - name: Download frontend artifact | |
| uses: actions/download-artifact@v4 | |
| with: | |
| name: frontend-dist | |
| path: frontend/dist | |
| - name: Get version info | |
| id: version | |
| run: | | |
| if [ "${{ github.event_name }}" == "push" ]; then | |
| VERSION=${GITHUB_REF#refs/tags/} | |
| elif [ "${{ github.event.inputs.version }}" != "" ]; then | |
| VERSION=${{ github.event.inputs.version }} | |
| else | |
| VERSION="dev-$(git rev-parse --short HEAD)" | |
| fi | |
| echo "version=$VERSION" >> $GITHUB_OUTPUT | |
| echo "commit=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT | |
| echo "build_time=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT | |
| - name: Build binary | |
| env: | |
| GOOS: ${{ matrix.goos }} | |
| GOARCH: ${{ matrix.goarch }} | |
| GOARM: ${{ matrix.goarm }} | |
| CGO_ENABLED: '0' | |
| run: | | |
| LDFLAGS="-w -s" | |
| LDFLAGS="$LDFLAGS -X main.Version=${{ steps.version.outputs.version }}" | |
| LDFLAGS="$LDFLAGS -X main.BuildTime=${{ steps.version.outputs.build_time }}" | |
| LDFLAGS="$LDFLAGS -X main.GitCommit=${{ steps.version.outputs.commit }}" | |
| echo "Building NetTool for ${{ matrix.name }}..." | |
| go build -ldflags "$LDFLAGS" -o nettool ./main.go | |
| echo "Building CLI tool..." | |
| go build -ldflags "$LDFLAGS" -o nettool-iterate ./app/cmd/iterate/main.go | |
| - name: Prepare package | |
| run: | | |
| mkdir -p package/frontend/dist | |
| mkdir -p package/app/plugins/plugins | |
| # Copy binaries | |
| cp nettool package/ | |
| cp nettool-iterate package/ | |
| # Copy frontend (must be in frontend/dist for the server) | |
| cp -r frontend/dist/* package/frontend/dist/ | |
| # Copy plugin config | |
| cp app/plugins/config.json.example package/app/plugins/ | |
| [ -f app/plugins/config.json ] && cp app/plugins/config.json package/app/plugins/ || true | |
| # Copy documentation | |
| cp README.md package/ || true | |
| cp LICENSE package/ || true | |
| # Create install script | |
| cat > package/install.sh << 'INSTALL_EOF' | |
| #!/bin/bash | |
| set -e | |
| INSTALL_DIR="/opt/nettool" | |
| SERVICE_FILE="/etc/systemd/system/nettool.service" | |
| USER="nettool" | |
| GROUP="nettool" | |
| echo "🚀 Installing NetTool..." | |
| if [ "$EUID" -ne 0 ]; then | |
| echo "❌ Please run as root (use sudo)" | |
| exit 1 | |
| fi | |
| # Create user and group | |
| if ! getent group $GROUP >/dev/null; then | |
| groupadd --system $GROUP | |
| fi | |
| if ! getent passwd $USER >/dev/null; then | |
| useradd --system --gid $GROUP --shell /bin/false --home-dir $INSTALL_DIR $USER | |
| fi | |
| # Create directory and copy files | |
| mkdir -p $INSTALL_DIR | |
| cp -r . $INSTALL_DIR/ | |
| chown -R $USER:$GROUP $INSTALL_DIR | |
| chmod +x $INSTALL_DIR/nettool $INSTALL_DIR/nettool-iterate | |
| # Create symlinks | |
| ln -sf $INSTALL_DIR/nettool /usr/local/bin/nettool | |
| ln -sf $INSTALL_DIR/nettool-iterate /usr/local/bin/nettool-iterate | |
| # Create systemd service | |
| cat > $SERVICE_FILE << 'SERVICE_EOF' | |
| [Unit] | |
| Description=NetTool Network Analysis Server | |
| After=network.target | |
| [Service] | |
| Type=simple | |
| User=nettool | |
| Group=nettool | |
| WorkingDirectory=/opt/nettool | |
| ExecStart=/opt/nettool/nettool --port=8080 | |
| Restart=always | |
| RestartSec=5 | |
| [Install] | |
| WantedBy=multi-user.target | |
| SERVICE_EOF | |
| systemctl daemon-reload | |
| systemctl enable nettool | |
| echo "✅ Installation complete!" | |
| echo " Start: sudo systemctl start nettool" | |
| echo " Logs: sudo journalctl -u nettool -f" | |
| echo " Web: http://localhost:8080" | |
| INSTALL_EOF | |
| chmod +x package/install.sh | |
| - name: Create archive | |
| run: | | |
| cd package | |
| tar -czvf ../${{ matrix.artifact }}-${{ steps.version.outputs.version }}.tar.gz . | |
| - name: Upload artifact | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: ${{ matrix.artifact }} | |
| path: ${{ matrix.artifact }}-${{ steps.version.outputs.version }}.tar.gz | |
| retention-days: 30 | |
| release: | |
| name: Create Release | |
| runs-on: ubuntu-latest | |
| needs: build-binaries | |
| if: github.event_name == 'push' && startsWith(github.ref, 'refs/tags/v') | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Get version | |
| id: version | |
| run: echo "version=${GITHUB_REF#refs/tags/}" >> $GITHUB_OUTPUT | |
| - name: Download all artifacts | |
| uses: actions/download-artifact@v4 | |
| with: | |
| path: artifacts | |
| - name: List artifacts | |
| run: | | |
| echo "Artifacts downloaded:" | |
| find artifacts -type f -name "*.tar.gz" | head -20 | |
| - name: Move artifacts | |
| run: | | |
| mkdir -p release-files | |
| find artifacts -name "*.tar.gz" -exec mv {} release-files/ \; | |
| echo "Release files:" | |
| ls -la release-files/ | |
| - name: Create Release | |
| uses: softprops/action-gh-release@v2 | |
| with: | |
| tag_name: ${{ steps.version.outputs.version }} | |
| name: NetTool ${{ steps.version.outputs.version }} | |
| files: release-files/*.tar.gz | |
| generate_release_notes: true | |
| draft: false | |
| prerelease: ${{ contains(github.ref, '-rc') || contains(github.ref, '-beta') || contains(github.ref, '-alpha') }} | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |