From cc46f0107c38910297df9444a3a59049c1b4e680 Mon Sep 17 00:00:00 2001 From: Anas Husseini Date: Thu, 18 Jan 2024 16:50:24 +0200 Subject: [PATCH] address review requests --- .github/workflows/schema.yaml | 7 +++-- .../{rockcraft_schema.json => rockcraft.json} | 0 {.github/scripts => tools/schema}/schema.py | 29 ++++++++++--------- 3 files changed, 20 insertions(+), 16 deletions(-) rename schemas/{rockcraft_schema.json => rockcraft.json} (100%) rename {.github/scripts => tools/schema}/schema.py (70%) diff --git a/.github/workflows/schema.yaml b/.github/workflows/schema.yaml index 939aef6e5..089ea86ad 100644 --- a/.github/workflows/schema.yaml +++ b/.github/workflows/schema.yaml @@ -1,4 +1,4 @@ -name: schema +name: Schema on: [pull_request] jobs: @@ -23,4 +23,7 @@ jobs: run: python .github/scripts/schema.py > generated_schema.json - name: Check with stored schema - run: diff generated_schema.json schemas/rockcraft_schema.json > /dev/null + run: | + if [[ -f schemas/rockcraft.json ]]; then + diff generated_schema.json schemas/rockcraft_schema.json + fi diff --git a/schemas/rockcraft_schema.json b/schemas/rockcraft.json similarity index 100% rename from schemas/rockcraft_schema.json rename to schemas/rockcraft.json diff --git a/.github/scripts/schema.py b/tools/schema/schema.py similarity index 70% rename from .github/scripts/schema.py rename to tools/schema/schema.py index d0d932552..40d565efa 100644 --- a/.github/scripts/schema.py +++ b/tools/schema/schema.py @@ -18,36 +18,37 @@ import json import os import sys -from typing import TYPE_CHECKING +import yaml from craft_parts import Part script_dir = os.path.dirname(os.path.realpath(__file__)) sys.path.append(os.path.join(script_dir, "../../")) +from rockcraft import cli # noqa: E402 from rockcraft.models.project import Project # noqa: E402 -if TYPE_CHECKING: - import argparse - def generate_project_schema() -> str: """Generate the schema.""" - project = Project( - name="placeholder", - version="1.0", - summary="summary", - description="description", - base="ubuntu@22.04", - parts=[], - license="MIT", - platforms={"amd64": None}, + # Initiate a project with all required fields + project = Project.unmarshal( + yaml.safe_load( + # pylint: disable=W0212 + cli.commands.InitCommand._INIT_TEMPLATE_YAML + ) ) + + # generate the project schema project_schema = project.schema(by_alias=True) + # override the generic title "Project" + project_schema["title"] = "Rockcraft project" + # project.schema() will define the `parts` field as an `object` + # so we need to manually add the schema for parts by running + # schema() on part.spec and add the outcome project schema's definitions part = Part(name="placeholder", data={}) part_schema = part.spec.schema(by_alias=True) - project_schema["properties"]["parts"]["additionalProperties"] = { "$ref": "#/definitions/Part" }