-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
156 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,30 @@ | ||
name: publish | ||
on: | ||
push: | ||
branches: | ||
- main | ||
workflow_dispatch: | ||
permissions: | ||
contents: write | ||
jobs: | ||
deploy: | ||
name: Download and publish JSON schemas | ||
if: github.event.repository.fork == false | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout repo content | ||
uses: actions/checkout@v4 | ||
- name: Setup Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: 3.x | ||
- name: Install dependencies | ||
run: pip install requests | ||
- name: Execute Python script | ||
run: python sync.py ./src/catalog.json ./publish | ||
- name: Deploy to GitHub Pages | ||
uses: peaceiris/actions-gh-pages@v4 | ||
with: | ||
github_token: ${{ secrets.GITHUB_TOKEN }} | ||
publish_dir: ./publish | ||
|
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,8 @@ | ||
# OpenPotato SchemaHub | ||
|
||
The aim of OpenPotato SchemaHub is to provide a central repository for the various JSON schema specifications at the OpenPotato Project. The schema files are stored under GitHub Pages and can be addressed via `https://schemahub.openpotato.org/<namesspace>/<version-tag>/<schema file>`. | ||
|
||
Here is a list of the available schema files: | ||
|
||
+ https://schemahub.openpotato.org/csv-table-schema/v0.1/schema.json | ||
+ https://schemahub.openpotato.org/opencoli/v0.1/schema.json |
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 @@ | ||
schemahub.openpotato.org |
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,51 @@ | ||
{ | ||
"$schema": "https://json-schema.org/draft/2020-12/schema", | ||
"id": "https://schemahub.openpotato.org/schema-catalog.json", | ||
"title": "Catalog Schema Specification for schemahub.openpotato.org", | ||
"description": "JSON schema for the schemahub.openpotato.org catalog file", | ||
"type": "object", | ||
"properties": { | ||
"schemas": { | ||
"description": "A list of JSON schema references.", | ||
"type": "array", | ||
"items": { | ||
"type": "object", | ||
"properties": { | ||
"name": { | ||
"description": "The name of the schema", | ||
"type": "string" | ||
}, | ||
"description": { | ||
"description": "A description of the schema", | ||
"type": "string" | ||
}, | ||
"urls": { | ||
"description": "A list of absolute schema location URLs", | ||
"uniqueItems": true, | ||
"type": "array", | ||
"items": { | ||
"type": "string", | ||
"format": "uri", | ||
"pattern": "^https://" | ||
} | ||
}, | ||
"targetFolder": { | ||
"description": "A relative target folder into which the schema files for the publication are to be copied.", | ||
"type": "string" | ||
} | ||
}, | ||
"required": [ | ||
"name", | ||
"description", | ||
"urls", | ||
"targetFolder" | ||
], | ||
"additionalProperties": false | ||
} | ||
} | ||
}, | ||
"required": [ | ||
"schemas" | ||
], | ||
"additionalProperties": false | ||
} |
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,22 @@ | ||
{ | ||
"$schema": "https://schemahub.openpotato.org/schema-catalog.json", | ||
"version": 1, | ||
"schemas": [ | ||
{ | ||
"name": "CSV Table Schema Specification v-0.1", | ||
"description": "JSON schema for CSV Table Schema (version 0.1)", | ||
"targetFolder": "csv-table-schema/v0.1", | ||
"urls": [ | ||
"https://raw.githubusercontent.com/openpotato/csv-table-schema/main/schemas/v0.1/schema.json" | ||
] | ||
}, | ||
{ | ||
"name": "OpenCoLi Schema v-0.1", | ||
"description": "JSON schema for OpenCoLi format (version 0.1)", | ||
"targetFolder": "opencoli/v0.1", | ||
"urls": [ | ||
"https://raw.githubusercontent.com/openpotato/opencoli/main/schemas/v0.1/schema.json" | ||
] | ||
} | ||
] | ||
} |
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,44 @@ | ||
import json | ||
import os | ||
import requests | ||
import argparse | ||
|
||
def download_json_files(catalog_file_path, base_target_folder): | ||
# Read the JSON catalog file | ||
with open(catalog_file_path, 'r') as file: | ||
data = json.load(file) | ||
|
||
# Iterate through the schemas | ||
for schema in data['schemas']: | ||
relative_target_folder = schema['targetFolder'] | ||
urls = schema['urls'] | ||
|
||
# Create the full path to the target folder under the base folder | ||
full_target_folder = os.path.join(base_target_folder, relative_target_folder) | ||
|
||
# Create the target folder if it doesn't exist | ||
if not os.path.exists(full_target_folder): | ||
os.makedirs(full_target_folder) | ||
|
||
# Download each JSON file and save it to the target folder | ||
for url in urls: | ||
response = requests.get(url) | ||
if response.status_code == 200: | ||
file_name = os.path.join(full_target_folder, url.split('/')[-1]) | ||
with open(file_name, 'w', encoding='utf8') as json_file: | ||
json_file.write(response.text) | ||
print(f"Downloaded and saved {url} to {file_name}") | ||
else: | ||
print(f"Failed to download {url}") | ||
|
||
if __name__ == "__main__": | ||
# Setup argument parser | ||
parser = argparse.ArgumentParser(description="Download JSON schemas and save them to specified folders.") | ||
parser.add_argument('catalog_file_path', type=str, help='Path to the input JSON file.') | ||
parser.add_argument('base_target_folder', type=str, help='Base folder where target folders will be created.') | ||
|
||
# Parse arguments | ||
args = parser.parse_args() | ||
|
||
# Call the download function with the provided arguments | ||
download_json_files(args.catalog_file_path, args.base_target_folder) |