Skip to content

Commit

Permalink
add validation a job
Browse files Browse the repository at this point in the history
  • Loading branch information
baloola committed Apr 30, 2024
1 parent bdb6cb2 commit c6bc3fa
Show file tree
Hide file tree
Showing 4 changed files with 88 additions and 18 deletions.
23 changes: 5 additions & 18 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
name: Deploy static content to Pages

on:
# Runs on pushes targeting the default branch
push:
branches:
- main
workflow_run:
workflows: ["tests"]
branches: [main]
types:
- completed

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
Expand Down Expand Up @@ -43,18 +44,4 @@ jobs:
run: |
python3 ./stac/stac-generator/stac-generator.py
stac copy -t ABSOLUTE_PUBLISHED --publish-location "https://fairicube.github.io/data-requests" stac_dist/catalog.json out
- name: Upload artifact
uses: actions/upload-pages-artifact@v1
with:
# Upload entire repository
path: './out'
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v2
- name: Update items
env:
USERNAME: ${{ secrets.USERNAME }}
PASSWORD: ${{ secrets.PASSWORD }}
run: |
python3 ./stac/stac-generator/update_items.py
25 changes: 25 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: Validate generated stac item in the PR

on:
pull_request:
branches:
- main

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
- name: install dependencies
run: |
pip install -r ./stac/stac-generator/requirements.txt
- name: validate stac items

run: |
python3 ./stac/stac-generator/test/validator.py
1 change: 1 addition & 0 deletions stac/stac-generator/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
pystac
pytest
gql
shapely
stactools
Expand Down
57 changes: 57 additions & 0 deletions stac/stac-generator/test/valdator.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import pystac
import pytest
import os
from typing import Any


def validate_item(item: pystac.item.Item):
properties: dict[str, Any] = item.properties

# validate ID
assert isinstance(item.id, str)

assert len(item.id) > 0

# validate Description
assert "description" in properties.keys()

# assert isinstance(properties["description"], str)
# assert len(properties["description"]) > 0


@pytest.mark.parametrize("dir", [
os.path.join('stac_dist', f) for f in os.listdir(
os.path.join('stac_dist')) if os.path.isdir(os.path.join('stac_dist', f))])
def test_items(dir):

items = [
f for f in os.listdir(dir) if not f.endswith(
'catalog.json') and f.endswith('.json')]

for item in items:
stac_item = pystac.Item.from_file(os.path.join(dir, item))
validate_item(stac_item)

# Mandatory Columns (additions in bold)
# ID [Column C]
# Description [D]
# Data Source [Column E]
# Owner/Organisation [G]
# Horizontal
# Horizontal CRS [Column P]
# Bounding Box (Horizontal) [Column Q-T]
# Resolution of Horizontal Axis (ie. Pixel Size) [Column W]
# Units of Measurement [Column U]
# Temporal
# Time (Begin/End) [Column AD-AE]
# Resolution of Time Axis (Intervall) [Column AH]
# Unit of measure [Column AF]
# Range Data Type [Column AR]
# Range Definition [AS]
# Range Description [AT]
# Null values [Column AQ]
# Legal - License [BA]
# Keywords - Keywords [BJ]
# In addition, some fields can be filled with defaults, e.g.
# Metadata Standard: STAC
# Provision Date: Date being provided

0 comments on commit c6bc3fa

Please sign in to comment.