Skip to content

Commit

Permalink
generate examples in ci on the fly
Browse files Browse the repository at this point in the history
  • Loading branch information
PicoCentauri committed Apr 8, 2024
1 parent c2dcd2f commit ed7c294
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 11 deletions.
21 changes: 14 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,24 @@ on:
- cron: '0 8 * * 1' # run every Monday at 8am UTC

jobs:
setup:
runs-on: ubuntu-latest
outputs:
examplesmatrix: ${{ steps.collectExamples.outputs.examples }}
steps:
- uses: actions/checkout@v4

- id: collectExamples
run: |
EXAMPLES=$(./developer/get_examples.py)
echo "examples=$(jq -cn --argjson env "$EXAMPLES" '{example-name: $env}')" >> $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
Expand Down
21 changes: 21 additions & 0 deletions developer/get_examples.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env python3
"""Script to create JSON array useful 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}/*")
]


if __name__ == "__main__":
# no spaces between elements are allowed for using array in bash
print(json.dumps(get_examples(), separators=(',', ':')))
13 changes: 9 additions & 4 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 #
Expand Down

0 comments on commit ed7c294

Please sign in to comment.