Skip to content

Commit

Permalink
Merge pull request #9 from ecmwf-projects/validation
Browse files Browse the repository at this point in the history
add validation script
  • Loading branch information
malmans2 authored Nov 28, 2023
2 parents 20cf7ca + 9b00196 commit 48179bb
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 1 deletion.
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/notebook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ body:
attributes:
label: Task ID
description: Provide the task ID.
placeholder: e.g., 1123e4567-e89b-12d3-a456-426655440000
placeholder: e.g., 1123e4567-e89b-12d3-a456-42665544000
validations:
required: true

Expand Down
30 changes: 30 additions & 0 deletions .github/workflows/on-push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: on-push

on:
push:
branches:
- main
pull_request:
branches:
- main

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

defaults:
run:
shell: bash -l {0}

jobs:
validate-notebook-names:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: 3.x
- name: Validate notebook names
run: |
python scripts/validate_notebook_names.py .
71 changes: 71 additions & 0 deletions scripts/validate_notebook_names.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import argparse
import pathlib
import urllib.request
import uuid

DATA_TYPES = (
"climate",
"insitu",
"reanalysis",
"satellite",
"seasonal",
)

ASSESSMENT_CATEGORIES = (
"climate-and-weather-extremes",
"climate-impact-indicators",
"climate-monitoring",
"consistency-assessment",
"data-completeness",
"forecast-skill",
"intercomparison",
"mean",
"model-performance",
"trend-assessment",
"uncertainty",
"variability",
)

API_URL = "https://cds.climate.copernicus.eu/api/v2"


def main(directory: str):
for path in pathlib.Path(directory).glob("**/*.ipynb"):
assert path.stem.islower(), f"{path=!s}: Invalid {path.name=}"

segments = path.stem.split("_")
assert len(segments) == 5, f"{path=!s}: Invalid {path.name=}"
(
data_type,
dataset_id,
assessment_category,
question_number,
task_id,
) = segments

assert data_type in DATA_TYPES, f"{path=!s}: Invalid {data_type=}"

url = f"{API_URL}/resources/dataset/{dataset_id}"
assert (
urllib.request.urlopen(url).getcode() == 200
), f"{path=!s}: Invalid {dataset_id=}"

assert (
assessment_category in ASSESSMENT_CATEGORIES
), f"{path=!s}: Invalid {assessment_category=}."

assert len(question_number) == 3, f"{path=!s}: Invalid {question_number=}"
assert question_number[0] == "q", f"{path=!s}: Invalid {question_number=}"
assert question_number[1:].isdigit(), f"{path=!s}: Invalid {question_number=}"

try:
uuid.UUID(task_id)
except ValueError:
raise ValueError(f"{path=!s}: Invalid {task_id=}")


if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument("directory", type=str)
args = parser.parse_args()
main(args.directory)

0 comments on commit 48179bb

Please sign in to comment.