-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #540 from bento-platform/features/schema-artifacts
chore: publish json schemas as release artifacts
- Loading branch information
Showing
2 changed files
with
84 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
name: Create and upload release artifacts | ||
on: | ||
release: | ||
types: [published, prereleased] | ||
|
||
jobs: | ||
release-artifacts: | ||
runs-on: ubuntu-latest | ||
|
||
permissions: | ||
contents: write | ||
repository-projects: write | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
submodules: true | ||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.11" | ||
- name: Install Poetry | ||
run: python -m pip install poetry | ||
- name: Install dependencies | ||
run: poetry install | ||
- name: Make release artifacts | ||
run: | | ||
mkdir -p ./dist/schemas | ||
poetry run ./manage.py schemas phenopacket >> ./dist/schemas/phenopacket_schema.json | ||
poetry run ./manage.py schemas experiment >> ./dist/schemas/experiment_schema.json | ||
poetry run ./manage.py schemas discovery >> ./dist/schemas/discovery.json | ||
pushd ./dist/schemas | ||
zip -r ../../json-schemas.zip * | ||
- name: Upload release artifacts | ||
uses: actions/github-script@v7 | ||
with: | ||
script: | | ||
const fs = require("fs"); | ||
// get tag | ||
const tag = context.ref.replace("refs/tags/", ""); | ||
// get release from tag | ||
const release = await github.rest.repos.getReleaseByTag({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
tag: tag, | ||
}); | ||
await github.rest.repos.uploadReleaseAsset({ | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
release_id: release.data.id, | ||
name: "json-schemas.zip", | ||
data: await fs.readFileSync("./json-schemas.zip"), | ||
}); |
28 changes: 28 additions & 0 deletions
28
chord_metadata_service/chord/management/commands/schemas.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import json | ||
from typing import Any | ||
from django.core.management.base import BaseCommand, CommandParser | ||
|
||
from chord_metadata_service.chord.data_types import DATA_TYPE_EXPERIMENT, DATA_TYPE_PHENOPACKET | ||
from chord_metadata_service.discovery.schemas import DISCOVERY_SCHEMA | ||
from chord_metadata_service.experiments.schemas import EXPERIMENT_SCHEMA | ||
from chord_metadata_service.phenopackets.schemas import PHENOPACKET_SCHEMA | ||
|
||
NAME_TO_SCHEMA: dict[str, object] = { | ||
DATA_TYPE_PHENOPACKET: PHENOPACKET_SCHEMA, | ||
DATA_TYPE_EXPERIMENT: EXPERIMENT_SCHEMA, | ||
"discovery": DISCOVERY_SCHEMA, | ||
} | ||
|
||
|
||
class Command(BaseCommand): | ||
help = """ | ||
Compiles and returns a JSON-schema in a single JSON file for artifact. | ||
Use in GitHub Actions in order to publish usable schemas on releases. | ||
""" | ||
|
||
def add_arguments(self, parser: CommandParser) -> None: | ||
parser.add_argument("schema", action="store", type=str, choices=NAME_TO_SCHEMA.keys()) | ||
|
||
def handle(self, *args: Any, **options: Any) -> str | None: | ||
schema = NAME_TO_SCHEMA[options["schema"]] | ||
self.stdout.write(json.dumps(schema, indent=2)) |