Skip to content

Commit 272f996

Browse files
authored
19 extend the ci to the other repo of the organization (#23)
* feat: made the github action generic for more than one repositories
1 parent 62ec6db commit 272f996

9 files changed

Lines changed: 476 additions & 38 deletions

File tree

.github/workflows/ci.yaml

Lines changed: 60 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ jobs:
4040
with:
4141
ssh-private-key: ${{ secrets.PRIVATE_SSH_KEY }}
4242

43-
- name: Clone private repo
44-
run: |
45-
ssh-keyscan -H github.com >> /root/.ssh/known_hosts
46-
git clone git@github.com:ubm-driverless/ubm-f1tenth.git
47-
4843
- name: Cache pip dependencies
4944
uses: actions/cache@v3
5045
with:
@@ -56,8 +51,53 @@ jobs:
5651
- name: Install tools
5752
run: |
5853
mkdir -p .pip-cache
59-
pip install --cache-dir .pip-cache --upgrade pip
60-
pip install --cache-dir .pip-cache -r requirements.txt
54+
python3 -m pip install --cache-dir .pip-cache --upgrade pip
55+
python3 -m pip install --cache-dir .pip-cache -r requirements.txt
56+
57+
- name: Clone configured repos
58+
env:
59+
ORG_READ_TOKEN: ${{ secrets.ACTION_TOKEN }}
60+
run: |
61+
mkdir -p /root/.ssh
62+
ssh-keyscan -H github.com >> /root/.ssh/known_hosts
63+
python3 - <<'PY'
64+
from pathlib import Path
65+
import os
66+
import subprocess
67+
68+
import yaml
69+
70+
config_path = Path("repositories.yaml")
71+
config = yaml.safe_load(config_path.read_text()) or {}
72+
repositories = config.get("repositories", [])
73+
74+
if not repositories:
75+
raise SystemExit("No repositories configured in repositories.yaml")
76+
77+
repos_root = Path("repos")
78+
repos_root.mkdir(exist_ok=True)
79+
80+
for repository in repositories:
81+
owner = repository.get("owner", "ubm-driverless")
82+
name = repository["name"]
83+
ref = repository.get("ref")
84+
target = repos_root / name
85+
token = os.environ.get("ORG_READ_TOKEN", "").strip()
86+
if token:
87+
remote = f"https://x-access-token:{token}@github.com/{owner}/{name}.git"
88+
else:
89+
remote = f"git@github.com:{owner}/{name}.git"
90+
91+
clone = subprocess.run(["git", "clone", remote, str(target)], check=False)
92+
if clone.returncode != 0:
93+
print(f"[WARN] Could not clone {owner}/{name}. Skipping this repository.")
94+
continue
95+
96+
if ref:
97+
checkout = subprocess.run(["git", "-C", str(target), "checkout", ref], check=False)
98+
if checkout.returncode != 0:
99+
print(f"[WARN] Ref '{ref}' not found for {owner}/{name}. Using repository default branch.")
100+
PY
61101
62102
- name: Generate docs
63103
id: generate_docs
@@ -70,35 +110,33 @@ jobs:
70110
# Configurable Paths (mkdocs.yml needs to be updated accordingly)
71111
ROSDOC2_OUTPUT="./rosdoc2_generated"
72112
SRC_FOLDER="./src"
113+
REPOS_ROOT="./repos"
73114
mkdir -p "$ROSDOC2_OUTPUT" "$SRC_FOLDER"
74-
CPP_PACKAGES_MD="./docs/CPP_PACKAGES.md"
75115
echo "rosdoc2_output=$ROSDOC2_OUTPUT" >> $GITHUB_OUTPUT
76116
77117
# Build C++ packages docs with rosdoc2
78118
echo "Building docs of C++ packages..."
79119
source /home/ubm/rosdoc2/bin/activate
80120
# rosdoc2 pulls sphinx which requires docutils < 0.22.
81-
python -m pip install "docutils>=0.20,<0.22"
121+
python3 -m pip install "docutils>=0.20,<0.22"
82122
source /opt/ros/foxy/setup.bash
83-
echo "# C++ Packages" > "$CPP_PACKAGES_MD"
84-
echo "" >> "$CPP_PACKAGES_MD"
85-
for f in $(find ./ubm-f1tenth -type f -iname "package.xml"); do
123+
find "$REPOS_ROOT" -type f -iname "package.xml" -print0 | while IFS= read -r -d '' f; do
86124
package_dir="${f%/package.xml}"
125+
repo_dir="${package_dir#${REPOS_ROOT}/}"
126+
repo_name="${repo_dir%%/*}"
87127
package_name="${package_dir##*/}"
88-
package_doc_path="$ROSDOC2_OUTPUT/$package_name/index.html"
89128
if grep -q "rosdoc2" "$f"; then
90-
echo "Building $package_name with rosdoc2"
91-
rosdoc2 build -p "$package_dir" -o "$ROSDOC2_OUTPUT/"
92-
if [ -f "$package_doc_path" ]; then
93-
echo "- [$package_name](../$ROSDOC2_OUTPUT/$package_name/)" >> "$CPP_PACKAGES_MD"
129+
echo "Building $repo_name/$package_name with rosdoc2"
130+
if ! rosdoc2 build -p "$package_dir" -o "$ROSDOC2_OUTPUT/$repo_name/"; then
131+
echo "[WARN] rosdoc2 failed for $repo_name/$package_name. Skipping package."
94132
fi
95133
fi
96134
done
97135
deactivate
98136
99137
# Preparing Python packages for mkdocs
100138
echo "Preparing Python packages for mkdocs..."
101-
for f in $(find ./ubm-f1tenth -type f -iname "package.xml"); do
139+
find "$REPOS_ROOT" -type f -iname "package.xml" -print0 | while IFS= read -r -d '' f; do
102140
package_dir="${f%/package.xml}"
103141
package_name="${package_dir##*/}"
104142
if grep -q "ament_python" "$f"; then
@@ -107,6 +145,10 @@ jobs:
107145
fi
108146
done
109147
148+
- name: Generate repository pages
149+
run: |
150+
python3 scripts/gen_repository_pages.py
151+
110152
- name: Build documentation
111153
run: |
112154
export PYTHONPATH="$PYTHONPATH:$(pwd)/src"

.gitignore

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,8 @@ site/
22
src/
33
venv/
44
.venv/
5-
.vscode/
5+
.vscode/
6+
repos/
7+
cross_reference/
8+
docs_build/
9+
rosdoc2_generated/

docs/guides/ADD_DOCUMENTATION.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,23 +38,54 @@ To contribute new documentation to the website, follow these steps:
3838
python -m venv venv
3939
```
4040
41-
2. Enable the virtual environment (for bash shell)
41+
2. Enable the virtual environment
4242
4343
```bash
4444
source ./venv/bin/activate
4545
```
46+
47+
Windows PowerShell:
48+
49+
```powershell
50+
.\venv\Scripts\Activate.ps1
51+
```
52+
53+
Windows cmd:
54+
55+
```bat
56+
venv\Scripts\activate.bat
57+
```
4658
4759
4. Install the requirements.
4860
4961
```bash
5062
pip install -r requirements.txt
5163
```
5264
53-
3. Modify the `PYTHONPATH` environment variable for the current terminal session and serve locally the website with mkdocs
65+
3. Run the local helper script to prepare generated docs content and start the preview
66+
67+
```bash
68+
python scripts/local_docs.py serve
69+
```
70+
71+
4. (Optional) Generate a static build locally
72+
73+
```bash
74+
python scripts/local_docs.py build
75+
```
76+
77+
5. (Optional) Generate C++ rosdoc2 output locally and include it in the static site
78+
79+
```bash
80+
python scripts/local_docs.py build-cpp
81+
```
82+
83+
Note: this command requires Docker Desktop (or another running Docker daemon).
84+
85+
6. (Optional) Serve the built static site including rosdoc2 output (recommended to test C++ links)
5486
5587
```bash
56-
export PYTHONPATH="$PYTHONPATH:$(pwd)/src"
57-
python3 -m mkdocs serve
88+
python scripts/local_docs.py serve-cpp
5889
```
5990
6091
!!! tip

docs/setup/DOCS_GENERATION.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
## Introduction
44

5-
This guide explains how documentation generation is configured and works in the `ubm-f1tenth` repository.
5+
This guide explains how documentation generation is configured and works across the repositories listed in `repositories.yaml`.
66

77
## Overview
88

@@ -16,29 +16,35 @@ The whole process is automatized with the use of GitHub Actions.
1616

1717
### Deployment with GitHub Actions
1818

19-
The CI/CD workflow automates the process of building and deploying documentation to GitHub Pages. The key steps in `.github/workflows/ci.yml` are:
19+
The CI/CD workflow automates the process of building and deploying documentation to GitHub Pages. The key steps in `.github/workflows/ci.yaml` are:
2020

21-
1. **Clone ubm-f1tenth Repository**
21+
1. **Clone configured repositories**
22+
- The workflow reads `repositories.yaml` and clones each listed repository into `./repos/`.
23+
- Add or remove repositories from that file to control which repositories are documented.
2224

23-
2. **Generate C++ Documentation**:
24-
- Uses rosdoc2 to generate documentation for C++ packages found in the repository.
25-
- The script searches for package.xml files in the ubm-f1tenth directory and identifies packages that use rosdoc2.
26-
- For each identified package, it runs rosdoc2 build to generate HTML documentation, which is stored in a specified output directory.
27-
- A markdown file (CPP_PACKAGES.md) is created listing the packages with links to their generated documentation.
25+
2. **Generate repository pages**:
26+
- `scripts/gen_repository_pages.py` creates a page for each repository listed in `repositories.yaml`.
27+
- Each repository page contains two subsections: one for Python packages and one for C++ packages.
28+
- The C++ subsection links to the rosdoc2 output generated for that repository.
2829

29-
3. **Move Python packages to src**:
30-
- Copies Python packages found within the repository into the `src/` folder to prepare them for MkDocs documentation generation. This is done by checking for the presence of ament_python in each package.xml file.
30+
3. **Generate C++ Documentation**:
31+
- Uses rosdoc2 to generate documentation for C++ packages found in the configured repositories.
32+
- The script searches for package.xml files under `./repos/` and identifies packages that use rosdoc2.
33+
- For each identified package, it runs rosdoc2 build to generate HTML documentation, which is stored under a repository-specific output directory.
3134

32-
4. **Build Documentation**:
35+
4. **Move Python packages to src**:
36+
- Copies Python packages found within the configured repositories into the `src/` folder to prepare them for MkDocs documentation generation. This is done by checking for the presence of ament_python in each package.xml file.
37+
38+
5. **Build Documentation**:
3339
- Runs MkDocs to generate static documentation from the source files.
3440
- All the configs are set in the `mkdocs.yaml` file.
3541
- `mkdocs build` clears the content of the `site/` directory, builds the content inside the `docs/` directory and processes with mkdocstrings the source code present in `src/` directory. The output will be in the `site` directory.
3642
- Custom navigation is generated dynamically based on Python module structure by the `gen_ref_pages.py` present in the script/ folder.
3743

38-
5. **Add Additional Files to Site**:
44+
6. **Add Additional Files to Site**:
3945
- Copies the generated C++ documentation to the `site` directory for deployment.
4046

41-
6. **Deploy with ghp-import**:
47+
7. **Deploy with ghp-import**:
4248
- Deploys the content of `site/` to GitHub Pages using the `ghp-import` tool.
4349

4450
!!! danger

mkdocs.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@ site_url: https://ubm-driverless.github.io/ubm-docs/
99
nav:
1010
- Setup: setup/
1111
- Guides: guides/
12-
- Python Packages: PYTHON_PACKAGES/
13-
- C++ Packages: CPP_PACKAGES/
12+
- Repositories: repositories.md
1413
# - NAME_OF_THE_SECTION: FOLDER_NAME_INSIDE_DOCS/ # To set up another entry
1514

1615

@@ -50,6 +49,7 @@ plugins:
5049
- gen-files:
5150
scripts:
5251
- scripts/gen_ref_pages.py
52+
- scripts/gen_repository_pages.py
5353
- literate-nav:
5454
nav_file: SUMMARY.md
5555
- section-index

repositories.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
repositories:
2+
- owner: ubm-driverless
3+
name: ubm-f1tenth
4+
ref: main
5+
- owner: ubm-driverless
6+
name: ubm-fsae
7+
ref: main

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ mkdocs-section-index
77
mkdocs-github-admonitions-plugin
88
mkdocs-site-urls
99
ghp-import
10+
PyYAML

0 commit comments

Comments
 (0)