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.yamlindex 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-hooksrev: v4.4.0@@ -17,6 +24,7 @@ repos:name: Detect secretsdescription: 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-installname: Check & Install dependencies - AutoGPT Platform - Backendalias: 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: truelanguage: systempass_filenames: false+ stages: [pre-commit, post-checkout]- id: poetry-installname: Check & Install dependencies - AutoGPT Platform - Libsalias: 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: truelanguage: systempass_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-installname: Check & Install dependencies - Classic - AutoGPTalias: 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: truelanguage: systempass_filenames: false+ stages: [pre-commit, post-checkout]- id: poetry-installname: Check & Install dependencies - Classic - Forgealias: 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: truelanguage: systempass_filenames: false+ stages: [pre-commit, post-checkout]- id: poetry-installname: Check & Install dependencies - Classic - Benchmarkalias: 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: truelanguage: systempass_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-generatename: Prisma Generate - AutoGPT Platform - Backendalias: 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: truelanguage: systempass_filenames: false+ stages: [pre-commit, post-checkout]- repo: https://github.com/astral-sh/ruff-pre-commitrev: v0.7.2diff --git a/autogpt_platform/backend/backend/cli/generate_openapi_json.py b/autogpt_platform/backend/backend/cli/generate_openapi_json.pyindex 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: