From 5253915c09ddd3e7b713aa4820229facbfeacb3c Mon Sep 17 00:00:00 2001 From: Philip Loche Date: Mon, 8 Apr 2024 10:48:24 +0200 Subject: [PATCH] generate examples in ci on the fly --- .github/workflows/docs.yml | 20 +++++++++++++------- developer/get_examples.py | 25 +++++++++++++++++++++++++ noxfile.py | 13 +++++++++---- 3 files changed, 47 insertions(+), 11 deletions(-) create mode 100755 developer/get_examples.py diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 7db59205..b3f206e9 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -10,17 +10,23 @@ on: - cron: '0 8 * * 1' # run every Monday at 8am UTC jobs: + setup: + runs-on: ubuntu-latest + outputs: + examplesmatrix: ${{ steps.collectExamples.outputs.examplesjson }} + steps: + - uses: actions/checkout@v4 + + - id: collectExamples + run: | + echo examplesjson=$(./developer/get_examples.py) >> $GITHUB_OUTPUT + generate-example: + needs: setup runs-on: ubuntu-latest strategy: matrix: - example-name: - - lode-linear - - roy-gch - - sample-selection - - gaas-map - - batch-cp2k - - lpr + ${{ fromJson(needs.setup.outputs.examplesmatrix) }} steps: - uses: actions/checkout@v4 diff --git a/developer/get_examples.py b/developer/get_examples.py new file mode 100755 index 00000000..8b65ba8d --- /dev/null +++ b/developer/get_examples.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 +"""Script to create JSON string suitable for a github action matrix.""" +import glob +import json +import os + + +ROOT = os.path.realpath(os.path.join(os.path.dirname(__file__), "..")) +EXAMPLES = os.path.join(ROOT, "examples") + + +def get_examples(): + """The current list of examples, determined from the directories on disk""" + return [ + os.path.basename(os.path.normpath(file)) for file in glob.glob(f"{EXAMPLES}/*") + ] + + +def create_json(): + """A JSON string suitable for a github action matrix.""" + return json.dumps({"example-name": get_examples()}) + + +if __name__ == "__main__": + print(create_json()) diff --git a/noxfile.py b/noxfile.py index a6779de4..241daf79 100644 --- a/noxfile.py +++ b/noxfile.py @@ -2,10 +2,17 @@ import hashlib import json import os +import sys import nox +ROOT = os.path.realpath(os.path.dirname(__file__)) + +sys.path.append(ROOT) +from developer.get_examples import get_examples # noqa: E402 + + # global nox options nox.needs_version = ">=2024" nox.options.reuse_venv = "yes" @@ -19,12 +26,10 @@ "noxfile.py", "docs/src/conf.py", "examples", + "developer", ] -# the current list of examples, determined from the directories on disk -EXAMPLES = [ - os.path.basename(os.path.normpath(file)) for file in glob.glob("examples/*/") -] +EXAMPLES = get_examples() # ==================================================================================== # # helper functions #