1#!/bin/bash
2# Generates versioned docs from git release branches at build time
3# Usage: ./scripts/generate-versions.sh
4#
5# This script reads versions from versions.json (manually managed) and
6# generates versioned docs for each. Trunk docs serve as "current" (unreleased).
7#
8# Version structure:
9# - current (trunk): /docs/next - unreleased docs
10# - latest release branch: /docs - default docs
11# - previous release branches: /docs/v2.0, /docs/v1.11, etc.
12
13set -e
14
15SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16WEBSITE_DIR="$(dirname "$SCRIPT_DIR")"
17REPO_ROOT="$(dirname "$WEBSITE_DIR")"
18
19echo "Generating versioned docs..."
20
21cd "$REPO_ROOT"
22
23# Read versions from manually managed versions.json
24VERSIONS_FILE="$WEBSITE_DIR/versions.json"
25if [ ! -f "$VERSIONS_FILE" ]; then
26 echo "Error: versions.json not found. Please create it manually."
27 echo "Example: [\"2.0.x\", \"1.11.x\", \"1.10.x\"]"
28 exit 1
29fi
30
31# Parse versions.json and build VERSIONS array
32# Format: version_label:git_ref (e.g., "1.11.x:release/1.11")
33declare -a VERSIONS=()
34while IFS= read -r version_label; do
35 # Extract version number from label (e.g., "1.11.x" -> "1.11")
36 version_num="${version_label%.x}"
37 git_ref="release/$version_num"
38 VERSIONS+=("$version_label:$git_ref")
39done < <(jq -r '.[]' "$VERSIONS_FILE")
40
41if [ ${#VERSIONS[@]} -eq 0 ]; then
42 echo "No versions found in versions.json. Skipping versioned docs generation."
43 exit 0
44fi
45
46echo "Versions from versions.json: ${VERSIONS[*]}"
47
48# Clean existing versioned docs
49rm -rf "$WEBSITE_DIR/versioned_docs"
50rm -rf "$WEBSITE_DIR/versioned_sidebars"
51mkdir -p "$WEBSITE_DIR/versioned_docs"
52mkdir -p "$WEBSITE_DIR/versioned_sidebars"
53
54# Generate versioned docs from git refs
55for version_entry in "${VERSIONS[@]}"; do
56 version_label="${version_entry%%:*}"
57 git_ref="${version_entry##*:}"
58
59 echo "Generating docs for $version_label from $git_ref..."
60
61 # Try the ref directly first, then with origin/ prefix (for CI environments)
62 resolved_ref=""
63 if git rev-parse --verify "$git_ref" >/dev/null 2>&1; then
64 resolved_ref="$git_ref"
65 elif git rev-parse --verify "origin/$git_ref" >/dev/null 2>&1; then
66 resolved_ref="origin/$git_ref"
67 else
68 echo "Error: Git ref '$git_ref' does not exist for version $version_label"
69 echo "Make sure the release branch exists: git checkout -b $git_ref && git push origin $git_ref"
70 exit 1
71 fi
72
73 echo "Using resolved ref: $resolved_ref"
74
75 version_dir="$WEBSITE_DIR/versioned_docs/version-$version_label"
76 mkdir -p "$version_dir"
77
78 # Extract docs from the git ref (run from repo root to ensure correct path resolution)
79 (cd "$REPO_ROOT" && git archive "$resolved_ref" website/docs) | tar -x -C "$version_dir" --strip-components=2
80
81 # Copy sidebars (convert to JSON format for versioned sidebars)
82 # For simplicity, we'll create a basic autogenerated sidebar
83 cat > "$WEBSITE_DIR/versioned_sidebars/version-$version_label-sidebars.json" << 'EOF'
84{
85 "docs": [{ "type": "autogenerated", "dirName": "." }],
86 "api": [
87 "api/overview",
88 "api/arrow-flight-sql/index",
89 "api/jdbc/index",
90 "api/odbc/index",
91 "api/auth/index",
92 "api/tls/index",
93 {
94 "type": "category",
95 "label": "HTTP",
96 "collapsible": true,
97 "collapsed": false,
98 "items": [{ "type": "autogenerated", "dirName": "api/HTTP" }]
99 }
100 ]
101}
102EOF
103done
104
105# Apply link fixes to versioned docs
106if [ -f "$SCRIPT_DIR/fix-versioned-links.sh" ]; then
107 "$SCRIPT_DIR/fix-versioned-links.sh"
108fi
109
110echo "Done! Generated versions: ${VERSIONS[*]}"
111
1#!/bin/bash
2# Generates versioned docs from git release branches at build time
3# Usage: ./scripts/generate-versions.sh
4#
5# This script reads versions from versions.json (manually managed) and
6# generates versioned docs for each. Trunk docs serve as "current" (unreleased).
7#
8# Version structure:
9# - current (trunk): /docs/next - unreleased docs
10# - latest release branch: /docs - default docs
11# - previous release branches: /docs/v2.0, /docs/v1.11, etc.
12
13set -e
14
15SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
16WEBSITE_DIR="$(dirname "$SCRIPT_DIR")"
17REPO_ROOT="$(dirname "$WEBSITE_DIR")"
18
19echo "Generating versioned docs..."
20
21cd "$REPO_ROOT"
22
23# Read versions from manually managed versions.json
24VERSIONS_FILE="$WEBSITE_DIR/versions.json"
25if [ ! -f "$VERSIONS_FILE" ]; then
26 echo "Error: versions.json not found. Please create it manually."
27 echo "Example: [\"2.0.x\", \"1.11.x\", \"1.10.x\"]"
28 exit 1
29fi
30
31# Parse versions.json and build VERSIONS array
32# Format: version_label:git_ref (e.g., "1.11.x:release/1.11")
33declare -a VERSIONS=()
34while IFS= read -r version_label; do
35 # Extract version number from label (e.g., "1.11.x" -> "1.11")
36 version_num="${version_label%.x}"
37 git_ref="release/$version_num"
38 VERSIONS+=("$version_label:$git_ref")
39done < <(jq -r '.[]' "$VERSIONS_FILE")
40
41if [ ${#VERSIONS[@]} -eq 0 ]; then
42 echo "No versions found in versions.json. Skipping versioned docs generation."
43 exit 0
44fi
45
46echo "Versions from versions.json: ${VERSIONS[*]}"
47
48# Clean existing versioned docs
49rm -rf "$WEBSITE_DIR/versioned_docs"
50rm -rf "$WEBSITE_DIR/versioned_sidebars"
51mkdir -p "$WEBSITE_DIR/versioned_docs"
52mkdir -p "$WEBSITE_DIR/versioned_sidebars"
53
54# Generate versioned docs from git refs
55for version_entry in "${VERSIONS[@]}"; do
56 version_label="${version_entry%%:*}"
57 git_ref="${version_entry##*:}"
58
59 echo "Generating docs for $version_label from $git_ref..."
60
61 # Try the ref directly first, then with origin/ prefix (for CI environments)
62 resolved_ref=""
63 if git rev-parse --verify "$git_ref" >/dev/null 2>&1; then
64 resolved_ref="$git_ref"
65 elif git rev-parse --verify "origin/$git_ref" >/dev/null 2>&1; then
66 resolved_ref="origin/$git_ref"
67 else
68 echo "Error: Git ref '$git_ref' does not exist for version $version_label"
69 echo "Make sure the release branch exists: git checkout -b $git_ref && git push origin $git_ref"
70 exit 1
71 fi
72
73 echo "Using resolved ref: $resolved_ref"
74
75 version_dir="$WEBSITE_DIR/versioned_docs/version-$version_label"
76 mkdir -p "$version_dir"
77
78 # Extract docs from the git ref (run from repo root to ensure correct path resolution)
79 (cd "$REPO_ROOT" && git archive "$resolved_ref" website/docs) | tar -x -C "$version_dir" --strip-components=2
80
81 # Copy sidebars (convert to JSON format for versioned sidebars)
82 # For simplicity, we'll create a basic autogenerated sidebar
83 cat > "$WEBSITE_DIR/versioned_sidebars/version-$version_label-sidebars.json" << 'EOF'
84{
85 "docs": [{ "type": "autogenerated", "dirName": "." }],
86 "api": [
87 "api/overview",
88 "api/arrow-flight-sql/index",
89 "api/jdbc/index",
90 "api/odbc/index",
91 "api/auth/index",
92 "api/tls/index",
93 {
94 "type": "category",
95 "label": "HTTP",
96 "collapsible": true,
97 "collapsed": false,
98 "items": [{ "type": "autogenerated", "dirName": "api/HTTP" }]
99 }
100 ]
101}
102EOF
103done
104
105# Apply link fixes to versioned docs
106if [ -f "$SCRIPT_DIR/fix-versioned-links.sh" ]; then
107 "$SCRIPT_DIR/fix-versioned-links.sh"
108fi
109
110echo "Done! Generated versions: ${VERSIONS[*]}"
111