diff --git a/.github/workflows/pages.yml b/.github/workflows/pages.yml index 45ec580c..72a9f20c 100644 --- a/.github/workflows/pages.yml +++ b/.github/workflows/pages.yml @@ -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: @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 00000000..71ce8236 --- /dev/null +++ b/.github/workflows/tests.yml @@ -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 + + diff --git a/stac/stac-generator/requirements.txt b/stac/stac-generator/requirements.txt index ae6c237e..0db26ed8 100644 --- a/stac/stac-generator/requirements.txt +++ b/stac/stac-generator/requirements.txt @@ -1,4 +1,5 @@ pystac +pytest gql shapely stactools diff --git a/stac/stac-generator/test/valdator.py b/stac/stac-generator/test/valdator.py new file mode 100644 index 00000000..a075831a --- /dev/null +++ b/stac/stac-generator/test/valdator.py @@ -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 \ No newline at end of file