Skip to content

Commit

Permalink
Merge pull request #101 from hubmapconsortium/thomcsmits/check-tags
Browse files Browse the repository at this point in the history
add script + github action to check if all tags are included in src/tags.json
  • Loading branch information
jpuerto-psc authored Oct 28, 2024
2 parents 9c98723 + 30f305d commit 6e61901
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 2 deletions.
22 changes: 22 additions & 0 deletions .github/workflows/check_tags.yml
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
33 changes: 31 additions & 2 deletions src/user_templates_api/tests.py
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}"
)

0 comments on commit 6e61901

Please sign in to comment.