diff --git a/.github/workflows/build-updater.yaml b/.github/workflows/build-updater.yaml new file mode 100644 index 000000000..ce9af5e6b --- /dev/null +++ b/.github/workflows/build-updater.yaml @@ -0,0 +1,131 @@ +name: Build updater + +on: + workflow_dispatch: + pull_request: + paths: + - updater/** + +jobs: + build-updater-linux: + name: Build updater for Linux + runs-on: ubuntu-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Mark workspace as safe + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + cache-dependency-path: updater/go.sum + + - name: Ensure dependencies + working-directory: updater + run: go mod tidy + + - name: Make output dir + run: mkdir -p updater/output + + - name: Build (linux/amd64) + run: | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 \ + go build -o updater/output/updater-linux-64 ./updater + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: updater-linux + path: updater/output/* + + build-updater-windows: + name: Build updater for Windows + runs-on: windows-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Mark workspace as safe + shell: pwsh + run: git config --global --add safe.directory $Env:GITHUB_WORKSPACE + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + cache-dependency-path: updater\go.sum + + - name: Ensure dependencies + working-directory: updater + shell: pwsh + run: go mod tidy + + - name: Make output dir + shell: pwsh + run: New-Item -ItemType Directory -Path updater\output -Force + + - name: Build (windows/amd64) + shell: pwsh + run: | + $Env:CGO_ENABLED='0' + go build -o updater\output\updater-windows-64.exe ./updater + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: updater-windows + path: updater\output\* + + build-updater-mac: + name: Build updater for macOS + runs-on: macos-latest + + steps: + - name: Checkout code + uses: actions/checkout@v4 + with: + fetch-depth: 0 + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Mark workspace as safe + run: git config --global --add safe.directory $GITHUB_WORKSPACE + + - name: Set up Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + cache-dependency-path: updater/go.sum + + - name: Ensure dependencies + working-directory: updater + run: go mod tidy + + - name: Make output dir + run: mkdir -p updater/output + + - name: Build (macOS Intel) + run: | + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 \ + go build -o updater/output/updater-macos-64 ./updater + + - name: Build (macOS ARM64) + run: | + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 \ + go build -o updater/output/updater-macos-m1-64 ./updater + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: updater-macos + path: updater/output/* diff --git a/.github/workflows/build-updater.yml b/.github/workflows/build-updater.yml deleted file mode 100644 index 220b2eeaa..000000000 --- a/.github/workflows/build-updater.yml +++ /dev/null @@ -1,128 +0,0 @@ -name: Build updater - -on: - workflow_dispatch: - -jobs: - build-backend-linux: - name: "Build updater for linux" - runs-on: ubuntu-latest - - # Runs on alpine because it is easier to statically link the library - container: - image: golang:alpine - - env: - UPDATER_DIR: ./updater - - steps: - - name: "Install packages" - run: apk update && apk add --no-cache gcc go - - - uses: actions/checkout@v4 - with: - sparse-checkout: updater - - - name: "Create output path" - working-directory: "${{env.UPDATER_DIR}}" - run: mkdir ./output - - - name: "Build (64 bit)" - working-directory: "${{env.UPDATER_DIR}}" - env: - CGO_ENABLED: 1 - GOARCH: amd64 - GOOS: linux - run: | - go build -ldflags '-linkmode external -extldflags "-static"' -o ../output/updaters/updater-linux-64 - - - name: "Upload build" - uses: actions/upload-artifact@v4 - with: - name: updater-linux - path: "${{env.UPDATER_DIR}}/output/updaters/*" - retention-days: 3 - compression-level: 9 - - build-backend-windows: - name: "Build updater for windows" - runs-on: windows-latest - - env: - UPDATER_DIR: ".\\updater" - - steps: - - uses: actions/checkout@v3 - - - name: "Setup Go" - uses: actions/setup-go@v4 - with: - go-version: "1.21.3" - cache-dependency-path: "${{env.UPDATER_DIR}}\\go.sum" - - - name: "Create output path" - working-directory: "${{env.UPDATER_DIR}}" - run: mkdir .\output - - - name: "Build (64 bit)" - working-directory: "${{env.UPDATER_DIR}}" - env: - CGO_ENABLED: 1 - GOARCH: amd64 - GOOS: windows - run: | - go build -o ..\output\updaters\backend-windows-64.exe - - - name: "Upload build" - uses: actions/upload-artifact@v4 - with: - name: updater-windows - path: "${{env.UPDATER_DIR}}\\output\\updaters\\*" - retention-days: 3 - compression-level: 9 - - build-backend-mac: - name: "Build updater for macOS" - runs-on: macos-latest - - env: - BACKEND_DIR: ./updater - - steps: - - name: "Setup Go" - uses: actions/setup-go@v4 - with: - go-version: "1.21.3" - cache-dependency-path: "${{env.UPDATER_DIR}}/go.sum" - - - uses: actions/checkout@v3 - - - name: "Create output path" - working-directory: "${{env.UPDATER_DIR}}" - run: mkdir ./output - - - name: "Build (64 bit)" - working-directory: "${{env.UPDATER_DIR}}" - env: - CGO_ENABLED: 1 - GOARCH: amd64 - GOOS: darwin - run: | - go build -o ../output/updaters/updater-macos-64 - - - name: "Build (apple 64 bit)" - working-directory: "${{env.UPDATER_DIR}}" - env: - CGO_ENABLED: 1 - GOARCH: arm64 - GOOS: darwin - run: | - go build -o ../output/updaters/updater-macos-m1-64 - - - name: "Upload build" - uses: actions/upload-artifact@v4 - with: - name: updater-macos - path: "${{env.UPDATER_DIR}}/output/updaters/*" - retention-days: 3 - compression-level: 9 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 000000000..93047989c --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,501 @@ +name: Release + +on: + workflow_dispatch: + inputs: + version: + description: 'Release version' + required: true + default: '' + draft: + description: 'Create as draft release' + type: boolean + default: true + release: + types: [created] + +jobs: + build-backend: + name: Build Backend + runs-on: ${{ matrix.os }} + container: ${{ matrix.container }} + strategy: + matrix: + include: + - os: ubuntu-latest + name: linux + container: + image: golang:alpine + setup: | + apk update && apk add --no-cache libpcap-dev musl-dev gcc go bash + build_cmd: | + cd backend/cmd + CGO_ENABLED=1 GOARCH=amd64 GOOS=linux go build -ldflags '-linkmode external -extldflags "-static"' -o ../output/backend-linux-amd64 + artifact_name: backend-linux + + - os: windows-latest + name: windows + setup: | + echo "Setting up Windows environment" + build_cmd: | + cd backend\cmd + $env:CGO_ENABLED="1" + $env:GOARCH="amd64" + $env:GOOS="windows" + go build -o ..\output\backend-windows-amd64.exe + artifact_name: backend-windows + + - os: macos-latest + name: macos + setup: | + brew install libpcap + build_cmd: | + cd backend/cmd + CGO_ENABLED=1 GOARCH=amd64 GOOS=darwin go build -o ../output/backend-macos-amd64 + CGO_ENABLED=1 GOARCH=arm64 GOOS=darwin go build -o ../output/backend-macos-arm64 + artifact_name: backend-macos + + steps: + - uses: actions/checkout@v4 + + - name: Setup environment + run: ${{ matrix.setup }} + + - name: Setup Go + if: matrix.os != 'ubuntu-latest' + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + cache-dependency-path: backend/go.sum + + - name: Create output directory (Linux) + if: matrix.os == 'ubuntu-latest' + run: mkdir -p backend/output + shell: sh + + - name: Create output directory (macOS) + if: matrix.os == 'macos-latest' + run: mkdir -p backend/output + shell: bash + + - name: Create output directory (Windows) + if: matrix.os == 'windows-latest' + run: mkdir -p backend/output + shell: bash + + - name: Build backend (Linux) + if: matrix.os == 'ubuntu-latest' + run: ${{ matrix.build_cmd }} + shell: sh + + - name: Build backend (macOS) + if: matrix.os == 'macos-latest' + run: ${{ matrix.build_cmd }} + shell: bash + + - name: Build backend (Windows) + if: matrix.os == 'windows-latest' + run: ${{ matrix.build_cmd }} + shell: pwsh + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: backend/output/* + retention-days: 7 + compression-level: 9 + + build-frontend: + name: Build Frontends + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: '18' + cache: 'npm' + + - name: Build common front dependencies + working-directory: ./common-front + run: | + npm install + npm run build + + - name: Build ethernet view + working-directory: ./ethernet-view + run: | + npm install + npm run build + + - name: Upload ethernet view artifact + uses: actions/upload-artifact@v4 + with: + name: ethernet-view + path: ethernet-view/static/* + retention-days: 7 + compression-level: 9 + + - name: Build control station + working-directory: ./control-station + run: | + npm install + npm run build + + - name: Upload control station artifact + uses: actions/upload-artifact@v4 + with: + name: control-station + path: control-station/static/* + retention-days: 7 + compression-level: 9 + + build-updater: + name: Build Updater + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + name: linux + build_cmd: | + CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -o updater/output/updater-linux-amd64 ./updater + artifact_name: updater-linux + + - os: windows-latest + name: windows + build_cmd: | + $Env:CGO_ENABLED='0' + $Env:GOOS='windows' + $Env:GOARCH='amd64' + go build -o updater\output\updater-windows-amd64.exe ./updater + artifact_name: updater-windows + + - os: macos-latest + name: macos + build_cmd: | + CGO_ENABLED=0 GOOS=darwin GOARCH=amd64 go build -o updater/output/updater-macos-amd64 ./updater + CGO_ENABLED=0 GOOS=darwin GOARCH=arm64 go build -o updater/output/updater-macos-arm64 ./updater + artifact_name: updater-macos + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Mark workspace as safe + run: git config --global --add safe.directory $GITHUB_WORKSPACE + shell: bash + + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: "1.21.3" + cache-dependency-path: updater/go.sum + + - name: Ensure dependencies (Linux) + if: matrix.os == 'ubuntu-latest' + working-directory: updater + run: go mod tidy + shell: bash + + - name: Ensure dependencies (macOS) + if: matrix.os == 'macos-latest' + working-directory: updater + run: go mod tidy + shell: bash + + - name: Ensure dependencies (Windows) + if: matrix.os == 'windows-latest' + working-directory: updater + run: go mod tidy + shell: pwsh + + - name: Create output directory (Linux) + if: matrix.os == 'ubuntu-latest' + run: mkdir -p updater/output + shell: bash + + - name: Create output directory (macOS) + if: matrix.os == 'macos-latest' + run: mkdir -p updater/output + shell: bash + + - name: Create output directory (Windows) + if: matrix.os == 'windows-latest' + run: mkdir -p updater/output + shell: bash + + - name: Build updater (Linux) + if: matrix.os == 'ubuntu-latest' + run: ${{ matrix.build_cmd }} + shell: bash + + - name: Build updater (macOS) + if: matrix.os == 'macos-latest' + run: ${{ matrix.build_cmd }} + shell: bash + + - name: Build updater (Windows) + if: matrix.os == 'windows-latest' + run: ${{ matrix.build_cmd }} + shell: pwsh + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: updater/output/* + retention-days: 7 + compression-level: 9 + + prepare-common-files: + name: Prepare Common Files + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Create common files directory + run: mkdir -p common-files + + - name: Copy config.toml + run: cp backend/cmd/config.toml common-files/ + + - name: Copy testadj.py + run: cp backend/cmd/testadj.py common-files/ + + - name: Copy README.md + run: cp README.md common-files/ + + - name: Copy VERSION.md + run: cp backend/cmd/VERSION.md common-files/ + + - name: Upload common files artifact + uses: actions/upload-artifact@v4 + with: + name: common-files + path: common-files/* + retention-days: 7 + compression-level: 9 + + package-release: + name: Package Release + needs: [build-backend, build-frontend, build-updater, prepare-common-files] + runs-on: ubuntu-latest + steps: + - name: Download all artifacts + uses: actions/download-artifact@v4 + with: + path: artifacts + + - name: Create release directories for each platform + run: | + VERSION="${{ github.event.inputs.version || github.event.release.tag_name || 'latest' }}" + + # Create directory structure for each platform + mkdir -p release-linux + mkdir -p release-windows + mkdir -p release-macos + mkdir -p release-macos-arm64 + + - name: Organize Linux release files + run: | + VERSION="${{ github.event.inputs.version || github.event.release.tag_name || 'latest' }}" + + # Copy Linux backend + cp artifacts/backend-linux/backend-linux-amd64 release-linux/backend + + # Copy Linux updater + cp artifacts/updater-linux/updater-linux-amd64 release-linux/updater + + # Copy frontends + mkdir -p release-linux/ethernet-view + mkdir -p release-linux/control-station + cp -r artifacts/ethernet-view/* release-linux/ethernet-view/ + cp -r artifacts/control-station/* release-linux/control-station/ + + # Copy common files + cp -r artifacts/common-files/* release-linux/ + + # Create Linux release archive + cd release-linux + zip -r ../linux-$VERSION.zip . + + - name: Organize Windows release files + run: | + VERSION="${{ github.event.inputs.version || github.event.release.tag_name || 'latest' }}" + + # Copy Windows backend + cp artifacts/backend-windows/backend-windows-amd64.exe release-windows/backend.exe + + # Copy Windows updater + cp artifacts/updater-windows/updater-windows-amd64.exe release-windows/updater.exe + + # Copy frontends + mkdir -p release-windows/ethernet-view + mkdir -p release-windows/control-station + cp -r artifacts/ethernet-view/* release-windows/ethernet-view/ + cp -r artifacts/control-station/* release-windows/control-station/ + + # Copy common files + cp -r artifacts/common-files/* release-windows/ + + # Create Windows release archive + cd release-windows + zip -r ../windows-$VERSION.zip . + + - name: Organize macOS Intel release files + run: | + VERSION="${{ github.event.inputs.version || github.event.release.tag_name || 'latest' }}" + + # Copy macOS Intel backend + cp artifacts/backend-macos/backend-macos-amd64 release-macos/backend + + # Copy macOS Intel updater + cp artifacts/updater-macos/updater-macos-amd64 release-macos/updater + + # Copy frontends + mkdir -p release-macos/ethernet-view + mkdir -p release-macos/control-station + cp -r artifacts/ethernet-view/* release-macos/ethernet-view/ + cp -r artifacts/control-station/* release-macos/control-station/ + + # Copy common files + cp -r artifacts/common-files/* release-macos/ + + # Create macOS Intel release archive + cd release-macos + zip -r ../macos-intel-$VERSION.zip . + + - name: Organize macOS ARM64 release files + run: | + VERSION="${{ github.event.inputs.version || github.event.release.tag_name || 'latest' }}" + + # Copy macOS ARM64 backend + cp artifacts/backend-macos/backend-macos-arm64 release-macos-arm64/backend + + # Copy macOS ARM64 updater + cp artifacts/updater-macos/updater-macos-arm64 release-macos-arm64/updater + + # Copy frontends + mkdir -p release-macos-arm64/ethernet-view + mkdir -p release-macos-arm64/control-station + cp -r artifacts/ethernet-view/* release-macos-arm64/ethernet-view/ + cp -r artifacts/control-station/* release-macos-arm64/control-station/ + + # Copy common files + cp -r artifacts/common-files/* release-macos-arm64/ + + # Create macOS ARM64 release archive + cd release-macos-arm64 + zip -r ../macos-arm64-$VERSION.zip . + + - name: Upload release packages + uses: actions/upload-artifact@v4 + with: + name: releases + path: "*.zip" + retention-days: 7 + compression-level: 9 + + - name: Create Release + if: github.event_name == 'workflow_dispatch' + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: v${{ github.event.inputs.version }} + release_name: Release ${{ github.event.inputs.version }} + draft: ${{ github.event.inputs.draft }} + prerelease: false + + - name: Upload Linux package to release + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./linux-${{ github.event.inputs.version }}.zip + asset_name: linux-${{ github.event.inputs.version }}.zip + asset_content_type: application/zip + + - name: Upload Windows package to release + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./windows-${{ github.event.inputs.version }}.zip + asset_name: windows-${{ github.event.inputs.version }}.zip + asset_content_type: application/zip + + - name: Upload macOS Intel package to release + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./macos-intel-${{ github.event.inputs.version }}.zip + asset_name: macos-intel-${{ github.event.inputs.version }}.zip + asset_content_type: application/zip + + - name: Upload macOS ARM64 package to release + if: github.event_name == 'workflow_dispatch' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./macos-arm64-${{ github.event.inputs.version }}.zip + asset_name: macos-arm64-${{ github.event.inputs.version }}.zip + asset_content_type: application/zip + + - name: Upload Linux package to existing release + if: github.event_name == 'release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./linux-${{ github.event.release.tag_name }}.zip + asset_name: linux-${{ github.event.release.tag_name }}.zip + asset_content_type: application/zip + + - name: Upload Windows package to existing release + if: github.event_name == 'release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./windows-${{ github.event.release.tag_name }}.zip + asset_name: windows-${{ github.event.release.tag_name }}.zip + asset_content_type: application/zip + + - name: Upload macOS Intel package to existing release + if: github.event_name == 'release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./macos-intel-${{ github.event.release.tag_name }}.zip + asset_name: macos-intel-${{ github.event.release.tag_name }}.zip + asset_content_type: application/zip + + - name: Upload macOS ARM64 package to existing release + if: github.event_name == 'release' + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./macos-arm64-${{ github.event.release.tag_name }}.zip + asset_name: macos-arm64-${{ github.event.release.tag_name }}.zip + asset_content_type: application/zip \ No newline at end of file diff --git a/.gitignore b/.gitignore index d6cca4505..769d96cab 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,6 @@ build profiles backend/cmd/cmd -backend/cmd/adj/ .ropeproject # MacOS Files diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 000000000..e42b8aae0 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,6 @@ +[submodule "backend/cmd/adj"] + path = backend/cmd/adj + url = https://github.com/HyperloopUPV-H8/adj.git +[submodule "packet-sender/adj"] + path = packet-sender/adj + url = https://github.com/HyperloopUPV-H8/adj.git diff --git a/backend/cmd/adj b/backend/cmd/adj index fd87ad3fa..4c320a720 160000 --- a/backend/cmd/adj +++ b/backend/cmd/adj @@ -1 +1 @@ -Subproject commit fd87ad3fac5aa62e7b274b5ae00412caa544c0a0 +Subproject commit 4c320a720a191ac4cb94e8952a6d75549dfa6101 diff --git a/backend/cmd/main.go b/backend/cmd/main.go index 01ba862a8..860259acc 100644 --- a/backend/cmd/main.go +++ b/backend/cmd/main.go @@ -34,6 +34,7 @@ import ( "github.com/HyperloopUPV-H8/h9-backend/pkg/abstraction" "github.com/HyperloopUPV-H8/h9-backend/pkg/broker" connection_topic "github.com/HyperloopUPV-H8/h9-backend/pkg/broker/topics/connection" + blcu_topics "github.com/HyperloopUPV-H8/h9-backend/pkg/broker/topics/blcu" data_topic "github.com/HyperloopUPV-H8/h9-backend/pkg/broker/topics/data" logger_topic "github.com/HyperloopUPV-H8/h9-backend/pkg/broker/topics/logger" message_topic "github.com/HyperloopUPV-H8/h9-backend/pkg/broker/topics/message" @@ -184,10 +185,32 @@ func main() { } else { fmt.Println("Backend folder not detected. Launching existing updater...") + osType := detectOS() + + execPath, err := os.Executable() + if err != nil { + fmt.Fprintf(os.Stderr, "Error getting executable path: %v\n", err) + os.Exit(1) + } + updatersDir := filepath.Join(filepath.Dir(execPath), "updaters") + + var updaterExe string + switch osType { + case "updaters/updater-windows-64.exe": + updaterExe = filepath.Join(updatersDir, "updater-windows-64") + case "updaters/updater-linux": + updaterExe = filepath.Join(updatersDir, "updater-linux") + case "updaters/updater-macos-m1": + updaterExe = filepath.Join(updatersDir, "updater-macos-m1") + case "updaters/updater-macos-64": + updaterExe = filepath.Join(updatersDir, "updater-macos-64") + default: + fmt.Fprintf(os.Stderr, "Unsupported updater: %s\n", osType) + os.Exit(1) + } - updaterExe := filepath.Join(execDir, "updater.exe") cmd := exec.Command(updaterExe) - cmd.Dir = filepath.Dir(updaterExe) + cmd.Dir = updatersDir cmd.Stdout = os.Stdout cmd.Stderr = os.Stderr if err := cmd.Run(); err != nil { @@ -295,6 +318,7 @@ func main() { upgrader := websocket.NewUpgrader(connections, trace.Logger) pool := websocket.NewPool(connections, trace.Logger) broker.SetPool(pool) + blcu_topics.RegisterTopics(broker, pool) // <--- transport ---> transp := transport.NewTransport(trace.Logger) @@ -715,3 +739,20 @@ func getLatestVersionFromGitHub() (string, error) { version := strings.TrimPrefix(release.TagName, "v") return version, nil } +func detectOS() string { + switch runtime.GOOS { + case "windows": + return "updaters/updater-windows-64.exe" + case "darwin": + if strings.Contains(runtime.GOARCH, "arm") { + return "updaters/updater-macos-m1" + } + return "updaters/updater-macos-64" + case "linux": + return "updaters/updater-linux" + default: + fmt.Fprintf(os.Stderr, "Unsupported operating system: %s\n", runtime.GOOS) + os.Exit(1) + return "" + } +} diff --git a/backend/pkg/broker/topics/blcu/register.go b/backend/pkg/broker/topics/blcu/register.go new file mode 100644 index 000000000..ee735b716 --- /dev/null +++ b/backend/pkg/broker/topics/blcu/register.go @@ -0,0 +1,22 @@ +package blcu + +import ( + "github.com/HyperloopUPV-H8/h9-backend/pkg/boards" + "github.com/HyperloopUPV-H8/h9-backend/pkg/broker" + "github.com/HyperloopUPV-H8/h9-backend/pkg/websocket" +) + +func RegisterTopics(b *broker.Broker, pool *websocket.Pool) { + upload := &Upload{} + upload.SetAPI(b) + upload.SetPool(pool) + download := &Download{} + download.SetAPI(b) + download.SetPool(pool) + b.AddTopic(UploadName, upload) + b.AddTopic(DownloadName, download) + b.AddTopic(boards.UploadSuccess{}.Topic(), upload) + b.AddTopic(boards.UploadFailure{}.Topic(), upload) + b.AddTopic(boards.DownloadSuccess{}.Topic(), download) + b.AddTopic(boards.DownloadFailure{}.Topic(), download) +} diff --git a/backend/pkg/transport/network/tcp/client.go b/backend/pkg/transport/network/tcp/client.go index 39e683c35..82817a668 100644 --- a/backend/pkg/transport/network/tcp/client.go +++ b/backend/pkg/transport/network/tcp/client.go @@ -35,15 +35,22 @@ func NewClient(address string, config ClientConfig, baseLogger zerolog.Logger) C // Dial attempts to connect with the client func (client *Client) Dial() (net.Conn, error) { - client.currentRetries = 0 var err error var conn net.Conn client.logger.Info().Msg("dialing") - for ; client.config.MaxConnectionRetries <= 0 || client.currentRetries < client.config.MaxConnectionRetries; client.currentRetries++ { + // The max connection retries will not work because the for loop never completes, it always returns and the function is called again by transport. + for client.config.MaxConnectionRetries <= 0 || client.currentRetries < client.config.MaxConnectionRetries { + client.currentRetries++ conn, err = client.config.DialContext(client.config.Context, "tcp", client.address) + + backoffDuration := client.config.ConnectionBackoffFunction(client.currentRetries) + client.logger.Error().Stack().Err(err).Dur("backoff", backoffDuration).Int("retries", client.currentRetries+1).Msg("retrying") + time.Sleep(backoffDuration) + if err == nil { client.logger.Info().Msg("connected") + client.currentRetries = 0 return conn, nil } if client.config.Context.Err() != nil { @@ -55,10 +62,6 @@ func (client *Client) Dial() (net.Conn, error) { client.logger.Error().Stack().Err(err).Msg("failed") return nil, err } - - backoffDuration := client.config.ConnectionBackoffFunction(client.currentRetries) - client.logger.Debug().Stack().Err(err).Dur("backoff", backoffDuration).Int("retries", client.currentRetries+1).Msg("retrying") - time.Sleep(backoffDuration) } client.logger.Debug().Int("max", client.config.MaxConnectionRetries).Msg("max connection retries exceeded") diff --git a/ethernet-view/src/components/BootloaderContainer/Bootloader/SendElement/SendElement.module.scss b/ethernet-view/src/components/BootloaderContainer/Bootloader/SendElement/SendElement.module.scss index a6ba3ba3a..0f1b5f0a7 100644 --- a/ethernet-view/src/components/BootloaderContainer/Bootloader/SendElement/SendElement.module.scss +++ b/ethernet-view/src/components/BootloaderContainer/Bootloader/SendElement/SendElement.module.scss @@ -12,7 +12,7 @@ } .fileIcon { - font-size: 1.8rem; + font-size: 0.9rem; color: orange; } @@ -22,17 +22,17 @@ flex-direction: column; gap: 0.5rem; text-overflow: ellipsis; + font-size: 1rem; } .name { flex: 1 1 0; - font-weight: bold; text-overflow: ellipsis; } .removeBtn { - color: #bebebe; - font-size: 0.8rem; cursor: pointer; + width: 25px; + height: 25px; } diff --git a/ethernet-view/src/components/Navbar/NavbarItem/NavbarItem.tsx b/ethernet-view/src/components/Navbar/NavbarItem/NavbarItem.tsx index 627b97359..77315fdab 100644 --- a/ethernet-view/src/components/Navbar/NavbarItem/NavbarItem.tsx +++ b/ethernet-view/src/components/Navbar/NavbarItem/NavbarItem.tsx @@ -3,6 +3,7 @@ import styles from "components/Navbar/NavbarItem/NavbarItem.module.scss"; export type NavbarItemData = { icon: string; page: string; + }; type Props = { diff --git a/ethernet-view/src/layouts/AppLayout/AppLayout.tsx b/ethernet-view/src/layouts/AppLayout/AppLayout.tsx index 49b27d37a..33e4dc894 100644 --- a/ethernet-view/src/layouts/AppLayout/AppLayout.tsx +++ b/ethernet-view/src/layouts/AppLayout/AppLayout.tsx @@ -2,6 +2,8 @@ import styles from "./AppLayout.module.scss" import Testing from "assets/svg/testing.svg" import Logger from "assets/svg/logger.svg" +import Chart from "assets/svg/chart.svg" + import { Navbar } from "components/Navbar/Navbar" import { ReactNode } from "react" @@ -12,7 +14,6 @@ interface Props { } export const AppLayout = ({children, pageShown, setPageShown} : Props) => { - return (
{ { icon: Logger, page: "logger" + }, + { + icon: Chart, + page: "chart" } ]} pageShown={pageShown} diff --git a/packet-sender/adj b/packet-sender/adj index e51cccf45..4c320a720 160000 --- a/packet-sender/adj +++ b/packet-sender/adj @@ -1 +1 @@ -Subproject commit e51cccf4527fc0fa623c3f0487a6d5741502067c +Subproject commit 4c320a720a191ac4cb94e8952a6d75549dfa6101 diff --git a/updater/main.go b/updater/main.go index 7469e4b99..ba08f9e4a 100644 --- a/updater/main.go +++ b/updater/main.go @@ -194,43 +194,46 @@ func downloadFile(filepath string, url string) error { } func extractBinaryFromZip(zipPath, binaryName string) (string, error) { - // Open the ZIP file r, err := zip.OpenReader(zipPath) if err != nil { return "", err } defer r.Close() - // Iterate through the files in the ZIP + var binaryPath string + parentDir, _ := filepath.Abs(filepath.Join(".", "..")) + for _, f := range r.File { - if f.Name == binaryName { - // Open the file inside the ZIP + baseName := filepath.Base(f.Name) + if baseName == binaryName || baseName == "VERSION.md" { rc, err := f.Open() if err != nil { return "", err } defer rc.Close() - // Create the output file - outPath := "./" + binaryName + outPath := filepath.Join(parentDir, baseName) outFile, err := os.Create(outPath) if err != nil { return "", err } defer outFile.Close() - // Copy the contents of the file _, err = io.Copy(outFile, rc) if err != nil { return "", err } - // Return the path to the extracted binary - return outPath, nil + if baseName == binaryName { + binaryPath = outPath + } } } - return "", fmt.Errorf("binary %s not found in ZIP", binaryName) + if binaryPath == "" { + return "", fmt.Errorf("binary %s not found in ZIP", binaryName) + } + return binaryPath, nil } func getLatestVersion() (string, error) {