From 1563cbdbaa722ba7b472d3331b73e1ef0814310e Mon Sep 17 00:00:00 2001 From: Yao Xiao <108576690+Charlie-XIAO@users.noreply.github.com> Date: Sun, 17 Nov 2024 22:13:25 -0500 Subject: [PATCH] ci: add code linting and formatting workflow (#12) * ci: add code linting and formatting workflow * fix node cache dependency path * install pipenv * specify node v20 to try to suppress warning --- .github/workflows/lint.yaml | 49 +++++++++++++++++++++++++++++++++++++ app/Makefile | 6 +++++ 2 files changed, 55 insertions(+) create mode 100644 .github/workflows/lint.yaml diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml new file mode 100644 index 0000000..d0369b2 --- /dev/null +++ b/.github/workflows/lint.yaml @@ -0,0 +1,49 @@ +name: Formatting and Linting + +on: + push: + branches: + - main + pull_request: + branches: + - main + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + lint: + runs-on: ubuntu-latest + + steps: + - name: Checkout repository + uses: actions/checkout@v4 + + - name: Python setup + uses: actions/setup-python@v4 + with: + python-version: '3.11' + cache: pipenv + cache-dependency-path: app/backend/Pipfile.lock + + - name: Install pipenv + run: pip install pipenv + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + version: 9 + + - name: Node setup and cache + uses: actions/setup-node@v4 + with: + node-version: 20 + cache: pnpm + cache-dependency-path: app/frontend/pnpm-lock.yaml + + - name: Install development dependencies + run: cd app && make devinstall + + - name: Check code formatting and linting + run: cd app && make devlintcheck diff --git a/app/Makefile b/app/Makefile index 37cfbbf..5c84eee 100644 --- a/app/Makefile +++ b/app/Makefile @@ -11,6 +11,12 @@ devlock: @cd backend && pipenv lock && pipenv sync -d && pipenv clean @cd frontend && pnpm install +# [DEV] Install development dependencies on the host machine based on the lock +# files without modifying them +devinstall: + @cd backend && pipenv sync -d + @cd frontend && pnpm install --frozen-lockfile + # [DEV] Format and lint the codebase devlint: @cd backend && pipenv run bash -c "black . && ruff check --select I --fix . && ruff format . && mypy ."