Skip to content

Commit

Permalink
Implementation of specifying collections to be tested in pull request…
Browse files Browse the repository at this point in the history
… body (#92)

* feat: added parameter for collections to be build; testing possibility to define them in pull request

* fix: added missing quotes

* feat: added check for empty body to throw error

* chore: moved check to start of workflow to run first saving time
  • Loading branch information
santilland authored Feb 13, 2024
1 parent f69d7b5 commit 61dde1e
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 6 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/build_pull_request.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ jobs:
deploy-preview:
runs-on: ubuntu-latest
steps:
- if: github.event.pull_request.body == ''
run: |
echo "::error::Pull request body text can't be empty, please define which collections to test"
exit 1
- name: Checkout
uses: actions/checkout@v3
- name: Setup Pages
Expand All @@ -27,14 +31,24 @@ jobs:
run: |
pip install -U pip
pip install -r generators/requirements.txt
- name: Build
- if: github.event.pull_request.body == 'all'
name: Build all
env:
SH_INSTANCE_ID: ${{ secrets.SH_INSTANCE_ID }}
SH_CLIENT_ID: ${{ secrets.SH_CLIENT_ID }}
SH_CLIENT_SECRET: ${{ secrets.SH_CLIENT_SECRET }}
run: |
cd generators/
python generate_indicators.py
- if: github.event.pull_request.body != 'all'
name: Build only specified collections
env:
SH_INSTANCE_ID: ${{ secrets.SH_INSTANCE_ID }}
SH_CLIENT_ID: ${{ secrets.SH_CLIENT_ID }}
SH_CLIENT_SECRET: ${{ secrets.SH_CLIENT_SECRET }}
run: |
cd generators/
python generate_indicators.py -ni
python generate_indicators.py -c ${{ github.event.pull_request.body }}
# Upload build to S3
- name: sync client s3
uses: jakejarvis/[email protected]
Expand Down
37 changes: 33 additions & 4 deletions generators/generate_indicators.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,28 @@
as possible and generating a STAC catalog with the information''',
)

argparser.add_argument("-vd", action="store_true", help="validation flag, if set, validation will be run on generated catalogs")
argparser.add_argument("-ni", action="store_true", help="no items flag, if set, items will not be saved")
argparser.add_argument("-tn", action="store_true", help="generate additionally thumbnail image for supported collections")
argparser.add_argument(
"-vd",
action="store_true",
help="validation flag, if set, validation will be run on generated catalogs"
)
argparser.add_argument(
"-ni",
action="store_true",
help="no items flag, if set, items will not be saved"
)
argparser.add_argument(
"-tn",
action="store_true",
help="generate additionally thumbnail image for supported collections"
)
argparser.add_argument(
"-c", "--collections",
help="list of collection identifiers to be generated for test build",
nargs='+',
required=False,
default=[]
)

def recursive_save(stac_object, no_items=False):
stac_object.save_object()
Expand All @@ -69,13 +88,23 @@ def process_catalog_file(file_path, options):
print("Processing catalog:", file_path)
with open(file_path) as f:
config = yaml.load(f, Loader=SafeLoader)

if len(options.collections) > 0:
# create only catalogs containing the passed collections
process_collections = [c for c in config["collections"] if c in options.collections]
elif (len(options.collections) == 1 and options.collections == "all") or len(options.collections) == 0:
# create full catalog
process_collections = config["collections"]
if len(process_collections) == 0:
print("No applicable collections found for catalog, skipping creation")
return
catalog = Catalog(
id = config["id"],
description = config["description"],
title = config["title"],
catalog_type=CatalogType.RELATIVE_PUBLISHED,
)
for collection in config["collections"]:
for collection in process_collections:
process_collection_file(config, "../collections/%s.yaml"%(collection), catalog)

strategy = TemplateLayoutStrategy(item_template="${collection}/${year}")
Expand Down

0 comments on commit 61dde1e

Please sign in to comment.