diff --git a/.github/actions/prepare-workflow/action.yml b/.github/actions/prepare-workflow/action.yml new file mode 100644 index 000000000..79a842872 --- /dev/null +++ b/.github/actions/prepare-workflow/action.yml @@ -0,0 +1,115 @@ +name: 'Prepare Workflow' +description: 'Setup environment, cache and install dependencies, and optionally download build artifacts' + +inputs: + e2e: + description: 'Whether to prepare for e2e tests' + required: false + default: 'false' + +runs: + using: 'composite' + steps: + - name: Setup environment + shell: bash + run: | + sudo chown -R testbot . + sudo mkdir -p /home/testbot/.cache/buf + sudo chown -R testbot:testbot /home/testbot/.cache + sudo mkdir -p /github/home/.npm + sudo chown -R testbot:testbot /github/home/.npm + sudo mkdir -p /github/home/.cache + sudo chown -R testbot:testbot /github/home/.cache + + - name: Setup Node.js + uses: actions/setup-node@v6 + with: + node-version: '22' + cache: 'npm' + + - name: Restore node_modules cache + uses: actions/cache/restore@v4 + id: cache-node-modules + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + restore-keys: | + node-modules-${{ runner.os }}- + + - name: Install npm dependencies + if: steps.cache-node-modules.outputs.cache-hit != 'true' + shell: bash + run: sudo -E -u testbot bash -lc 'npm ci --audit=false' + + - name: Save node_modules cache + if: steps.cache-node-modules.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: node_modules + key: node-modules-${{ runner.os }}-${{ hashFiles('package-lock.json') }} + + - name: Prebuild + shell: bash + run: sudo -E -u testbot bash -lc 'npm run prebuild' + + - name: Download build artifacts + if: inputs.e2e == 'true' + uses: actions/download-artifact@v4 + with: + name: build-artifacts + path: . + + - name: Restore build-buf cache + if: inputs.e2e != 'true' + uses: actions/cache/restore@v4 + id: cache-build-buf + with: + path: src/gen + key: build-buf-${{ runner.os }}-${{ hashFiles('api_version.lock', 'buf.gen.yaml') }} + restore-keys: | + build-buf-${{ runner.os }}-${{ hashFiles('api_version.lock') }}- + build-buf-${{ runner.os }}- + + - name: Generate build-buf if not cached + if: inputs.e2e != 'true' && steps.cache-build-buf.outputs.cache-hit != 'true' + shell: bash + run: sudo -E -u testbot bash -lc 'make build-buf-ci' + + - name: Save build-buf cache + if: inputs.e2e != 'true' && steps.cache-build-buf.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: src/gen + key: build-buf-${{ runner.os }}-${{ hashFiles('api_version.lock', 'buf.gen.yaml') }} + + - name: Read Playwright version from package.json + if: inputs.e2e == 'true' + id: playwright-version + shell: bash + run: | + PLAYWRIGHT_VERSION=$(jq -r '.devDependencies."@playwright/test"' package.json) + echo "version=$PLAYWRIGHT_VERSION" >> $GITHUB_OUTPUT + echo "Using Playwright version: $PLAYWRIGHT_VERSION" + + - name: Restore Playwright browsers cache + if: inputs.e2e == 'true' + uses: actions/cache/restore@v4 + id: cache-playwright + with: + path: /home/testbot/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} + restore-keys: | + playwright-${{ runner.os }}- + + - name: Install Playwright browsers and dependencies + if: inputs.e2e == 'true' + shell: bash + run: | + sudo -E -u testbot bash -lc 'npx playwright install --with-deps' + + - name: Save Playwright browsers cache + if: inputs.e2e == 'true' && steps.cache-playwright.outputs.cache-hit != 'true' + uses: actions/cache/save@v4 + with: + path: /home/testbot/.cache/ms-playwright + key: playwright-${{ runner.os }}-${{ steps.playwright-version.outputs.version }} diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 6aa9293c2..5ffad9c65 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -6,11 +6,80 @@ on: - main jobs: + build: + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Build + run: sudo -u testbot bash -lc 'make build-ci' + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + dist + src/gen + retention-days: 1 + + lint: + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Lint + run: sudo -u testbot bash -lc 'make lint-ci' + test: - uses: viamrobotics/viam-typescript-sdk/.github/workflows/test.yml@main + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Test + run: sudo -u testbot bash -lc 'make test-ci' + + test-e2e: + if: github.repository_owner == 'viamrobotics' + needs: build + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + with: + e2e: 'true' + + - name: Test E2E + run: sudo -u testbot bash -lc 'make test-e2e-ci' publish_next: - needs: test + needs: [build, lint, test, test-e2e] uses: viamrobotics/viam-typescript-sdk/.github/workflows/publish_next.yml@main secrets: NPM_TOKEN: ${{ secrets.NPM_TOKEN }} diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml index a6668d9d5..3c162a058 100644 --- a/.github/workflows/publish.yml +++ b/.github/workflows/publish.yml @@ -38,7 +38,7 @@ jobs: echo "tag=latest" >> $GITHUB_OUTPUT fi - - uses: actions/setup-node@v4 + - uses: actions/setup-node@v6 with: node-version: '24' registry-url: 'https://registry.npmjs.org' diff --git a/.github/workflows/pullrequest.yml b/.github/workflows/pullrequest.yml index 9c1817de3..d3fb53c27 100644 --- a/.github/workflows/pullrequest.yml +++ b/.github/workflows/pullrequest.yml @@ -3,8 +3,77 @@ name: Pull Request Update on: [workflow_dispatch, pull_request] jobs: + build: + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Build + run: sudo -u testbot bash -lc 'make build-ci' + + - name: Upload build artifacts + uses: actions/upload-artifact@v4 + with: + name: build-artifacts + path: | + dist + src/gen + retention-days: 1 + + lint: + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Lint + run: sudo -u testbot bash -lc 'make lint-ci' + test: - uses: viamrobotics/viam-typescript-sdk/.github/workflows/test.yml@main + if: github.repository_owner == 'viamrobotics' + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + + - name: Test + run: sudo -u testbot bash -lc 'make test-ci' + + test-e2e: + if: github.repository_owner == 'viamrobotics' + needs: build + runs-on: ubuntu-latest + container: + image: ghcr.io/viamrobotics/rdk-devenv:amd64 + + steps: + - uses: actions/checkout@v4 + + - name: Prepare workflow + uses: viamrobotics/viam-typescript-sdk/.github/actions/prepare-workflow@main + with: + e2e: 'true' + + - name: Test E2E + run: sudo -u testbot bash -lc 'make test-e2e-ci' license_check: uses: viamrobotics/viam-typescript-sdk/.github/workflows/license_finder.yml@main diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml deleted file mode 100644 index b95c10622..000000000 --- a/.github/workflows/test.yml +++ /dev/null @@ -1,23 +0,0 @@ -name: Test - -on: - workflow_call: - workflow_dispatch: - -jobs: - build_lint_test: - if: github.repository_owner == 'viamrobotics' - runs-on: ubuntu-latest - container: - image: ghcr.io/viamrobotics/rdk-devenv:amd64 - - steps: - - uses: actions/checkout@v4 - - - name: Build, lint, and test - run: | - sudo apt-get update && sudo apt-get upgrade -y - sudo apt-get install -y software-properties-common - apt-add-repository -y 'deb https://archive.debian.org/debian bullseye-backports main' - sudo chown -R testbot . - sudo -u testbot bash -lc 'make build lint test test-e2e' diff --git a/.prettierignore b/.prettierignore index 631885b76..1a73c651d 100644 --- a/.prettierignore +++ b/.prettierignore @@ -1,3 +1,4 @@ dist docs src/gen +src/api-version.ts diff --git a/Makefile b/Makefile index d084369cf..c523c7c00 100644 --- a/Makefile +++ b/Makefile @@ -16,6 +16,12 @@ teardown: .PHONY: build build: build-buf build-js build-docs +.PHONY: build-ci +build-ci: + npm run build + npm run doc + + .PHONY: clean clean: clean-js clean-buf clean-docs @@ -23,16 +29,26 @@ clean: clean-js clean-buf clean-docs test: $(node_modules) build-buf npm run test +.PHONY: test-ci +test-ci: + npm run test + .PHONY: test-watch test-watch: $(node_modules) build-buf npm run test:watch -.PHONY: lint -lint: $(node_modules) build-buf +.PHONY: _lint +_lint: npm run lint npm run typecheck npm run check -- --reject="@bufbuild/protobuf,@connectrpc/connect,@connectrpc/connect-web" +.PHONY: lint +lint: $(node_modules) build-buf _lint + +.PHONY: lint-ci +lint-ci: _lint + .PHONY: format format: $(node_modules) npm run format @@ -52,13 +68,19 @@ clean-buf: update-buf: $(node_modules) $(buf) mod update -.PHONY: build-buf -build-buf: $(node_modules) clean-buf +.PHONY: _build-buf +_build-buf: $(buf) generate buf.build/googleapis/googleapis $(buf) generate buf.build/viamrobotics/api:$$(cat api_version.lock) --path common,component,robot,service,app,provisioning,tagger,stream $(buf) generate buf.build/viamrobotics/goutils $(buf) generate buf.build/grpc/grpc --path grpc/reflection/v1/reflection.proto +.PHONY: build-buf +build-buf: $(node_modules) clean-buf _build-buf + +.PHONY: build-buf-ci +build-buf-ci: _build-buf + # js targets .PHONY: clean-js @@ -93,11 +115,6 @@ build-docs: clean-docs build-buf # e2e tests -.PHONY: install-playwright -install-playwright: - cd e2e && npm install - cd e2e && npx playwright install --with-deps - e2e/bin/viam-server: bash e2e/setup.sh @@ -105,5 +122,9 @@ e2e/bin/viam-server: run-e2e-server: e2e/bin/viam-server e2e/bin/viam-server --config=./e2e/server_config.json -test-e2e: e2e/bin/viam-server build install-playwright - cd e2e && npm run e2e:playwright +test-e2e: e2e/bin/viam-server build + npx playwright install --with-deps + npm run e2e:playwright + +test-e2e-ci: e2e/bin/viam-server + npm run e2e:playwright diff --git a/package-lock.json b/package-lock.json index 31eb98cbc..fb8d1810f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -41,6 +41,9 @@ "vite": "^5.0.10", "vitest": "^1.1.0", "yaml": "^2.3.3" + }, + "engines": { + "node": ">=22" } }, "node_modules/@babel/code-frame": { diff --git a/package.json b/package.json index 4335b7521..303c7ac2b 100644 --- a/package.json +++ b/package.json @@ -16,6 +16,10 @@ "default": "./dist/main.es.js" } }, + "packageManager": "npm@10.9.3", + "engines": { + "node": ">=22" + }, "scripts": { "prebuild": "node ./scripts/write-versions.js", "build": "npm run build:bundle && npm run build:types && npm run build:copy-dts", @@ -39,8 +43,8 @@ "e2e:playwright-debug": "playwright test --debug", "e2e:playwright-install": "playwright install", "e2e:test-harness": "vite e2e", - "_eslint": "eslint '.*.cjs' '**/*.{ts,js,cjs}'", - "_prettier": "prettier '.*.cjs' '**/*.{ts,js,cjs}'" + "_eslint": "eslint '.*.cjs' '**/*.{ts,js,cjs}' --ignore-pattern 'src/gen/**' --ignore-pattern 'dist/**' --ignore-pattern 'docs/**'", + "_prettier": "prettier '.*.cjs' '**/*.{ts,js,cjs}' --ignore-path .prettierignore" }, "repository": { "type": "git",