diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml index 4eeab1089..2825c3bf4 100644 --- a/.github/workflows/pre-commit.yml +++ b/.github/workflows/pre-commit.yml @@ -36,20 +36,16 @@ jobs: **/requirements*.txt .pre-commit-config.yaml - # npm ci may fail - - # npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing. - # npm error Invalid: lock file's llama-stack-client@0.2.17 does not satisfy llama-stack-client@0.2.18 + - name: Set up Node.js + uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 + with: + node-version: '20' + cache: 'npm' + cache-dependency-path: 'llama_stack/ui/' - # - name: Set up Node.js - # uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0 - # with: - # node-version: '20' - # cache: 'npm' - # cache-dependency-path: 'llama_stack/ui/' - - # - name: Install npm dependencies - # run: npm ci - # working-directory: llama_stack/ui + - name: Install npm dependencies + run: npm ci + working-directory: llama_stack/ui - uses: pre-commit/action@2c7b3805fd2a0fd8c1884dcaebf91fc102a13ecd # v3.0.1 continue-on-error: true diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d25455cf0..514fe6d2e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -146,31 +146,13 @@ repos: pass_filenames: false require_serial: true files: ^.github/workflows/.*$ - # ui-prettier and ui-eslint are disabled until we can avoid `npm ci`, which is slow and may fail - - # npm error `npm ci` can only install packages when your package.json and package-lock.json or npm-shrinkwrap.json are in sync. Please update your lock file with `npm install` before continuing. - # npm error Invalid: lock file's llama-stack-client@0.2.17 does not satisfy llama-stack-client@0.2.18 - # and until we have infra for installing prettier and next via npm - - # Lint UI code with ESLint.....................................................Failed - # - hook id: ui-eslint - # - exit code: 127 - # > ui@0.1.0 lint - # > next lint --fix --quiet - # sh: line 1: next: command not found - # - # - id: ui-prettier - # name: Format UI code with Prettier - # entry: bash -c 'cd llama_stack/ui && npm ci && npm run format' - # language: system - # files: ^llama_stack/ui/.*\.(ts|tsx)$ - # pass_filenames: false - # require_serial: true - # - id: ui-eslint - # name: Lint UI code with ESLint - # entry: bash -c 'cd llama_stack/ui && npm run lint -- --fix --quiet' - # language: system - # files: ^llama_stack/ui/.*\.(ts|tsx)$ - # pass_filenames: false - # require_serial: true + - id: ui-linter + name: Format & Lint UI + entry: bash ./scripts/run-ui-linter.sh + language: system + files: ^llama_stack/ui/.*\.(ts|tsx)$ + pass_filenames: false + require_serial: true - id: check-log-usage name: Ensure 'llama_stack.log' usage for logging diff --git a/scripts/run-ui-linter.sh b/scripts/run-ui-linter.sh new file mode 100755 index 000000000..3ced4483b --- /dev/null +++ b/scripts/run-ui-linter.sh @@ -0,0 +1,17 @@ +#!/bin/bash +# Copyright (c) Meta Platforms, Inc. and affiliates. +# All rights reserved. +# +# This source code is licensed under the terms described in the LICENSE file in +# the root directory of this source tree. + +set -e +cd llama_stack/ui + +if [ ! -d node_modules ] || [ ! -x node_modules/.bin/prettier ] || [ ! -x node_modules/.bin/eslint ]; then + echo "UI dependencies not installed, skipping prettier/linter check" + exit 0 +fi + +npm run format +npm run lint