diff --git a/plugin-template b/plugin-template index 943e6693..130040fe 100755 --- a/plugin-template +++ b/plugin-template @@ -335,6 +335,7 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): files_templated = 0 files_copied = 0 + PULPDOCS_BRANCH = "rewrite-as-mkdocs-plugin" template_vars = { "section": name, "setup_py": (plugin_root_path / "setup.py").exists(), @@ -342,7 +343,8 @@ def write_template_section(config, name, plugin_root_dir, verbose=False): "python_version": "3.11", "ci_update_hour": sum((ord(c) for c in config["plugin_app_label"])) % 24, "current_version": utils.current_version(plugin_root_path), - "is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(), + "pulpdocs_branch": PULPDOCS_BRANCH, + "is_pulpdocs_member": config["plugin_name"] in utils.get_pulpdocs_members(PULPDOCS_BRANCH), **config, } diff --git a/templates/github/.github/workflows/docs.yml.j2 b/templates/github/.github/workflows/docs.yml.j2 index ac0e19fd..b72501e2 100644 --- a/templates/github/.github/workflows/docs.yml.j2 +++ b/templates/github/.github/workflows/docs.yml.j2 @@ -5,12 +5,12 @@ install_python_deps, with context %} --- -name: "Docs" +name: "Docs CI" on: workflow_call: jobs: - test: + changelog: if: "endsWith(github.base_ref, '{{ plugin_default_branch }}')" runs-on: "ubuntu-latest" defaults: @@ -18,17 +18,15 @@ jobs: working-directory: "{{ plugin_name }}" steps: {{ checkout(depth=1, path=plugin_name) | indent(6) }} - {{ checkout(depth=0, repository="pulp/pulp-docs", path="pulp-docs", ref="rewrite-as-mkdocs-plugin") | indent(6) }} {{ setup_python(pyversion="3.12") | indent(6) }} - {{ install_python_deps(["../pulp-docs", "towncrier"]) | indent(6) }} + {{ install_python_deps(["towncrier"]) | indent(6) }} - name: "Build changelog" run: | towncrier build --yes --version 4.0.0.ci - - name: "Build docs" - working-directory: "pulp-docs" - run: | - pulp-docs fetch --dest .. - pulp-docs build + docs: + uses: 'pulp/pulp-docs/.github/workflows/docs-ci.yml@{{ pulpdocs_branch }}' + with: + pulpdocs_ref: '{{ pulpdocs_branch }}' no-test: if: "!endsWith(github.base_ref, '{{ plugin_default_branch }}')" diff --git a/templates/github/doc_requirements.txt.j2 b/templates/github/doc_requirements.txt.j2 index c97fe2f7..99d6a475 100644 --- a/templates/github/doc_requirements.txt.j2 +++ b/templates/github/doc_requirements.txt.j2 @@ -1,3 +1,3 @@ {% include 'header.j2' %} towncrier -pulp-docs @ git+https://github.com/pulp/pulp-docs@main +pulp-docs @ git+https://github.com/pulp/pulp-docs@{{ pulpdocs_branch }} diff --git a/utils.py b/utils.py index f21f359c..18b7dfac 100644 --- a/utils.py +++ b/utils.py @@ -1,8 +1,8 @@ from datetime import timedelta -import itertools import re import requests_cache import stat +import textwrap import tomlkit import tomllib import yaml @@ -93,7 +93,7 @@ def current_version(plugin_root_path): return current_version -def get_pulpdocs_members() -> list[str]: +def get_pulpdocs_members(pulpdocs_branch="main") -> list[str]: """ Get repositories which are members of the Pulp managed documentation. @@ -101,7 +101,7 @@ def get_pulpdocs_members() -> list[str]: """ session = requests_cache.CachedSession(".requests_cache", expire_after=timedelta(days=1)) response = session.get( - "https://raw.githubusercontent.com/pulp/pulp-docs/main/src/pulp_docs/data/repolist.yml" + f"https://raw.githubusercontent.com/pulp/pulp-docs/{pulpdocs_branch}/mkdocs.yml" ) if response.status_code != 200: raise ValueError( @@ -109,12 +109,38 @@ def get_pulpdocs_members() -> list[str]: "This mean we can't know if we should manage the doc-related workflows." ) - repolist = yaml.safe_load(response.content.decode()) - return [ - repo["name"] - for repo in itertools.chain(*repolist["repos"].values()) - if "subpackage_of" not in repo - ] + class IgnoreTags(yaml.SafeLoader): + pass + + IgnoreTags.add_multi_constructor("tag", lambda *a, **kw: None) + mkdocs_config = yaml.load(response.content.decode(), Loader=IgnoreTags) + repository_members = set() + try: + found = False + for plugin in mkdocs_config["plugins"]: + if "PulpDocs" in plugin: + found = True + for component in plugin["PulpDocs"]["components"]: + repository = component["path"].split("/")[0] + repository_members.add(repository) + break + if not found: + raise KeyError("PulpDocs plugin not found") + except KeyError: + EXPECTED = """ + plugins: + - PulpDocs: + components: + - title: "Pulpcore" + path: "pulpcore" + git_url: "https://github.com/pulp/pulpcore" + kind: "Core" + rest_api: "core" + - ... + """ + raise ValueError(f"Expected mkdocs.yml with structure:\n{textwrap.dedent(EXPECTED)}") + + return list(repository_members) # Utilities for templating