Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add script to automatically remove accepted ontologies #23

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .github/workflows/purge.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Remove Accepted Ontologies
on:
workflow_dispatch:
schedule:
- cron: "0 0 * * *" # once per day
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
with:
persist-credentials: false # otherwise, the token used is the GITHUB_TOKEN, instead of your personal token
fetch-depth: 0 # otherwise, you will failed to push refs to dest repo

- uses: actions/setup-python@v2
with:
python-version: "3.11"

- name: Install dependencies
run: |
pip install --upgrade pip
pip install --upgrade setuptools wheel
pip install tox
- name: Update
run: |
tox -e purge
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add --all
git commit -m "Automatically remove accepted ontologies" -a
- name: Push changes
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please pull request instead - I prefer not to commit to master..
https://github.com/OBOFoundry/obo-nor.github.io/blob/master/.github/workflows/dashboard.yml#L31

uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
16 changes: 14 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,21 @@
# Repo to manage the OBO Foundry Dashboard for New Ontology Requests
# Repo to manage the OBO Foundry Dashboard for New Ontology Requests (NORs)

Page deployed at: https://obofoundry.github.io/obo-nor.github.io/

To update:
## Update

1. change `dashboard-config.yml`
2. run `sh run-dash.sh`

## Remove accepted ontologies

After ontologies have been accepted into the OBO Foundry, they will be displayed on the
main [OBO Dashboard](https://dashboard.obofoundry.org/) and can be safely removed from the NOR dashboard. This is
automated with the following code:

```shell
pip install tox
tox -e purge
```

This is also automatically run nightly via GitHub Actions. [![Remove Accepted Ontologies](https://github.com/OBOFoundry/obo-nor.github.io/actions/workflows/purge.yml/badge.svg)](https://github.com/OBOFoundry/obo-nor.github.io/actions/workflows/purge.yml)
44 changes: 44 additions & 0 deletions scripts/purge.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
"""Purge accepted ontologies from NOR Dashboard."""

from pathlib import Path

import click
import requests
import yaml

HERE = Path(__file__).parent.resolve()
ROOT = HERE.parent.resolve()
DASHBOARD_DIRECTORY = ROOT.joinpath("dashboard")
DASHBOARD_CONFIG_PATH = ROOT.joinpath("dashboard-config.yml")

URL = "https://raw.githubusercontent.com/OBOFoundry/OBOFoundry.github.io/master/registry/ontologies.yml"


@click.command()
def main():
"""Purge accepted ontologies from NOR Dashboard."""
#: A set of prefixes for active ontologies in the OBO Foundry
prefixes = {
record["id"]
for record in yaml.safe_load(requests.get(URL).content)["ontologies"]
if record["activity_status"] in {"active"}
}

# Remove folders corresponding to active ontologies
for directory in DASHBOARD_DIRECTORY.iterdir():
if directory.is_dir() and directory.name in prefixes:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is already an action that deals with cleaning the directory. Only the yaml file needs to be edited! The rest happens automatically!

for path in directory.iterdir():
click.echo(f"removing file: {path}")
path.unlink()
click.echo(f"removing directory: {directory}")
directory.rmdir()

# Remove configuration corresponding to active ontologies
config = yaml.safe_load(DASHBOARD_CONFIG_PATH.read_text())
config["ontologies"]["custom"] = [
row for row in config["ontologies"]["custom"] if row["id"] not in prefixes
]


if __name__ == "__main__":
main()
22 changes: 22 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[tox]
envlist =
lint
purge

[testenv:purge]
skip_install = true
deps =
click
requests
pyyaml
commands =
python scripts/purge.py

[testenv:lint]
skip_install = true
deps =
black
isort
commands =
isort --profile=black .
black .