generated from hubmapconsortium/hubmap-template
-
Notifications
You must be signed in to change notification settings - Fork 3
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 #101 from hubmapconsortium/thomcsmits/check-tags
add script + github action to check if all tags are included in src/tags.json
- Loading branch information
Showing
2 changed files
with
53 additions
and
2 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,22 @@ | ||
name: Check Template Tags | ||
|
||
on: | ||
push: | ||
pull_request: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
build: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
matrix: | ||
python-version: ["3.8", "3.9", "3.10"] | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- name: Set up Python ${{ matrix.python-version }} | ||
uses: actions/setup-python@v3 | ||
with: | ||
python-version: ${{ matrix.python-version }} | ||
- name: Check tags | ||
run: | | ||
python src/user_templates_api/tests.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 |
---|---|---|
@@ -1,3 +1,32 @@ | ||
# from django.test import TestCase | ||
# Testing tags | ||
import json | ||
import os | ||
|
||
# Create your tests here. | ||
# read in the existing tags in tags.json | ||
with open("./src/tags.json") as file: | ||
tags_dict = json.load(file) | ||
|
||
tags = list(tags_dict.keys()) | ||
tags.sort() | ||
|
||
# retrieve all tags used in templates | ||
templates_path = "./src/user_templates_api/templates/jupyter_lab/templates/" | ||
templates = os.listdir(templates_path) | ||
|
||
template_tags = [] | ||
for template in templates: | ||
with open(templates_path + template + "/metadata.json") as file: | ||
metadata = json.load(file) | ||
if not metadata["is_hidden"]: | ||
template_tags.extend(metadata["tags"]) | ||
|
||
template_tags = list(set(template_tags)) | ||
template_tags.sort() | ||
|
||
# check if all tags used in templates are part of tags.json | ||
missing_tags = [tag for tag in template_tags if tag not in tags] | ||
|
||
if len(missing_tags) > 0: | ||
raise ValueError( | ||
f"All tags in templates should exist in tags.json. The following tags are missing in tags.json: {missing_tags}" | ||
) |