|
| 1 | +#!/usr/bin/env bash |
| 2 | +set -euo pipefail |
| 3 | + |
| 4 | +# Creates a new versioned documentation release. |
| 5 | +# |
| 6 | +# Usage: |
| 7 | +# ./create-release.sh <version> |
| 8 | +# |
| 9 | +# Example: |
| 10 | +# ./create-release.sh 2.1 |
| 11 | +# |
| 12 | +# This will: |
| 13 | +# 1. Copy docs/ to versioned_docs/version-2.1.x/ |
| 14 | +# 2. Prepend "2.1.x" to versions.json |
| 15 | +# 3. Create versioned_sidebars/version-2.1.x-sidebars.json from sidebars.ts |
| 16 | + |
| 17 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 18 | +cd "$SCRIPT_DIR" |
| 19 | + |
| 20 | +if [ $# -ne 1 ]; then |
| 21 | + echo "Usage: $0 <version>" |
| 22 | + echo "Example: $0 2.1" |
| 23 | + exit 1 |
| 24 | +fi |
| 25 | + |
| 26 | +VERSION="$1" |
| 27 | +VERSION_LABEL="${VERSION}.x" |
| 28 | +VERSIONED_DOCS_DIR="versioned_docs/version-${VERSION_LABEL}" |
| 29 | +SIDEBAR_FILE="versioned_sidebars/version-${VERSION_LABEL}-sidebars.json" |
| 30 | + |
| 31 | +# Validate that the version doesn't already exist |
| 32 | +if [ -d "$VERSIONED_DOCS_DIR" ]; then |
| 33 | + echo "Error: Version ${VERSION_LABEL} already exists at ${VERSIONED_DOCS_DIR}" |
| 34 | + exit 1 |
| 35 | +fi |
| 36 | + |
| 37 | +if grep -q "\"${VERSION_LABEL}\"" versions.json; then |
| 38 | + echo "Error: Version ${VERSION_LABEL} already listed in versions.json" |
| 39 | + exit 1 |
| 40 | +fi |
| 41 | + |
| 42 | +# Step 1: Copy docs/ to versioned_docs/version-<version>.x/ |
| 43 | +echo "Copying docs/ to ${VERSIONED_DOCS_DIR}/" |
| 44 | +cp -r docs "$VERSIONED_DOCS_DIR" |
| 45 | + |
| 46 | +# Step 2: Prepend version to versions.json |
| 47 | +echo "Adding \"${VERSION_LABEL}\" to versions.json" |
| 48 | +EXISTING=$(cat versions.json) |
| 49 | +echo "$EXISTING" | python3 -c " |
| 50 | +import json, sys |
| 51 | +versions = json.load(sys.stdin) |
| 52 | +versions.insert(0, '${VERSION_LABEL}') |
| 53 | +print(json.dumps(versions, indent=4)) |
| 54 | +" > versions.json |
| 55 | + |
| 56 | +# Step 3: Create sidebar file by converting sidebars.ts to JSON |
| 57 | +# Use the same structure as existing versioned sidebar files |
| 58 | +echo "Creating ${SIDEBAR_FILE}" |
| 59 | +# Extract the sidebar JSON from the most recent versioned sidebar as a template, |
| 60 | +# since all versioned sidebars match the current sidebars.ts structure. |
| 61 | +LATEST_SIDEBAR=$(ls -1 versioned_sidebars/*.json 2>/dev/null | sort -V | tail -1) |
| 62 | + |
| 63 | +if [ -n "$LATEST_SIDEBAR" ]; then |
| 64 | + cp "$LATEST_SIDEBAR" "$SIDEBAR_FILE" |
| 65 | +else |
| 66 | + # Fallback: generate from the known structure in sidebars.ts |
| 67 | + cat > "$SIDEBAR_FILE" << 'EOF' |
| 68 | +{ |
| 69 | + "docs": [{ "type": "autogenerated", "dirName": "." }], |
| 70 | + "api": [ |
| 71 | + "api/overview", |
| 72 | + "api/arrow-flight-sql/index", |
| 73 | + "api/jdbc/index", |
| 74 | + "api/odbc/index", |
| 75 | + "api/auth/index", |
| 76 | + "api/tls/index", |
| 77 | + { |
| 78 | + "type": "category", |
| 79 | + "label": "HTTP", |
| 80 | + "collapsible": true, |
| 81 | + "collapsed": false, |
| 82 | + "items": [{ "type": "autogenerated", "dirName": "api/HTTP" }] |
| 83 | + } |
| 84 | + ] |
| 85 | +} |
| 86 | +EOF |
| 87 | +fi |
| 88 | + |
| 89 | +echo "" |
| 90 | +echo "Release ${VERSION_LABEL} created successfully!" |
| 91 | +echo "" |
| 92 | +echo "Files created/modified:" |
| 93 | +echo " - ${VERSIONED_DOCS_DIR}/ (copied from docs/)" |
| 94 | +echo " - versions.json (updated)" |
| 95 | +echo " - ${SIDEBAR_FILE} (created)" |
0 commit comments