diff --git a/.github/workflows/static-analysis.yaml b/.github/workflows/static-analysis.yaml index aba7bf3b6b25..e9dd3ff3ce9b 100644 --- a/.github/workflows/static-analysis.yaml +++ b/.github/workflows/static-analysis.yaml @@ -67,3 +67,22 @@ jobs: - name: Run pre-commit run: | pre-commit run --show-diff-on-failure --color=always --all-files + + - name: Extract branch name + shell: bash + run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT + id: extract_branch + + - name: Generate OpenAPI YAML and commit + # Generate OpenAPI YAML for the UI + with: + token: ${{ secrets.PREFECT_CONTENTS_PR_RW }} + run: | + uv run --with 'pydantic>=2.9.0' ./scripts/generate_openapi_yml.py + git add src/prefect/_internal/openapi.yml + git commit -m "Update OpenAPI YAML" || echo "No changes to commit" + git push orign HEAD:${{ github.head_ref || github.ref_name }} + env: + GITHUB_TOKEN: ${{ secrets.PREFECT_CONTENTS_PR_RW }} + + \ No newline at end of file diff --git a/scripts/generate_openapi_yml.py b/scripts/generate_openapi_yml.py new file mode 100644 index 000000000000..f0d033d730b5 --- /dev/null +++ b/scripts/generate_openapi_yml.py @@ -0,0 +1,34 @@ +import inspect +import os + +import yaml +from fastapi.openapi.utils import get_openapi + +from prefect.server.api.server import create_api_app # type: ignore + +app = create_api_app() + +schema = get_openapi(title=app.title, version=app.version, routes=app.routes) + +OPENAPI_YAML_PATH = os.path.join( + os.path.dirname(os.path.dirname(__file__)), + "src", + "prefect", + "_internal", + "openapi.yml", +) + +with open(OPENAPI_YAML_PATH, "w+") as file: + file.write( + inspect.cleandoc( + f""" + # ### {app.title}: Version {app.version} + # - This file is auto-generated by scripts/generate_openapi_yml.py + # - Do not edit this file directly. + """ + ) + + "\n" + ) + yaml.dump(schema, file, sort_keys=False) + +del app