Skip to content

Commit

Permalink
Automatically check PRs for trivial mistakes with GitHub Actions
Browse files Browse the repository at this point in the history
  • Loading branch information
jeandet authored Jan 19, 2024
1 parent f8fd30d commit 2c849e7
Show file tree
Hide file tree
Showing 5 changed files with 92 additions and 13 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/PRs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: PR Tests

on: [ pull_request ]

jobs:
check_projects:
runs-on: ubuntu-latest
steps:
- name: Checkout PR
uses: actions/checkout@v4
- name: Set up Python 3.12
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install dependencies
run: |
python -m pip install pyyaml
- name: Run PR checker
run: |
python .github/workflows/pr_checker.py
58 changes: 58 additions & 0 deletions .github/workflows/pr_checker.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import yaml
from glob import glob
import os
import itertools
import argparse

here = os.path.dirname(__file__)
root = os.path.abspath(f'{here}/../../')

parser = argparse.ArgumentParser(
prog='pyhc website checker program',
description='Check that all yaml files are valid',
epilog='Enjoy the program! :)')

parser.add_argument('-d', '--dry-run', action='store_true', help='Dry run')


def ensure_all_yaml_files_are_valid(dry_run: bool = False):
for yaml_file in glob(f"{root}/**/*.yml", recursive=True):
try:
with open(yaml_file, "r") as f:
yaml.safe_load(f)
except Exception as e:
if dry_run:
print(f"Invalid yaml file: {yaml_file}")
else:
raise e


def load_taxonomy():
with open(f"{root}/_data/taxonomy.yml", "r") as f:
t = yaml.safe_load(f)
return set(itertools.chain.from_iterable(map(lambda x: x["keywords"], t)))


def check_keywords_respect_taxonomy(projects_file: str, dry_run: bool = False):
allowed_keywords: set = load_taxonomy()
with open(projects_file, "r") as f:
projects = yaml.safe_load(f)
for project in projects:
if "keywords" in project:
project_keywords = set(project["keywords"])
unlisted_keywords = project_keywords.difference(allowed_keywords)
if len(unlisted_keywords) > 0:
if dry_run:
print(f"Unlisted keywords for project {project['name']}: {unlisted_keywords}")
else:
raise Exception(f"Unlisted keywords for project {project['name']}: {unlisted_keywords}")
else:
print(f"Project {project['name']} has no keywords")


if __name__ == "__main__":
dry_run = parser.parse_args().dry_run
ensure_all_yaml_files_are_valid(dry_run=dry_run)
check_keywords_respect_taxonomy(f"{root}/_data/projects_core.yml", dry_run=dry_run)
check_keywords_respect_taxonomy(f"{root}/_data/projects.yml", dry_run=dry_run)
check_keywords_respect_taxonomy(f"{root}/_data/projects_unevaluated.yml", dry_run=dry_run)
19 changes: 10 additions & 9 deletions _data/projects.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
docs: https://afino-release-version.readthedocs.io/
description: A tool for finding oscillations in time series data
contact: Andrew Inglis
keywords: ["data_analysis"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
testing: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
Expand Down Expand Up @@ -57,7 +58,7 @@
docs: "https://geospacelab.readthedocs.io/en/latest/"
code: "https://github.com/JouleCai/geospacelab"
contact: "Lei Cai"
keywords: ["geospace","ionosphere_thermosphere_mesosphere","magnetosphere","data_retrieval","data_containe","plotting","data_access", "data_analysis"]
keywords: ["geospace","ionosphere_thermosphere_mesosphere","magnetosphere","data_retrieval","data_container","plotting","data_access", "data_analysis"]
community: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Partially met"]
testing: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
Expand Down Expand Up @@ -149,7 +150,7 @@
description: "Data loader for Solar Orbiter/EPD energetic charged particle sensors EPT, HET, and STEP"
docs: https://github.com/jgieseler/solo-epd-loader#readme=
contact: Jan Gieseler
keywords: ["data", "data_access", "data_retrieval", "heliosphere", "heliophysics", "instrumentation", "solar", "space physics", "specific"]
keywords: ["data_access", "data_retrieval", "heliosphere","instrumentation", "solar", "specific"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Requires%20improvement-red.svg", "Requires improvement"]
Expand All @@ -162,7 +163,7 @@
description: "A CCSDS telemetry packet decoding library based on the XTCE packet format description standard."
docs: "https://space-packet-parser.readthedocs.io"
contact: "Gavin Medley"
keywords: ["ccsds", "xtce", "space data systems", "space packet protocol", "packet parsing", "lasp", "university of colorado", "data processing", "data extraction", "data manipulation", "data transformation", "data encoding", "data decoding", "packet inspection", "binary data", "python"]
keywords: ["ccsds", "xtce", "packet_parsing", "packet_inspection", "data_analysis", "data_assimilation", "binary"]
community: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
Expand Down Expand Up @@ -256,7 +257,7 @@
docs: "https://docs.sunpy.org/projects/ndcube"
code: "https://github.com/sunpy/ndcube"
contact: "Dan Ryan"
keywords: ["heliophysics", "solar", "astrophysics", "n-dimensional", "data", "container objects", "visualization", "data manipulation"]
keywords: ["coordinates", "data_analysis", "data_container", "heliosphere", "plotting", "solar"]
community: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
Expand Down Expand Up @@ -298,7 +299,7 @@
docs: "https://aidapy.readthedocs.io"
description: "A Python package to provide machine learning and statistical methods to heliophysics data"
contact: "Romain Dupuis, Jorge Amaya, Giovanni Lapenta"
keyword: ["machine learning", "heliophysics", "statistics", "data"]
keywords: ["machine_learning", "heliosphere", "data_analysis"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
testing: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
Expand All @@ -311,7 +312,7 @@
docs: "https://github.com/tsssss/geopack/blob/master/README.md"
code: "https://github.com/tsssss/geopack"
contact: "Sheng Tian"
keywords: ["heliophysics", "space physics", "magnetospheric physics"]
keywords: ["heliosphere", "magnetosphere"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
Expand Down Expand Up @@ -350,7 +351,7 @@
docs: "https://docs.sunpy.org/projects/sunraster"
code: "https://github.com/sunpy/sunraster"
contact: "Nabil Freij"
keywords: ["solar", "data_container", "spectral", "plotting", "general", "fits"]
keywords: ["solar", "data_container", "spectra", "plotting", "general", "fits"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
Expand Down Expand Up @@ -402,7 +403,7 @@
docs: "https://irispy-lmsal.readthedocs.io"
code: "https://gitlab.com/LMSAL_HUB/iris_hub/irispy-lmsal"
contact: "Nabil Freij"
keywords: ["solar", "specific", "data_analysis", "spectral", "fits", "time", "coordinates","plotting", "multidimensional"]
keywords: ["solar", "specific", "data_analysis", "spectra", "fits", "time", "coordinates","plotting", "multidimensional"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
Expand Down Expand Up @@ -544,7 +545,7 @@
description: LOFAR solar and spaceweather data processing
logo: https://lofar-sun-tools.readthedocs.io/en/latest/_static/logo0.png
contact: Peijin Zhang
keywords: ["Solar_radio", "LOFAR"]
keywords: ["lofar"]
community: ["https://img.shields.io/badge/Partially%20met-orange.svg", "Partially met"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Requires%20improvement-red.svg", "Requires improvement"]
Expand Down
2 changes: 1 addition & 1 deletion _data/projects_core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
docs: "https://pyspedas.readthedocs.io"
code: "https://github.com/spedas/pyspedas"
contact: "Jim Lewis"
keywords: ["ace","arase","cdf","cluster","coordinates","csswe","data","data_access","dscovr","equator_s","fast","geotail","heliophysics","image","kyoto_dst","line_plots","magnetospheric physics","maven","mica","mms","plotting","poes","polar","psp","solo","space physics","spectra","stereo","themis","twins","ulysses","van_allen_probes","wind"]
keywords: ["ace","arase","cdf","cluster","coordinates","csswe","data_access","dscovr","equator_s","fast","geotail","heliosphere","image","kyoto_dst","line_plots","magnetosphere","maven","mica","mms","plotting","poes","polar","psp","solo","spectra","stereo","themis","twins","ulysses","van_allen_probes","wind"]
community: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
documentation: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
testing: ["https://img.shields.io/badge/Good-brightgreen.svg", "Good"]
Expand Down
6 changes: 3 additions & 3 deletions _data/taxonomy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

- category: "Functionality"
description: "The functionality available in a package"
keywords: ["2D_graphics", "3D_graphics", "calibration", "ccsds", "coordinates", "data_container", "data_retrieval", "image_processing", "interactive", "line_plots", "machine_learning", "multidimensional", "orbit", "plotting", "power_spectra", "spectra", "time"]
keywords: ["2D_graphics", "3D_graphics", "calibration", "ccsds", "coordinates", "data_container", "data_retrieval", "image_processing", "interactive", "line_plots", "machine_learning", "multidimensional", "orbit", "packet_parsing", "packet_inspection", "plotting", "power_spectra", "spectra", "time", "xtce"]

- category: "Span"
description: "The user scope of a project"
keywords: ["general", "specific"]

- category: "Input/Output Formats"
description: "The different data formats a package reads and/or writes"
keywords: ["ascii", "cdf", "csv", "fits", "hdf5", "idl_save", "netcdf"]
keywords: ["ascii", "binary", "cdf", "csv", "fits", "hdf5", "idl_save", "netcdf"]

- category: "Input Sources"
description: "The ability of a project to access web service data/local data"
Expand All @@ -24,4 +24,4 @@

- category: "Mission"
description: "Observational, including ground and satellite, and also models. TODO."
keywords: ["ace", "adelphi", "amgeo", "arase", "bats_r_us", "cluster", "csswe", "ctipe", "de2", "dmsp", "dscovr", "enlil", "equator_s", "fast", "fermi", "gamera", "geotail", "gitm", "goes", "hermes", "hinode", "icon", "igrf", "image", "iri", "kyoto_dst", "lasco", "madrigal", "maven", "mica", "mms", "omni", "openggcm", "poes", "polar", "proba_2", "psp", "rhessi", "sami2", "sami3", "sdo", "shue", "soho", "solo", "stereo", "superdarn", "swmf", "themis", "tiegcm", "tsyganenko", "twins", "ulysses", "van_allen_probes", "waccmx", "wind"]
keywords: ["ace", "adelphi", "amgeo", "arase", "bats_r_us", "cluster", "csswe", "ctipe", "de2", "dmsp", "dscovr", "enlil", "equator_s", "fast", "fermi", "gamera", "geotail", "gitm", "goes", "hermes", "hinode", "icon", "igrf", "image", "iri", "kyoto_dst", "lasco", "lofar", "madrigal", "maven", "mica", "mms", "omni", "openggcm", "poes", "polar", "proba_2", "psp", "rhessi", "sami2", "sami3", "sdo", "shue", "soho", "solo", "stereo", "superdarn", "swmf", "themis", "tiegcm", "tsyganenko", "twins", "ulysses", "van_allen_probes", "waccmx", "wind"]

0 comments on commit 2c849e7

Please sign in to comment.