ci #84
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Workflow for deploying documentation to GitHub Pages | |
| # **WARNING**: Make sure that code that is not meant to be public is not included in the ./docs folder or ./site folder. | |
| # This workflow will make the content of the ./docs folder and ./site folder public. | |
| name: ci | |
| on: | |
| workflow_dispatch: | |
| push: | |
| branches: | |
| - main | |
| permissions: | |
| contents: write | |
| pages: write | |
| id-token: write | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| defaults: | |
| run: | |
| shell: bash | |
| container: | |
| image: ubmdriverless/f1tenth:latest | |
| credentials: | |
| username: ubmdriverless | |
| password: ${{ secrets.DOCKER_HUB_TOKEN_READ_ONLY }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Setup ssh | |
| uses: webfactory/ssh-agent@v0.9.0 | |
| with: | |
| ssh-private-key: ${{ secrets.PRIVATE_SSH_KEY }} | |
| - name: Cache pip dependencies | |
| uses: actions/cache@v3 | |
| with: | |
| path: .pip-cache | |
| key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} | |
| restore-keys: | | |
| ${{ runner.os }}-pip- | |
| - name: Install tools | |
| run: | | |
| mkdir -p .pip-cache | |
| python3 -m pip install --cache-dir .pip-cache --upgrade pip | |
| python3 -m pip install --cache-dir .pip-cache -r requirements.txt | |
| - name: Clone configured repos | |
| env: | |
| ORG_READ_TOKEN: ${{ secrets.ACTION_TOKEN }} | |
| run: | | |
| mkdir -p /root/.ssh | |
| ssh-keyscan -H github.com >> /root/.ssh/known_hosts | |
| python3 - <<'PY' | |
| from pathlib import Path | |
| import os | |
| import subprocess | |
| import yaml | |
| config_path = Path("repositories.yaml") | |
| config = yaml.safe_load(config_path.read_text()) or {} | |
| repositories = config.get("repositories", []) | |
| if not repositories: | |
| raise SystemExit("No repositories configured in repositories.yaml") | |
| repos_root = Path("repos") | |
| repos_root.mkdir(exist_ok=True) | |
| for repository in repositories: | |
| owner = repository.get("owner", "ubm-driverless") | |
| name = repository["name"] | |
| ref = repository.get("ref") | |
| target = repos_root / name | |
| token = os.environ.get("ORG_READ_TOKEN", "").strip() | |
| if token: | |
| remote = f"https://x-access-token:{token}@github.com/{owner}/{name}.git" | |
| else: | |
| remote = f"git@github.com:{owner}/{name}.git" | |
| clone = subprocess.run(["git", "clone", remote, str(target)], check=False) | |
| if clone.returncode != 0: | |
| print(f"[WARN] Could not clone {owner}/{name}. Skipping this repository.") | |
| continue | |
| if ref: | |
| checkout = subprocess.run(["git", "-C", str(target), "checkout", ref], check=False) | |
| if checkout.returncode != 0: | |
| print(f"[WARN] Ref '{ref}' not found for {owner}/{name}. Using repository default branch.") | |
| PY | |
| - name: Generate docs | |
| id: generate_docs | |
| run: | | |
| set -e | |
| echo "pwd: $(pwd)" | |
| echo "ls: $(ls)" | |
| # Configurable Paths (mkdocs.yml needs to be updated accordingly) | |
| ROSDOC2_OUTPUT="./rosdoc2_generated" | |
| SRC_FOLDER="./src" | |
| REPOS_ROOT="./repos" | |
| mkdir -p "$ROSDOC2_OUTPUT" "$SRC_FOLDER" | |
| echo "rosdoc2_output=$ROSDOC2_OUTPUT" >> $GITHUB_OUTPUT | |
| # Build C++ packages docs with rosdoc2 | |
| echo "Building docs of C++ packages..." | |
| source /home/ubm/rosdoc2/bin/activate | |
| # rosdoc2 pulls sphinx which requires docutils < 0.22. | |
| python3 -m pip install "docutils>=0.20,<0.22" | |
| source /opt/ros/foxy/setup.bash | |
| find "$REPOS_ROOT" -type f -iname "package.xml" -print0 | while IFS= read -r -d '' f; do | |
| package_dir="${f%/package.xml}" | |
| repo_dir="${package_dir#${REPOS_ROOT}/}" | |
| repo_name="${repo_dir%%/*}" | |
| package_name="${package_dir##*/}" | |
| if grep -q "rosdoc2" "$f"; then | |
| echo "Building $repo_name/$package_name with rosdoc2" | |
| rosdoc2 build -p "$package_dir" -o "$ROSDOC2_OUTPUT/$repo_name/" | |
| fi | |
| done | |
| deactivate | |
| # Preparing Python packages for mkdocs | |
| echo "Preparing Python packages for mkdocs..." | |
| find "$REPOS_ROOT" -type f -iname "package.xml" -print0 | while IFS= read -r -d '' f; do | |
| package_dir="${f%/package.xml}" | |
| package_name="${package_dir##*/}" | |
| if grep -q "ament_python" "$f"; then | |
| echo "Copying $package_name to $SRC_FOLDER" | |
| cp -r "$package_dir/$package_name" "$SRC_FOLDER/$package_name" | |
| fi | |
| done | |
| - name: Generate repository pages | |
| run: | | |
| python3 scripts/gen_repository_pages.py | |
| - name: Build documentation | |
| run: | | |
| export PYTHONPATH="$PYTHONPATH:$(pwd)/src" | |
| mkdocs build --clean --use-directory-urls | |
| - name: Add additional files to site | |
| run: | | |
| cp -r "${{ steps.generate_docs.outputs.rosdoc2_output }}" ./site/ | |
| - name: Configure Git for Deployment | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| git config --global --add safe.directory /__w/ubm-docs/ubm-docs | |
| - name: Deploy with ghp-import | |
| if: github.ref == 'refs/heads/main' | |
| run: | | |
| ghp-import --no-jekyll --push --force site |