From 2b4468d4073af5d777389cec4bd9192776848ac4 Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Sat, 3 Jan 2026 15:59:34 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20Update=20proto=20build=20system?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 5 +++ .github/workflows/frontend-tests.yml | 51 ++++++++++++++++------------ .github/workflows/proto-build.yml | 3 +- .gitignore | 6 ++-- app/package.json | 2 +- app/scripts/compile_protos.js | 49 ++++++++++++++++++++++++++ app/src/lib/platform_shared/.gitkeep | 0 esp32/src/platform_shared/.gitkeep | 0 8 files changed, 91 insertions(+), 25 deletions(-) create mode 100644 app/scripts/compile_protos.js create mode 100644 app/src/lib/platform_shared/.gitkeep create mode 100644 esp32/src/platform_shared/.gitkeep diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 6e213b7..41e6d57 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -36,6 +36,11 @@ jobs: cache: "pnpm" cache-dependency-path: "./app/pnpm-lock.yaml" + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + version: "27.x" + - run: pnpm install - run: pnpm run build diff --git a/.github/workflows/frontend-tests.yml b/.github/workflows/frontend-tests.yml index b68ec7c..92c3e95 100644 --- a/.github/workflows/frontend-tests.yml +++ b/.github/workflows/frontend-tests.yml @@ -2,14 +2,14 @@ name: Frontend Tests on: push: - branches: [ master ] + branches: [master] paths: - - 'app/**' + - "app/**" pull_request: - branches: [ master ] + branches: [master] paths: - - 'app/**' - + - "app/**" + permissions: contents: read @@ -20,22 +20,31 @@ jobs: run: working-directory: ./app steps: - - uses: actions/checkout@v4 - - uses: pnpm/action-setup@v2 - with: - version: 9 + - uses: actions/checkout@v4 + - uses: pnpm/action-setup@v2 + with: + version: 9 - - name: Setup Node.js - uses: actions/setup-node@v4 - with: - node-version: 'latest' - cache: 'pnpm' - cache-dependency-path: './app/pnpm-lock.yaml' + - name: Setup Node.js + uses: actions/setup-node@v4 + with: + node-version: "latest" + cache: "pnpm" + cache-dependency-path: "./app/pnpm-lock.yaml" - - name: Install dependencies - run: pnpm install - - name: Install Playwright Browsers - run: npx playwright install --with-deps + - name: Install Protoc + uses: arduino/setup-protoc@v3 + with: + version: "27.x" - - name: Run tests - run: pnpm test + - name: Install dependencies + run: pnpm install + + - name: Generate Proto + run: pnpm proto + + - name: Install Playwright Browsers + run: npx playwright install --with-deps + + - name: Run tests + run: pnpm test diff --git a/.github/workflows/proto-build.yml b/.github/workflows/proto-build.yml index 977f672..e0bf988 100644 --- a/.github/workflows/proto-build.yml +++ b/.github/workflows/proto-build.yml @@ -56,4 +56,5 @@ jobs: working-directory: ./app - name: Build Protocol Buffers (Typescript) - run: protoc --plugin="protoc-gen-ts_proto=./app/node_modules/.bin/protoc-gen-ts_proto" --ts_proto_out="./app/src/lib/platform_shared" --ts_proto_opt=outputSchema=true --proto_path "./platform_shared" ./platform_shared/websocket_message.proto ./platform_shared/rest_message.proto \ No newline at end of file + run: pnpm proto + working-directory: ./app \ No newline at end of file diff --git a/.gitignore b/.gitignore index cdc57fd..235b201 100644 --- a/.gitignore +++ b/.gitignore @@ -6,5 +6,7 @@ __pycache__/ *.py[cod] *$py.class .pio -esp32/src/platform_shared -app/src/lib/platform_shared +esp32/src/platform_shared/* +!esp32/src/platform_shared/.gitkeep +app/src/lib/platform_shared/* +!app/src/lib/platform_shared/.gitkeep diff --git a/app/package.json b/app/package.json index 5f057ef..3c156be 100644 --- a/app/package.json +++ b/app/package.json @@ -14,7 +14,7 @@ "format": "prettier --write .", "test:integration": "playwright test", "test:unit": "vitest", - "proto": "protoc --plugin=protoc-gen-ts_proto=.\\node_modules\\.bin\\protoc-gen-ts_proto.cmd --ts_proto_out=./src/lib/platform_shared --ts_proto_opt=outputTypeAnnotations=true,useExactTypes=false,outputExtensions=true,outputTypeRegistry=true,outputSchema=true -I ../platform_shared ../platform_shared/websocket_message.proto ../platform_shared/rest_message.proto" + "proto": "node scripts/compile_protos.js" }, "devDependencies": { "@eslint/js": "^9.39.2", diff --git a/app/scripts/compile_protos.js b/app/scripts/compile_protos.js new file mode 100644 index 0000000..dcadd46 --- /dev/null +++ b/app/scripts/compile_protos.js @@ -0,0 +1,49 @@ +#!/usr/bin/env node +import { execSync } from 'child_process'; +import path from 'path'; +import os from 'os'; +import { fileURLToPath } from 'url'; + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +const isWindows = os.platform() === 'win32'; +const projectRoot = path.resolve(__dirname, '..'); +const platformSharedDir = path.resolve(projectRoot, '..', 'platform_shared'); +const outputDir = path.resolve(projectRoot, 'src', 'lib', 'platform_shared'); + +const pluginPath = isWindows + ? path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto.cmd') + : path.join(projectRoot, 'node_modules', '.bin', 'protoc-gen-ts_proto'); + +const protoFiles = ['websocket_message.proto', 'rest_message.proto']; + +const tsProtoOpts = [ + 'outputTypeAnnotations=true', + 'useExactTypes=false', + 'outputExtensions=true', + 'outputTypeRegistry=true', + 'outputSchema=true' +].join(','); + +const cmd = [ + 'protoc', + `--plugin=protoc-gen-ts_proto=${pluginPath}`, + `--ts_proto_out=${outputDir}`, + `--ts_proto_opt=${tsProtoOpts}`, + `-I${platformSharedDir}`, + ...protoFiles.map(f => path.join(platformSharedDir, f)) +].join(' '); + +console.log('Compiling protos...'); +console.log(` Platform: ${os.platform()}`); +console.log(` Output: ${outputDir}`); + +try { + execSync(cmd, { stdio: 'inherit', cwd: projectRoot }); + console.log('Proto compilation complete!'); +} catch (error) { + console.error('Proto compilation failed!'); + process.exit(1); +} + diff --git a/app/src/lib/platform_shared/.gitkeep b/app/src/lib/platform_shared/.gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/esp32/src/platform_shared/.gitkeep b/esp32/src/platform_shared/.gitkeep new file mode 100644 index 0000000..e69de29