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 6, 2024
1 parent 7030222 commit c06aa65
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
2 changes: 1 addition & 1 deletion 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 Expand Up @@ -123,7 +124,6 @@ EXPOSE 5151/tcp
USER ${BUILD_USER}
WORKDIR ${BUILD_DIR}
COPY docker-entrypoint.sh /usr/local/bin/

COPY process-native-protocol-specs-in-docker.sh /usr/local/bin/

ENTRYPOINT ["docker-entrypoint.sh"]
Expand Down
20 changes: 10 additions & 10 deletions site-content/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,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 +70,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 @@ -205,8 +207,8 @@ render_site_content_to_html() {
}

generate_native_protocol_specs_pages() {
log_message "INFO" "Processing native protocols spec page"
sudo /usr/local/bin/process-native-protocol-specs-in-docker.sh
log_message "INFO" "Processing native protocols spec page"
sudo /usr/local/bin/process-native-protocol-specs-in-docker.sh
}

prepare_site_html_for_publication() {
Expand Down Expand Up @@ -409,8 +411,6 @@ then
export DOCSEARCH_INDEX_VERSION=latest

render_site_content_to_html
generate_native_protocol_specs_pages

prepare_site_html_for_publication
fi

Expand Down
48 changes: 33 additions & 15 deletions site-content/process-native-protocol-specs-in-docker.sh
Original file line number Diff line number Diff line change
@@ -1,41 +1,59 @@
#!/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.


[ -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
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"
GO_DIR="/tmp"
WEBSITE_DIR="${CASSANDRA_WEBSITE_DIR:-../cassandra-website}"

# 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 $GO_DIR/$GO_TAR

echo "Installing Go..."
tar -C /usr/local -xzf $GO_TAR
tar -C $GO_DIR -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:$GO_DIR/go/bin
export GOPATH=$GO_DIR/go

# Step 1: Building the parser
echo "Building the cqlprotodoc..."
cd "$PARSER_DIR"
go build -o cqlprotodoc

mkdir "specs"
wget -q -L -O "$PARSER_DIR/specs/native_protocol_v3.spec" https://raw.github.com/apache/cassandra/trunk/doc/native_protocol_v3.spec
wget -q -L -O "$PARSER_DIR/specs/native_protocol_v4.spec" https://raw.github.com/apache/cassandra/trunk/doc/native_protocol_v4.spec
wget -q -L -O "$PARSER_DIR/specs/native_protocol_v5.spec" https://raw.github.com/apache/cassandra/trunk/doc/native_protocol_v5.spec
pushd "$WEBSITE_DIR/cqlprotodoc" >/dev/null
go build -o "$GO_DIR"/cqlprotodoc
popd >/dev/null

# Step 2: Process the spec files using the parser
echo "Processing the .spec files..."
"$PARSER_DIR"/cqlprotodoc "$PARSER_DIR/specs" "$WEBSITE_DIR/site-content/build/html/_"
pushd doc >/dev/null
mkdir -p ../build/html
"$GO_DIR"/cqlprotodoc . .
popd >/dev/null

# 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
rm -rf $GO_DIR/go 2>/dev/null

echo "Script completed successfully."

0 comments on commit c06aa65

Please sign in to comment.