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
4 changes: 3 additions & 1 deletion plugin-template
Original file line number Diff line number Diff line change
Expand Up @@ -335,14 +335,16 @@ def write_template_section(config, name, plugin_root_dir, verbose=False):
files_templated = 0
files_copied = 0

PULPDOCS_BRANCH = "rewrite-as-mkdocs-plugin"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So this is where we switch them all in one go, not one after another...

template_vars = {
"section": name,
"setup_py": (plugin_root_path / "setup.py").exists(),
"ci_update_branches": utils.ci_update_branches(config),
"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,
}

Expand Down
16 changes: 7 additions & 9 deletions templates/github/.github/workflows/docs.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,28 @@
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:
run:
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 }}')"
Expand Down
2 changes: 1 addition & 1 deletion templates/github/doc_requirements.txt.j2
Original file line number Diff line number Diff line change
@@ -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 }}
44 changes: 35 additions & 9 deletions utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -93,28 +93,54 @@ 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.

Raises if can't get the authoritative file.
"""
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(
"There was an error getting 'repolist.yml' from from pulp-docs repository."
"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
Expand Down