Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate examples in CI on the fly #58

Merged
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 13 additions & 7 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
25 changes: 25 additions & 0 deletions developer/get_examples.py
Original file line number Diff line number Diff line change
@@ -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())
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