From 61dde1ea43c9799cbe80bb2e6325000ac163bdc2 Mon Sep 17 00:00:00 2001 From: Daniel Santillan Date: Tue, 13 Feb 2024 13:39:00 +0100 Subject: [PATCH] Implementation of specifying collections to be tested in pull request 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 --- .github/workflows/build_pull_request.yaml | 18 +++++++++-- generators/generate_indicators.py | 37 ++++++++++++++++++++--- 2 files changed, 49 insertions(+), 6 deletions(-) diff --git a/.github/workflows/build_pull_request.yaml b/.github/workflows/build_pull_request.yaml index 92a7d0f9..9b4d0e04 100644 --- a/.github/workflows/build_pull_request.yaml +++ b/.github/workflows/build_pull_request.yaml @@ -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 @@ -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/s3-sync-action@v0.5.1 diff --git a/generators/generate_indicators.py b/generators/generate_indicators.py index 3edc5f75..7d3e1b37 100644 --- a/generators/generate_indicators.py +++ b/generators/generate_indicators.py @@ -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() @@ -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}")