Skip to content

Commit

Permalink
SQUASH – wip – generate spec html pages for each intree version
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelsembwever committed Dec 30, 2024
1 parent a5deafa commit da86c5b
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 50 deletions.
1 change: 1 addition & 0 deletions site-content/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ RUN apt update && \
apt install -y \
openjdk-8-jdk \
openjdk-11-jdk \
openjdk-17-jdk \
python3 \
python3-pip \
ant \
Expand Down
61 changes: 24 additions & 37 deletions site-content/docker-entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,19 @@
#!/bin/bash
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# Abort script if a command fails
set -e
Expand All @@ -7,7 +22,6 @@ export CASSANDRA_USE_JDK11=true
export CASSANDRA_WEBSITE_DIR="${BUILD_DIR}/cassandra-website"
export CASSANDRA_SOURCE_DIR="${BUILD_DIR}/cassandra"
export CASSANDRA_WORKING_DIR="${BUILD_DIR}/working/cassandra"
export CASSANDRA_WORKING_DOC="${CASSANDRA_WORKING_DIR}/doc"
GIT_USER_SETUP="false"

setup_git_user() {
Expand Down Expand Up @@ -49,10 +63,10 @@ generate_cassandra_versioned_docs() {
commit_changes_to_branch="disabled"
fi

pushd "${CASSANDRA_WORKING_DIR}" > /dev/null
for version in ${GENERATE_CASSANDRA_VERSIONS}
do
log_message "INFO" "Checking out '${version}'"
pushd "${CASSANDRA_WORKING_DIR}" > /dev/null
git clean -xdff
git checkout "${version}"

Expand All @@ -70,23 +84,25 @@ generate_cassandra_versioned_docs() {
# For Cassandra 3.11 docs use JDK 8
java_version="/usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java"
javac_version="/usr/lib/jvm/java-8-openjdk-amd64/bin/javac"
ant_cmd_options=""
else
elif [ "$(cut -d'.' -f1 <<< "${doc_version}")" -lt 5 ]
then
# For Cassandra 4.0+ docs use JDK 11
# TODO – from 5 onwards, we can detect the default JDK version from the build.xml file
java_version="/usr/lib/jvm/java-11-openjdk-amd64/bin/java"
javac_version="/usr/lib/jvm/java-11-openjdk-amd64/bin/javac"
ant_cmd_options="-Duse.jdk11=true"
else
java_version_=$(grep 'property\s*name="java.default"' build.xml |sed -ne 's/.*value="\([^"]*\)".*/\1/p')
java_version="/usr/lib/jvm/java-${java_version_}-openjdk-amd64/bin/java"
javac_version="/usr/lib/jvm/java-${java_version_}-openjdk-amd64/bin/javac"
fi
sudo update-alternatives --set java ${java_version}
sudo update-alternatives --set javac ${javac_version}

log_message "INFO" "Using Java compiler version $(javac -version) to compile Cassandra JARs"
ant realclean
ant "${ant_cmd_options}" gen-asciidoc
popd > /dev/null
generate_native_protocol_specs_pages

pushd "${CASSANDRA_WORKING_DIR}" > /dev/null
if [ "${commit_changes_to_branch}" = "enabled" ]
then
# Remove the doc/* directory entries in the .gitignore file so we can commit the generated docs to the working
Expand Down Expand Up @@ -206,21 +222,7 @@ render_site_content_to_html() {

generate_native_protocol_specs_pages() {
log_message "INFO" "Processing native protocols spec page"
for version in ${GENERATE_CASSANDRA_VERSIONS}
do
log_message "INFO" "Checking out '${version}'"
pushd "${CASSANDRA_WORKING_DIR}" > /dev/null
git clean -xdff
git checkout "${version}"

local doc_version=""
doc_version=$(grep 'property\s*name=\"base.version\"' build.xml |sed -ne 's/.*value=\"\([^"]*\)\".*/\1/p')
if [ -d "${CASSANDRA_WEBSITE_DIR}/site-content/build/html/Cassandra/$(cut -d'.' -f1-2 <<< "${doc_version}")/cassandra/native-protocol" ]
then
sudo /usr/local/bin/process-native-protocol-specs-in-docker.sh "$(cut -d'.' -f1-2 <<< "${doc_version}")"
fi
popd > /dev/null
done
sudo /usr/local/bin/process-native-protocol-specs-in-docker.sh
}

prepare_site_html_for_publication() {
Expand All @@ -230,7 +232,6 @@ prepare_site_html_for_publication() {
log_message "INFO" "Moving site HTML to content/"
mkdir -p content/doc
cp -r site-content/build/html/* content/
#rm -f content/_/sed*

# remove hardcoded domain name, and empty domain names first before we duplicate and documentation
content_files_to_change=($(grep -rl 'https://cassandra.apache.org/' content/))
Expand Down Expand Up @@ -332,15 +333,6 @@ run_preview_mode() {
render_site_content_to_html
fi

if [ "${COMMAND_GENERATE_DOCS}" = "run" ]
then
export -f generate_native_protocol_specs_pages
on_change_functions="${on_change_functions} && generate_native_protocol_specs_pages"

GENERATE_CASSANDRA_VERSIONS=$(cut -d' ' -f1 <<< "${GENERATE_CASSANDRA_VERSIONS}")
fi


pushd "${CASSANDRA_WEBSITE_DIR}/site-content/build/html" > /dev/null
live-server --port=5151 --host=0.0.0.0 --no-browser --no-css-inject --wait=2000 &
popd > /dev/null
Expand Down Expand Up @@ -432,11 +424,6 @@ then
export DOCSEARCH_INDEX_VERSION=latest

render_site_content_to_html
if [ "${COMMAND_GENERATE_DOCS}" = "run" ]
then
generate_native_protocol_specs_pages
fi

prepare_site_html_for_publication
fi

Expand Down
41 changes: 28 additions & 13 deletions site-content/process-native-protocol-specs-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash
#!/bin/sh
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
Expand All @@ -15,39 +15,54 @@
# See the License for the specific language governing permissions and
# limitations under the License.

[ -f "build.xml" ] || { error 1 "build.xml must exist (current directory needs to be cassandra repo"; }

# Exit immediately if a command exits with a non-zero status.
set -e

# Variables
DOC_VERSION="$1"
GO_VERSION="1.23.1"
GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz"
PARSER_DIR="/home/build/cassandra-website/cqlprotodoc"
WEBSITE_DIR="/home/build/cassandra-website"
CASSANDRA_DIR="/home/build/cassandra"
TMPDIR="/tmp"

# Step 0: Download and install Go
echo "Downloading Go $GO_VERSION..."
wget -q https://golang.org/dl/$GO_TAR
wget -q https://golang.org/dl/$GO_TAR -O $TMPDIR/$GO_TAR

echo "Installing Go..."
tar -C /usr/local -xzf $GO_TAR
tar -C $TMPDIR -xzf /tmp/$GO_TAR
rm /tmp/$GO_TAR

# Set Go environment variables
export PATH=$PATH:/usr/local/go/bin
export GOPATH=$HOME/go
export PATH=$PATH:$TMPDIR/go/bin
export GOPATH=$TMPDIR/go

# Step 1: Building the parser
echo "Building the cqlprotodoc..."
cd "$PARSER_DIR"
go build -o cqlprotodoc
DIR="$(pwd)"
cd "${TMPDIR}"
git clone -n --depth=1 --filter=tree:0 https://github.com/apache/cassandra-website
cd "${TMPDIR}/cassandra-website"
git sparse-checkout set --no-cone /cqlprotodoc
git checkout
cd "${TMPDIR}/cassandra-website/cqlprotodoc"
go build -o "$TMPDIR"/cqlprotodoc
cd "${DIR}"

# Step 2: Process the spec files using the parser
echo "Processing the .spec files..."
"$PARSER_DIR"/cqlprotodoc "$CASSANDRA_DIR/doc" "$WEBSITE_DIR/site-content/build/html/Cassandra/$DOC_VERSION/cassandra/native-protocol"
cd "${DIR}/doc"
output_dir="modules/cassandra/pages/native-protocol"
mkdir -p "${output_dir}"
"$TMPDIR"/cqlprotodoc . "${output_dir}"
# antora processes first the files and sees .adoc files not .html
# XXX maybe cqlprotodoc should just be directly generating asciidoc files?
find ${output_dir} -name "*.html" -exec bash -c 'mv "$0" "${0%.html}.adoc"' {} \;
ls ${output_dir}

# Step 3: Cleanup - Remove the Cassandra and parser directories
echo "Cleaning up..."
rm -rf "$PARSER_DIR/cqlprotodoc" "$PARSER_DIR/specs" /usr/local/go $GO_TAR
cd "${DIR}"
rm -rf "$TMPDIR/go" "${TMPDIR}/cassandra-website" 2>/dev/null

echo "Script completed successfully."

0 comments on commit da86c5b

Please sign in to comment.