|
| 1 | +#!/bin/bash |
| 2 | +# (C) 2026 GoodData Corporation |
| 3 | +# Generates documentation for a single version branch. |
| 4 | +# This is the per-version logic extracted from generate.sh for parallel execution. |
| 5 | +# |
| 6 | +# Usage: generate-single-version.sh <full-branch-ref> <section> |
| 7 | +# Example: generate-single-version.sh origin/rel/1.3 1 |
| 8 | +# |
| 9 | +# Prerequisites: |
| 10 | +# - Repository checked out with the target branch fetched |
| 11 | +# - Python environment with script-requirements.txt installed from the TARGET branch |
| 12 | +set -e |
| 13 | + |
| 14 | +branch=$1 |
| 15 | +section=$2 |
| 16 | + |
| 17 | +if [ -z "$branch" ] || [ -z "$section" ]; then |
| 18 | + echo "Usage: generate-single-version.sh <full-branch-ref> <section>" |
| 19 | + echo "Example: generate-single-version.sh origin/rel/1.3 1" |
| 20 | + exit 1 |
| 21 | +fi |
| 22 | + |
| 23 | +REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)" |
| 24 | +cd "$REPO_ROOT/docs" |
| 25 | + |
| 26 | +content_dir=versioned_docs |
| 27 | + |
| 28 | +mkdir -p "$content_dir/$section" |
| 29 | + |
| 30 | +# Determine source content path on the branch |
| 31 | +if git ls-tree -d "$branch" -- "content/en/docs" 2>/dev/null | grep -q "content/en/docs"; then |
| 32 | + src_section=docs |
| 33 | +else |
| 34 | + src_section=latest |
| 35 | +fi |
| 36 | + |
| 37 | +# Extract documentation content from the branch |
| 38 | +echo "Extracting docs from $branch for section $section (src=$src_section)" |
| 39 | +# strip-components=3 removes content/en/{src_section} prefix |
| 40 | +git archive "$branch" "content/en/$src_section" | tar xf - -C "$content_dir/$section" \ |
| 41 | + --strip-components=3 "content/en/$src_section" |
| 42 | + |
| 43 | +# Generate API reference if json_builder.py exists on the branch |
| 44 | +API_GEN_FILE="$branch:scripts/docs/json_builder.py" |
| 45 | +if git cat-file -e "$API_GEN_FILE" 2>/dev/null; then |
| 46 | + echo "Generating API ref for section $section..." |
| 47 | + |
| 48 | + # Get api_spec.toml from the branch |
| 49 | + if git ls-tree --name-only "$branch" | grep -q "^api_spec.toml$"; then |
| 50 | + git checkout "$branch" -- api_spec.toml |
| 51 | + else |
| 52 | + echo "No api_spec.toml on $branch, removing local copy" |
| 53 | + rm -f api_spec.toml |
| 54 | + fi |
| 55 | + |
| 56 | + # Generate API introspection data from this version's SDK |
| 57 | + python3 ../scripts/docs/json_builder.py |
| 58 | + mv -f data.json "$content_dir/$section/" |
| 59 | + |
| 60 | + # Generate API reference markdown files |
| 61 | + python3 ../scripts/docs/python_ref_builder.py api_spec.toml \ |
| 62 | + "./$content_dir/$section/data.json" "$section" "$content_dir" |
| 63 | +else |
| 64 | + echo "No json_builder.py on $branch, skipping API ref generation" |
| 65 | +fi |
| 66 | + |
| 67 | +echo "Done: section $section from $branch" |
0 commit comments