Skip to content

AutoGPT is the vision of accessible AI for everyone, to use and to build on. Our mission is to provide the tools, so that you can focus on what matters.

dx: Sync types & dependencies on `pre-commit` and `post-checkout` (#12211)

Reinier van der Leerd5efb6915b75
diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml
index 39ec659ef9..d43c1d862c 100644
--- a/.pre-commit-config.yaml
+++ b/.pre-commit-config.yaml
@@ -1,3 +1,10 @@
+default_install_hook_types:
+ - pre-commit
+ - pre-push
+ - post-checkout
+
+default_stages: [pre-commit]
+
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.4.0
@@ -17,6 +24,7 @@ repos:
name: Detect secrets
description: Detects high entropy strings that are likely to be passwords.
files: ^autogpt_platform/
+ exclude: pnpm-lock\.yaml$
stages: [pre-push]
- repo: local
@@ -26,49 +34,106 @@ repos:
- id: poetry-install
name: Check & Install dependencies - AutoGPT Platform - Backend
alias: poetry-install-platform-backend
- entry: poetry -C autogpt_platform/backend install
# include autogpt_libs source (since it's a path dependency)
- files: ^autogpt_platform/(backend|autogpt_libs)/poetry\.lock$
- types: [file]
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^autogpt_platform/(backend|autogpt_libs)/poetry\.lock$" || exit 0;
+ poetry -C autogpt_platform/backend install
+ '
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
- id: poetry-install
name: Check & Install dependencies - AutoGPT Platform - Libs
alias: poetry-install-platform-libs
- entry: poetry -C autogpt_platform/autogpt_libs install
- files: ^autogpt_platform/autogpt_libs/poetry\.lock$
- types: [file]
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^autogpt_platform/autogpt_libs/poetry\.lock$" || exit 0;
+ poetry -C autogpt_platform/autogpt_libs install
+ '
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
+
+ - id: pnpm-install
+ name: Check & Install dependencies - AutoGPT Platform - Frontend
+ alias: pnpm-install-platform-frontend
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^autogpt_platform/frontend/pnpm-lock\.yaml$" || exit 0;
+ pnpm --prefix autogpt_platform/frontend install
+ '
+ always_run: true
+ language: system
+ pass_filenames: false
+ stages: [pre-commit, post-checkout]
- id: poetry-install
name: Check & Install dependencies - Classic - AutoGPT
alias: poetry-install-classic-autogpt
- entry: poetry -C classic/original_autogpt install
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^classic/(original_autogpt|forge)/poetry\.lock$" || exit 0;
+ poetry -C classic/original_autogpt install
+ '
# include forge source (since it's a path dependency)
- files: ^classic/(original_autogpt|forge)/poetry\.lock$
- types: [file]
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
- id: poetry-install
name: Check & Install dependencies - Classic - Forge
alias: poetry-install-classic-forge
- entry: poetry -C classic/forge install
- files: ^classic/forge/poetry\.lock$
- types: [file]
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^classic/forge/poetry\.lock$" || exit 0;
+ poetry -C classic/forge install
+ '
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
- id: poetry-install
name: Check & Install dependencies - Classic - Benchmark
alias: poetry-install-classic-benchmark
- entry: poetry -C classic/benchmark install
- files: ^classic/benchmark/poetry\.lock$
- types: [file]
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^classic/benchmark/poetry\.lock$" || exit 0;
+ poetry -C classic/benchmark install
+ '
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
- repo: local
# For proper type checking, Prisma client must be up-to-date.
@@ -76,12 +141,54 @@ repos:
- id: prisma-generate
name: Prisma Generate - AutoGPT Platform - Backend
alias: prisma-generate-platform-backend
- entry: bash -c 'cd autogpt_platform/backend && poetry run prisma generate'
+ entry: >
+ bash -c '
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --name-only "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF"
+ else
+ git diff --cached --name-only
+ fi | grep -qE "^autogpt_platform/((backend|autogpt_libs)/poetry\.lock|backend/schema\.prisma)$" || exit 0;
+ cd autogpt_platform/backend
+ && poetry run prisma generate
+ && poetry run gen-prisma-stub
+ '
# include everything that triggers poetry install + the prisma schema
- files: ^autogpt_platform/((backend|autogpt_libs)/poetry\.lock|backend/schema.prisma)$
- types: [file]
+ always_run: true
+ language: system
+ pass_filenames: false
+ stages: [pre-commit, post-checkout]
+
+ - id: export-api-schema
+ name: Export API schema - AutoGPT Platform - Backend -> Frontend
+ alias: export-api-schema-platform
+ entry: >
+ bash -c '
+ cd autogpt_platform/backend
+ && poetry run export-api-schema --output ../frontend/src/app/api/openapi.json
+ && cd ../frontend
+ && pnpm prettier --write ./src/app/api/openapi.json
+ '
+ files: ^autogpt_platform/backend/
+ language: system
+ pass_filenames: false
+
+ - id: generate-api-client
+ name: Generate API client - AutoGPT Platform - Frontend
+ alias: generate-api-client-platform-frontend
+ entry: >
+ bash -c '
+ SCHEMA=autogpt_platform/frontend/src/app/api/openapi.json;
+ if [ -n "$PRE_COMMIT_FROM_REF" ]; then
+ git diff --quiet "$PRE_COMMIT_FROM_REF" "$PRE_COMMIT_TO_REF" -- "$SCHEMA" && exit 0
+ else
+ git diff --quiet HEAD -- "$SCHEMA" && exit 0
+ fi;
+ cd autogpt_platform/frontend && pnpm generate:api
+ '
+ always_run: true
language: system
pass_filenames: false
+ stages: [pre-commit, post-checkout]
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
diff --git a/autogpt_platform/backend/backend/cli/generate_openapi_json.py b/autogpt_platform/backend/backend/cli/generate_openapi_json.py
index de74c0b5d2..1a642eea7f 100644
--- a/autogpt_platform/backend/backend/cli/generate_openapi_json.py
+++ b/autogpt_platform/backend/backend/cli/generate_openapi_json.py
@@ -34,10 +34,12 @@ def main(output: Path, pretty: bool):
"""Generate and output the OpenAPI JSON specification."""
openapi_schema = get_openapi_schema()
- json_output = json.dumps(openapi_schema, indent=2 if pretty else None)
+ json_output = json.dumps(
+ openapi_schema, indent=2 if pretty else None, ensure_ascii=False
+ )
if output:
- output.write_text(json_output)
+ output.write_text(json_output, encoding="utf-8")
click.echo(f"✅ OpenAPI specification written to {output}\n\nPreview:")
click.echo(f"\n{json_output[:500]} ...")
else: