mirror of https://github.com/apache/cassandra
Improve Go download when building source code
patch by Ling Mao; reviewed by Stefan Miklosovic, Michael Semb Wever for CASSANDRA-20422 Co-authored-by: Stefan Miklosovic <smiklosovic@apache.org>
This commit is contained in:
parent
c925228a4d
commit
e16f30c587
|
|
@ -221,7 +221,7 @@ def tasks() {
|
||||||
// Disable splits for all but proper stages
|
// Disable splits for all but proper stages
|
||||||
!(axis['split'] > 1 && !stepsMap.findAll { entry -> entry.value.splits >= axis['split'] }.keySet().contains(axis['step'])) &&
|
!(axis['split'] > 1 && !stepsMap.findAll { entry -> entry.value.splits >= axis['split'] }.keySet().contains(axis['step'])) &&
|
||||||
// run only the build types on non-amd64
|
// run only the build types on non-amd64
|
||||||
!(axis['arch'] != 'amd64' && stepsMap.findAll { entry -> 'build' == entry.value.type }.keySet().contains(axis['step']))
|
!(axis['arch'] != 'amd64' && !stepsMap.findAll { entry -> 'build' == entry.value.type }.keySet().contains(axis['step']))
|
||||||
}
|
}
|
||||||
|
|
||||||
def Map tasks = [
|
def Map tasks = [
|
||||||
|
|
@ -337,7 +337,7 @@ def build(command, cell) {
|
||||||
test -f .jenkins/Jenkinsfile || { echo "Invalid git fork/branch"; exit 1; }
|
test -f .jenkins/Jenkinsfile || { echo "Invalid git fork/branch"; exit 1; }
|
||||||
grep -q "Jenkins CI declaration" .jenkins/Jenkinsfile || { echo "Only Cassandra 5.0+ supported"; exit 1; }
|
grep -q "Jenkins CI declaration" .jenkins/Jenkinsfile || { echo "Only Cassandra 5.0+ supported"; exit 1; }
|
||||||
"""
|
"""
|
||||||
fetchDockerImages(['almalinux-build', 'bullseye-build', 'centos7-build'])
|
fetchDockerImages(['almalinux-build', 'bullseye-build'])
|
||||||
def cell_suffix = "_jdk${cell.jdk}_${cell.arch}"
|
def cell_suffix = "_jdk${cell.jdk}_${cell.arch}"
|
||||||
def logfile = "stage-logs/${JOB_NAME}_${BUILD_NUMBER}_${cell.step}${cell_suffix}_attempt${attempt}.log.xz"
|
def logfile = "stage-logs/${JOB_NAME}_${BUILD_NUMBER}_${cell.step}${cell_suffix}_attempt${attempt}.log.xz"
|
||||||
def script_vars = "#!/bin/bash \n set -o pipefail ; " // pipe to tee needs pipefail
|
def script_vars = "#!/bin/bash \n set -o pipefail ; " // pipe to tee needs pipefail
|
||||||
|
|
|
||||||
|
|
@ -468,13 +468,13 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="gen-asciidoc" description="Generate dynamic asciidoc pages" depends="jar" unless="ant.gen-doc.skip">
|
<target name="gen-asciidoc" description="Generate dynamic asciidoc pages" depends="jar" unless="ant.gen-doc.skip">
|
||||||
<exec executable="make" osfamily="unix" dir="${doc.dir}">
|
<exec executable="make" osfamily="unix" dir="${doc.dir}" failonerror="true">
|
||||||
<arg value="gen-asciidoc"/>
|
<arg value="gen-asciidoc"/>
|
||||||
</exec>
|
</exec>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="gen-doc" description="Generate documentation" depends="gen-asciidoc,generate-cql-html" unless="ant.gen-doc.skip">
|
<target name="gen-doc" description="Generate documentation" depends="gen-asciidoc,generate-cql-html" unless="ant.gen-doc.skip">
|
||||||
<exec executable="make" osfamily="unix" dir="${doc.dir}">
|
<exec executable="make" osfamily="unix" dir="${doc.dir}" failonerror="true">
|
||||||
<arg value="html"/>
|
<arg value="html"/>
|
||||||
</exec>
|
</exec>
|
||||||
</target>
|
</target>
|
||||||
|
|
@ -548,7 +548,7 @@
|
||||||
<copy todir="${basedir}/conf" file="${build.classes.main}/META-INF/hotspot_compiler"/>
|
<copy todir="${basedir}/conf" file="${build.classes.main}/META-INF/hotspot_compiler"/>
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<target name="check" depends="_main-jar,build-test" description="Verifies the source code and dependencies. This task is intended to run on pre-commit and locally. It should verify mostly modified files compared to the upstream base branch." unless="check.skip">
|
<target name="check" depends="_main-jar,build-test,gen-doc" description="Verifies the source code and dependencies. This task is intended to run on pre-commit and locally. It should verify mostly modified files compared to the upstream base branch." unless="check.skip">
|
||||||
<antcall target="rat-check" inheritrefs="true"/>
|
<antcall target="rat-check" inheritrefs="true"/>
|
||||||
<antcall target="checkstyle" inheritrefs="true"/>
|
<antcall target="checkstyle" inheritrefs="true"/>
|
||||||
<antcall target="checkstyle-test" inheritrefs="true"/>
|
<antcall target="checkstyle-test" inheritrefs="true"/>
|
||||||
|
|
@ -909,7 +909,7 @@
|
||||||
</target>
|
</target>
|
||||||
|
|
||||||
<!-- creates release tarballs -->
|
<!-- creates release tarballs -->
|
||||||
<target name="artifacts" depends="_artifacts-init,check,gen-doc,sources-jar"
|
<target name="artifacts" depends="_artifacts-init,check,sources-jar"
|
||||||
description="Create Cassandra tarball and maven artifacts">
|
description="Create Cassandra tarball and maven artifacts">
|
||||||
<tar compression="gzip" longfile="gnu"
|
<tar compression="gzip" longfile="gnu"
|
||||||
destfile="${build.dir}/${final.name}-bin.tar.gz">
|
destfile="${build.dir}/${final.name}-bin.tar.gz">
|
||||||
|
|
|
||||||
|
|
@ -20,33 +20,94 @@
|
||||||
|
|
||||||
# Variables
|
# Variables
|
||||||
GO_VERSION="1.23.1"
|
GO_VERSION="1.23.1"
|
||||||
GO_TAR="go${GO_VERSION}.linux-amd64.tar.gz"
|
|
||||||
|
GO_OS=linux
|
||||||
|
|
||||||
|
if [ $(uname) = "Darwin" ]; then
|
||||||
|
GO_OS=darwin
|
||||||
|
fi
|
||||||
|
|
||||||
|
GO_PLATFORM=amd64
|
||||||
|
|
||||||
|
if [ $(uname -m) = "aarch64" ]; then
|
||||||
|
GO_PLATFORM=arm64
|
||||||
|
fi
|
||||||
|
|
||||||
|
GO_TAR="go${GO_VERSION}.${GO_OS}-${GO_PLATFORM}.tar.gz"
|
||||||
TMPDIR="${TMPDIR:-/tmp}"
|
TMPDIR="${TMPDIR:-/tmp}"
|
||||||
|
|
||||||
# Step 0: Download and install Go
|
check_go_version() {
|
||||||
echo "Downloading Go $GO_VERSION..."
|
if command -v go &>/dev/null; then
|
||||||
wget -q "https://golang.org/dl/$GO_TAR" -O "$TMPDIR/$GO_TAR"
|
local installed_version=$(go version | awk '{print $3}' | sed 's/go//')
|
||||||
|
|
||||||
echo "Installing Go..."
|
if [ "$(printf '%s\n' "$GO_VERSION" "$installed_version" | sort -V | head -n1)" = "$GO_VERSION" ]; then
|
||||||
tar -C "$TMPDIR" -xzf "$TMPDIR/$GO_TAR"
|
echo "Detected Go $installed_version (>= $GO_VERSION), skipping installation."
|
||||||
rm "$TMPDIR/$GO_TAR"
|
return 0
|
||||||
|
else
|
||||||
|
if [ -z $installed_version ]; then
|
||||||
|
echo "No Go installation detected, proceeding with installation."
|
||||||
|
else
|
||||||
|
echo "Detected Go $installed_version (< $GO_VERSION), proceeding with installation."
|
||||||
|
fi
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Go env not found in your system, proceeding with installation."
|
||||||
|
return 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
# Set Go environment variables
|
if ! check_go_version; then
|
||||||
export PATH="$PATH:$TMPDIR/go/bin"
|
|
||||||
export GOPATH="$TMPDIR/go"
|
if ls $TMPDIR/go$GO_VERSION > /dev/null 2>&1; then
|
||||||
|
echo "Reusing cached installation in $TMPDIR/go$GO_VERSION"
|
||||||
|
export PATH="$PATH:$TMPDIR/go$GO_VERSION/go/bin"
|
||||||
|
export GOPATH="$TMPDIR/go$GO_VERSION/go/bin"
|
||||||
|
export GOROOT="$TMPDIR/go$GO_VERSION/go"
|
||||||
|
else
|
||||||
|
if ! ls $TMPDIR/$GO_TAR > /dev/null 2>&1; then
|
||||||
|
echo "Downloading Go $GO_VERSION..."
|
||||||
|
|
||||||
|
curl -L --fail --silent --retry 2 --retry-delay 5 --max-time 30 https://golang.org/dl/$GO_TAR -o $TMPDIR/$GO_TAR
|
||||||
|
|
||||||
|
if [ $? != "0" ]; then
|
||||||
|
echo "Network error. Specify '-Dant.gen-doc.skip=true' to skip if offline."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Installing Go $GO_VERSION..."
|
||||||
|
mkdir -p $TMPDIR/go$GO_VERSION
|
||||||
|
tar -C "$TMPDIR/go$GO_VERSION" -xzf "$TMPDIR/$GO_TAR"
|
||||||
|
|
||||||
|
# Set Go environment variables
|
||||||
|
export PATH="$PATH:$TMPDIR/go$GO_VERSION/go/bin"
|
||||||
|
export GOPATH="$TMPDIR/go$GO_VERSION/go/bin"
|
||||||
|
export GOROOT="$TMPDIR/go$GO_VERSION/go"
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "Using system-installed Go."
|
||||||
|
fi
|
||||||
|
|
||||||
# Step 1: Building the parser
|
# Step 1: Building the parser
|
||||||
echo "Building the cqlprotodoc..."
|
echo "Building the cqlprotodoc..."
|
||||||
DIR="$(pwd)"
|
DIR="$(pwd)"
|
||||||
cd "${TMPDIR}"
|
cd "${TMPDIR}"
|
||||||
|
|
||||||
|
rm -rf "${TMPDIR}/cassandra-website"
|
||||||
git clone -n --depth=1 --filter=tree:0 https://github.com/apache/cassandra-website
|
git clone -n --depth=1 --filter=tree:0 https://github.com/apache/cassandra-website
|
||||||
|
|
||||||
|
if [ $? != "0" ]; then
|
||||||
|
echo "Error occured while cloning https://github.com/apache/cassandra-website"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
cd "${TMPDIR}/cassandra-website"
|
cd "${TMPDIR}/cassandra-website"
|
||||||
git sparse-checkout set --no-cone /cqlprotodoc
|
git sparse-checkout set --no-cone /cqlprotodoc
|
||||||
git checkout
|
git checkout
|
||||||
cd "${TMPDIR}/cassandra-website/cqlprotodoc"
|
cd "${TMPDIR}/cassandra-website/cqlprotodoc"
|
||||||
go build -o "$TMPDIR"/cqlprotodoc
|
rm -rf "${TMPDIR}/cqlprotodoc"
|
||||||
|
$TMPDIR/go$GO_VERSION/go/bin/go build -o "$TMPDIR"/cqlprotodoc
|
||||||
|
|
||||||
# Step 2: Process the spec files using the parser
|
# Step 2: Process the spec files using the parser
|
||||||
echo "Processing the .spec files..."
|
echo "Processing the .spec files..."
|
||||||
|
|
@ -121,6 +182,6 @@ echo " </script>" >> "$summary_file"
|
||||||
# Step 3: Cleanup - Remove the Cassandra and parser directories
|
# Step 3: Cleanup - Remove the Cassandra and parser directories
|
||||||
echo "Cleaning up..."
|
echo "Cleaning up..."
|
||||||
cd "${DIR}"
|
cd "${DIR}"
|
||||||
rm -rf "${TMPDIR}/go" "${TMPDIR}/cassandra-website" "${TMPDIR}/cqlprotodoc" 2>/dev/null
|
rm -rf "${TMPDIR}/cassandra-website" "${TMPDIR}/cqlprotodoc" 2>/dev/null
|
||||||
|
|
||||||
echo "Script completed successfully."
|
echo "Script completed successfully."
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue