Skip to content

Commit

Permalink
Merge pull request #276 from dandi/gh-273
Browse files Browse the repository at this point in the history
Add workflow for publishing model schemata to dandi/schema
  • Loading branch information
yarikoptic authored Nov 23, 2020
2 parents 97292b7 + 32d49e7 commit 39c62bc
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
51 changes: 51 additions & 0 deletions .github/workflows/publish-schemata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: Publish model schemata

on:
# ATM, this is the closest trigger to a PR merging
push:
branches:
- master
paths:
- dandi/model*.py
- tools/pubschemata.py

jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout this repository
uses: actions/checkout@v2
with:
fetch-depth: 0 # Need history for `git describe`
path: dandi

- name: Set up Python
uses: actions/setup-python@v1
with:
python-version: '3.8'

- name: Install dandi
run: python -m pip install .
working-directory: dandi

- name: Checkout dandi/schema
uses: actions/checkout@v2
with:
repository: dandi/schema
path: schema
token: ${{ secrets.DANDI_GITHUB_TOKEN }}

- name: Generate model schemata
run: python dandi/tools/pubschemata.py schema/releases

- name: Commit changes
run: |
git add releases
if ! git diff --quiet
then git commit -m "Publish model schemata as of dandi-cli $(git -C ../dandi describe --tags)"
git push
else echo "No changes to commit"
fi
working-directory: schema

# vim:set sts=2:
15 changes: 15 additions & 0 deletions tools/pubschemata.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path
import sys
from dandi.models import AssetMeta, CommonModel, DandiMeta


def publish_model_schemata(releasedir):
version = CommonModel.__fields__["schemaVersion"].default
vdir = Path(releasedir, version)
vdir.mkdir(exist_ok=True, parents=True)
(vdir / "dandiset.json").write_text(DandiMeta.schema_json(indent=2))
(vdir / "asset.json").write_text(AssetMeta.schema_json(indent=2))


if __name__ == "__main__":
publish_model_schemata(sys.argv[1])

0 comments on commit 39c62bc

Please sign in to comment.