Skip to content

Commit

Permalink
address review requests
Browse files Browse the repository at this point in the history
  • Loading branch information
linostar committed Jan 18, 2024
1 parent 516111d commit cc46f01
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 16 deletions.
7 changes: 5 additions & 2 deletions .github/workflows/schema.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: schema
name: Schema
on: [pull_request]

jobs:
Expand All @@ -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
File renamed without changes.
29 changes: 15 additions & 14 deletions .github/scripts/schema.py → tools/schema/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -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="[email protected]",
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"
}
Expand Down

0 comments on commit cc46f01

Please sign in to comment.