Skip to content
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
60 changes: 60 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
name: Test Build

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]

jobs:
test-mkdocs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.12'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

- name: Test build MkDocs site
run: mkdocs build --strict --verbose

test-b2input:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v7

- name: Set up Python
uses: actions/setup-python@v7
with:
python-version: '3.12'
cache: 'pip'

- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt

# Note: Testing the same command as in .readthedocs.yaml
- name: Test fetch b2input.xml files
run: python extras/b2input/fetch_b2input_xml_files.py
--verbose
--dest-dir extras/b2input/fetched
extras/b2input/versions.yaml

# Note: Testing the same command as in .readthedocs.yaml
- name: Test generate b2input viewer HTML pages
run: python extras/b2input/generate_html.py
--verbose
--source-dir extras/b2input
--dest-dir docs/extras/b2input
extras/b2input/fetched
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
builds
public
docs/extras
extras/b2input/fetched

/venv
__pycache__/
Expand Down
26 changes: 26 additions & 0 deletions .readthedocs.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
version: 2

build:
os: ubuntu-24.04
tools:
python: "3.12"
jobs:
pre_build:
# Generating b2input.xml viewer webpages
- python extras/b2input/fetch_b2input_xml_files.py
--verbose
--dest-dir extras/b2input/fetched
extras/b2input/versions.yaml
- python extras/b2input/generate_html.py
--verbose
--source-dir extras/b2input
--dest-dir docs/extras/b2input
extras/b2input/fetched


mkdocs:
configuration: mkdocs.yml

python:
install:
- requirements: requirements.txt
2 changes: 1 addition & 1 deletion extras/b2input/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ python generate_html.py -d "./public" /path/to/solps-iter/modules/B2.5/src/docum

### Advanced usage (in CI pipeline)

There is a second script, which can download the `b2input.xml` files for one or more SOLPS-ITER versions directly from its git repository. Requires a `versions.yaml` file analogous to the one found in this repository and a read-access token, see [https://git.iter.org/account](https://git.iter.org/account) -> HTTP access tokens.
There is a second script, which can download the `b2input.xml` files for one or more SOLPS-ITER versions directly from its git repository. Requires a `versions.yaml` file analogous to the one found in this repository.

```bash
python fetch_b2input_xml_files.py --help
Expand Down
77 changes: 18 additions & 59 deletions extras/b2input/fetch_b2input_xml_files.py
Original file line number Diff line number Diff line change
@@ -1,61 +1,38 @@
"""
Fetch b2input.xml files (and xhtml-symbol.ent) from different versions
of the B2.5 repository hosted on https://git.iter.org.
of the B2.5 repository hosted on https://github.com/iterorganization/.

Usage:

export GIT_ITER_USER="username"
export GIT_ITER_TOKEN="some_secret_token"
python fetch_b2input_xml_files.py ./versions.yaml -d ./fetched

"""
import argparse
import logging
import os
import shutil
import subprocess
import tempfile
import urllib.request
from pathlib import Path

import yaml

logger = logging.getLogger()


def fetch_b25_repo_file(git_user, git_token, ref, src, dest):
def fetch_b25_repo_file(ref, src, dest):
"""Fetch B2.5 repository and copy a file from it."""
if not shutil.which('git'):
raise RuntimeError('Command `git` not found, please install git')
repourl = f'https://{git_user}:{git_token}@git.iter.org/scm/bnd/b2.5.git'

# Remove the prefix if ref is specified using the full git ref name
if ref.startswith('refs/'):
for prefix in ('refs/heads/', 'refs/tags/'):
if ref.startswith(prefix):
ref = ref.removeprefix(prefix)
break
else:
raise RuntimeError(f'Unsupported ref "{ref}", expected "refs/heads/..." or "refs/tags/..."')

with tempfile.TemporaryDirectory(prefix='b2.5_') as tmpdir:
repodir = Path(tmpdir, ref.replace('/', '_'))
result = subprocess.run(
['git', 'clone', '--depth', '1', '--branch', ref, repourl, str(repodir)],
# stdout=subprocess.DEVNULL,
# stderr=subprocess.DEVNULL,
)
if result.returncode != 0:
raise RuntimeError(
f'Failed to clone the B2.5 repository at ref "{ref}", return code={result.returncode},'
+ ' possibly a token authentication issue or invalid branch/tag name'
)
if not (repodir / src).exists():
raise RuntimeError(f'File "{src}" not found in the B2.5 repository at ref "{ref}"')
with open(dest, 'wb') as f:
f.write((repodir / src).read_bytes())


def fetch_all_versions(git_user, git_token, versions_yaml, dest_dir):
if not any(ref.startswith(prefix) for prefix in ('refs/heads/', 'refs/tags/')):
raise RuntimeError(f'Unsupported ref "{ref}", expected "refs/heads/..." or "refs/tags/..."')

fileurl = f'https://github.com/iterorganization/B2.5/raw/{ref}/{src}'
try:
urllib.request.urlretrieve(fileurl, dest)
except urllib.error.HTTPError as e:
raise RuntimeError(f'Failed to fetch file from {fileurl}: {e}') from e


def fetch_all_versions(versions_yaml, dest_dir):
if not Path(dest_dir).exists():
Path(dest_dir).mkdir(exist_ok=True, parents=True)

Expand All @@ -66,31 +43,27 @@ def fetch_all_versions(git_user, git_token, versions_yaml, dest_dir):
git_ref = config['xhtml_symbol']['git_ref']
path = Path(dest_dir, 'xhtml-symbol.ent')
logger.info(f'Downloading xhtml-symbol.ent at ref "{git_ref}" to "{path}"')
fetch_b25_repo_file(git_user, git_token, git_ref, 'src/documentation/xhtml-symbol.ent', path)
fetch_b25_repo_file(git_ref, 'src/documentation/xhtml-symbol.ent', path)

for item in config['versions']:
git_ref = item['git_ref']
path = Path(dest_dir, f'b2input.xml.{item["label"]}')
logger.info(f'Downloading b2input.xml at ref "{git_ref}" to "{path}"')
if ' ' in item['label']:
raise ValueError(f'Version label "{item["label"]}" contains a space')
fetch_b25_repo_file(git_user, git_token, git_ref, 'src/documentation/b2input.xml', path)
fetch_b25_repo_file(git_ref, 'src/documentation/b2input.xml', path)


parser = argparse.ArgumentParser()
parser.add_argument('versions_yaml', metavar='PATH_VERSIONS_YAML', help=(
'path to a "versions.yaml" file containing the list of git refs in the B2.5',
' repository and corresponding labels for the webpage, see the "versions.yaml"',
'path to a "versions.yaml" file containing the list of git refs in the B2.5'
' repository and corresponding labels for the webpage, see the "versions.yaml"'
' file in this repo for more information'
))
parser.add_argument('-d', '--dest-dir', default='.', help=(
'destination directory for the fetched files, will be created if it'
' does not exist, default="."'
))
parser.add_argument('-a', '--auth', default=None, help=(
'username and access token in format "user:token" with read-only access to git.iter.org,'
' will attempt to read it from the GIT_ITER_USER and GIT_ITER_TOKEN env vars if this parameter is not specified'
))
parser.add_argument('-v', '--verbose', action='store_true', help=(
'print logging output'
))
Expand All @@ -103,21 +76,7 @@ def fetch_all_versions(git_user, git_token, versions_yaml, dest_dir):
else:
pass

if args.auth is not None:
try:
git_user, git_token = args.auth.split(':')
except ValueError:
raise RuntimeError('Invalid auth format, expected "user:token"')
elif 'GIT_ITER_USER' in os.environ and 'GIT_ITER_TOKEN' in os.environ:
git_user = os.environ['GIT_ITER_USER']
git_token = os.environ['GIT_ITER_TOKEN']
else:
raise RuntimeError(
'If auth credentials are not provided (--token), GIT_ITER_USER and GIT_ITER_TOKEN env vars must be set')

fetch_all_versions(
git_user=git_user,
git_token=git_token,
versions_yaml=args.versions_yaml,
dest_dir=args.dest_dir,
)
4 changes: 2 additions & 2 deletions extras/b2input/src_html/index_toplevel_template.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@
{% block content %}
<div style="margin-top: 3rem;"></div>

<div class="ui icon message">
<div class="ui icon orange message">
<i class="calendar check outline icon"></i>
<div class="content">
<div class="header">
Last updated on {{ current_date.strftime('%Y-%m-%d') }}
</div>
<p>Kept up-to-date via automated gitlab pipeline.</p>
<!-- <p>Kept up-to-date via automated gitlab pipeline.</p> -->
</div>
</div>

Expand Down
16 changes: 9 additions & 7 deletions extras/b2input/versions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

versions:
- git_ref: refs/heads/develop
label: 3.0.9@develop
- git_ref: refs/heads/release/3.1.1
label: 3.1.1
- git_ref: refs/heads/feature/wg_workflow
label: 3.2.0@wg_workflow
- git_ref: refs/tags/3.0.8
label: 3.0.8@old
label: develop
- git_ref: refs/tags/3.0.10a
label: 3.0.10a
- git_ref: refs/tags/3.1.2a
label: 3.1.2a
- git_ref: refs/tags/3.2.1a
label: WG-3.2.1a
- git_ref: refs/heads/feature/wg-release
label: WG-3.2.0@wg_release

# The `xhtml-symbol.ent` file is not really changed often, thus we assume
# that it's ok to pick one recent version and share it for all `b2input.xml` versions.
Expand Down