| 1 |
#!/bin/bash |
| 2 |
# Copyright 2018 The gRPC Authors |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
set -ex |
| 17 |
|
| 18 |
shopt -s nullglob |
| 19 |
|
| 20 |
cd "$(dirname "$0")/../../.." |
| 21 |
|
| 22 |
GRPC_VERSION=$(grep -e "^ *version: " build_handwritten.yaml | head -n 1 | sed 's/.*: //') |
| 23 |
|
| 24 |
INPUT_ARTIFACTS=$KOKORO_GFILE_DIR/github/grpc/artifacts |
| 25 |
INDEX_FILENAME=index.xml |
| 26 |
|
| 27 |
BUILD_ID=${KOKORO_BUILD_ID:-$(uuidgen)} |
| 28 |
BUILD_BRANCH_NAME=master |
| 29 |
BUILD_GIT_COMMIT=${KOKORO_GIT_COMMIT:-unknown} |
| 30 |
BUILD_TIMESTAMP=$(date -Iseconds) |
| 31 |
BUILD_RELPATH=$(date "+%Y/%m")/$BUILD_GIT_COMMIT-$BUILD_ID/ |
| 32 |
|
| 33 |
GCS_ROOT=gs://packages.grpc.io/ |
| 34 |
GCS_ARCHIVE_PREFIX=archive/ |
| 35 |
GCS_ARCHIVE_ROOT=$GCS_ROOT$GCS_ARCHIVE_PREFIX |
| 36 |
GCS_INDEX=$GCS_ROOT$INDEX_FILENAME |
| 37 |
|
| 38 |
LOCAL_STAGING_TEMPDIR=$(mktemp -d) |
| 39 |
LOCAL_BUILD_ROOT=$LOCAL_STAGING_TEMPDIR/$BUILD_RELPATH |
| 40 |
LOCAL_BUILD_INDEX=$LOCAL_BUILD_ROOT$INDEX_FILENAME |
| 41 |
|
| 42 |
mkdir -p "$LOCAL_BUILD_ROOT" |
| 43 |
|
| 44 |
find "$INPUT_ARTIFACTS" -type f |
| 45 |
|
| 46 |
# protoc Plugins |
| 47 |
PROTOC_PLUGINS_ZIPPED_PACKAGES=$(mktemp -d) |
| 48 |
for zip_dir in protoc_windows_{x86,x64} |
| 49 |
do |
| 50 |
zip -jr "$PROTOC_PLUGINS_ZIPPED_PACKAGES/grpc-$zip_dir-$GRPC_VERSION.zip" "$INPUT_ARTIFACTS/$zip_dir/"* |
| 51 |
done |
| 52 |
for tar_dir in protoc_linux_{x86,x64} protoc_macos_x64 |
| 53 |
do |
| 54 |
chmod +x "$INPUT_ARTIFACTS/$tar_dir"/* |
| 55 |
tar -cvzf "$PROTOC_PLUGINS_ZIPPED_PACKAGES/grpc-$tar_dir-$GRPC_VERSION.tar.gz" -C "$INPUT_ARTIFACTS/$tar_dir" . |
| 56 |
done |
| 57 |
|
| 58 |
PROTOC_PACKAGES=( |
| 59 |
"$PROTOC_PLUGINS_ZIPPED_PACKAGES"/grpc-protoc_windows_{x86,x64}-"$GRPC_VERSION.zip" |
| 60 |
"$PROTOC_PLUGINS_ZIPPED_PACKAGES"/grpc-protoc_linux_{x86,x64}-"$GRPC_VERSION.tar.gz" |
| 61 |
"$PROTOC_PLUGINS_ZIPPED_PACKAGES"/grpc-protoc_macos_x64-"$GRPC_VERSION.tar.gz" |
| 62 |
) |
| 63 |
|
| 64 |
# C# |
| 65 |
UNZIPPED_CSHARP_PACKAGES=$(mktemp -d) |
| 66 |
unzip "$INPUT_ARTIFACTS/csharp_nugets_windows_dotnetcli.zip" -d "$UNZIPPED_CSHARP_PACKAGES" |
| 67 |
CSHARP_PACKAGES=( |
| 68 |
"$UNZIPPED_CSHARP_PACKAGES"/* |
| 69 |
"$INPUT_ARTIFACTS"/grpc_unity_package.[0-9]*.zip |
| 70 |
) |
| 71 |
|
| 72 |
# Python |
| 73 |
PYTHON_GRPCIO_PACKAGES=( |
| 74 |
"$INPUT_ARTIFACTS"/grpcio-[0-9]*.tar.gz |
| 75 |
"$INPUT_ARTIFACTS"/grpcio-[0-9]*.whl |
| 76 |
"$INPUT_ARTIFACTS"/python_linux_extra_arm*/grpcio-[0-9]*.whl |
| 77 |
) |
| 78 |
PYTHON_GRPCIO_TOOLS_PACKAGES=( |
| 79 |
"$INPUT_ARTIFACTS"/grpcio-tools-[0-9]*.tar.gz |
| 80 |
"$INPUT_ARTIFACTS"/grpcio_tools-[0-9]*.whl |
| 81 |
"$INPUT_ARTIFACTS"/python_linux_extra_arm*/grpcio_tools-[0-9]*.whl |
| 82 |
) |
| 83 |
PYTHON_GRPCIO_HEALTH_CHECKING_PACKAGES=( |
| 84 |
"$INPUT_ARTIFACTS"/grpcio-health-checking-[0-9]*.tar.gz |
| 85 |
) |
| 86 |
PYTHON_GRPCIO_REFLECTION_PACKAGES=( |
| 87 |
"$INPUT_ARTIFACTS"/grpcio-reflection-[0-9]*.tar.gz |
| 88 |
) |
| 89 |
PYTHON_GRPCIO_TESTING_PACKAGES=( |
| 90 |
"$INPUT_ARTIFACTS"/grpcio-testing-[0-9]*.tar.gz |
| 91 |
) |
| 92 |
|
| 93 |
# PHP |
| 94 |
PHP_PACKAGES=( |
| 95 |
"$INPUT_ARTIFACTS"/grpc-[0-9]*.tgz |
| 96 |
) |
| 97 |
|
| 98 |
# Ruby |
| 99 |
RUBY_PACKAGES=( |
| 100 |
"$INPUT_ARTIFACTS"/grpc-[0-9]*.gem |
| 101 |
"$INPUT_ARTIFACTS"/grpc-tools-[0-9]*.gem |
| 102 |
) |
| 103 |
|
| 104 |
function add_to_manifest() { |
| 105 |
local artifact_type=$1 |
| 106 |
local artifact_file=$2 |
| 107 |
local artifact_prefix=$3 |
| 108 |
local artifact_name |
| 109 |
artifact_name=$(basename "$artifact_file") |
| 110 |
local artifact_size |
| 111 |
artifact_size=$(stat -c%s "$artifact_file") |
| 112 |
local artifact_sha256 |
| 113 |
artifact_sha256=$(openssl sha256 -r "$artifact_file" | cut -d " " -f 1) |
| 114 |
local artifact_target=$LOCAL_BUILD_ROOT/$artifact_type/$artifact_prefix |
| 115 |
mkdir -p "$artifact_target" |
| 116 |
cp "$artifact_file" "$artifact_target" |
| 117 |
cat <<EOF |
| 118 |
<artifact name='$artifact_name' |
| 119 |
type='$artifact_type' |
| 120 |
path='$artifact_type/$artifact_prefix$artifact_name' |
| 121 |
size='$artifact_size' |
| 122 |
sha256='$artifact_sha256' /> |
| 123 |
EOF |
| 124 |
} |
| 125 |
|
| 126 |
{ |
| 127 |
cat <<EOF |
| 128 |
<?xml version="1.0"?> |
| 129 |
<?xml-stylesheet href="/web-assets/build-201807.xsl" type="text/xsl"?> |
| 130 |
<build id='$BUILD_ID' timestamp='$BUILD_TIMESTAMP' version="201807"> |
| 131 |
<metadata> |
| 132 |
<project>gRPC</project> |
| 133 |
<repository>https://github.com/grpc/grpc</repository> |
| 134 |
<branch>$BUILD_BRANCH_NAME</branch> |
| 135 |
<commit>$BUILD_GIT_COMMIT</commit> |
| 136 |
</metadata> |
| 137 |
<artifacts> |
| 138 |
EOF |
| 139 |
|
| 140 |
for pkg in "${PROTOC_PACKAGES[@]}"; do add_to_manifest protoc "$pkg"; done |
| 141 |
for pkg in "${CSHARP_PACKAGES[@]}"; do add_to_manifest csharp "$pkg"; done |
| 142 |
for pkg in "${PHP_PACKAGES[@]}"; do add_to_manifest php "$pkg"; done |
| 143 |
for pkg in "${PYTHON_GRPCIO_PACKAGES[@]}"; do add_to_manifest python "$pkg" grpcio/; done |
| 144 |
for pkg in "${PYTHON_GRPCIO_TOOLS_PACKAGES[@]}"; do add_to_manifest python "$pkg" grpcio-tools/; done |
| 145 |
for pkg in "${PYTHON_GRPCIO_HEALTH_CHECKING_PACKAGES[@]}"; do add_to_manifest python "$pkg" grpcio-health-checking/; done |
| 146 |
for pkg in "${PYTHON_GRPCIO_REFLECTION_PACKAGES[@]}"; do add_to_manifest python "$pkg" grpcio-reflection/; done |
| 147 |
for pkg in "${PYTHON_GRPCIO_TESTING_PACKAGES[@]}"; do add_to_manifest python "$pkg" grpcio-testing/; done |
| 148 |
for pkg in "${RUBY_PACKAGES[@]}"; do add_to_manifest ruby "$pkg"; done |
| 149 |
|
| 150 |
cat <<EOF |
| 151 |
</artifacts> |
| 152 |
</build> |
| 153 |
EOF |
| 154 |
}> "$LOCAL_BUILD_INDEX" |
| 155 |
|
| 156 |
LOCAL_BUILD_INDEX_SIZE=$(stat -c%s "$LOCAL_BUILD_INDEX") |
| 157 |
LOCAL_BUILD_INDEX_SHA256=$(openssl sha256 -r "$LOCAL_BUILD_INDEX" | cut -d " " -f 1) |
| 158 |
|
| 159 |
OLD_INDEX=$(mktemp) |
| 160 |
NEW_INDEX=$(mktemp) |
| 161 |
|
| 162 |
# Download the current /index.xml into $OLD_INDEX |
| 163 |
gsutil cp "$GCS_INDEX" "$OLD_INDEX" |
| 164 |
|
| 165 |
{ |
| 166 |
# we want to add an entry as the first child under <builds> tag |
| 167 |
# we can get by without a real XML parser by rewriting the header, |
| 168 |
# injecting our new tag, and then dumping the rest of the file as is. |
| 169 |
cat <<EOF |
| 170 |
<?xml version="1.0"?> |
| 171 |
<?xml-stylesheet href="/web-assets/home.xsl" type="text/xsl"?> |
| 172 |
<packages> |
| 173 |
<builds> |
| 174 |
<build id='$BUILD_ID' |
| 175 |
timestamp='$BUILD_TIMESTAMP' |
| 176 |
branch='$BUILD_BRANCH_NAME' |
| 177 |
commit='$BUILD_GIT_COMMIT' |
| 178 |
path='$GCS_ARCHIVE_PREFIX$BUILD_RELPATH$INDEX_FILENAME' |
| 179 |
size='$LOCAL_BUILD_INDEX_SIZE' |
| 180 |
sha256='$LOCAL_BUILD_INDEX_SHA256' /> |
| 181 |
EOF |
| 182 |
tail --lines=+5 "$OLD_INDEX" |
| 183 |
}> "$NEW_INDEX" |
| 184 |
|
| 185 |
|
| 186 |
function generate_directory_index() |
| 187 |
{ |
| 188 |
local target_dir=$1 |
| 189 |
local current_directory_name |
| 190 |
current_directory_name=$(basename "$target_dir") |
| 191 |
cat <<EOF |
| 192 |
<!DOCTYPE html> |
| 193 |
<html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang=""> |
| 194 |
<head> |
| 195 |
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> |
| 196 |
<title>Index of $current_directory_name - packages.grpc.io</title> |
| 197 |
<link rel="stylesheet" type="text/css" href="/web-assets/dirindex.css" /> |
| 198 |
</head> |
| 199 |
<body> |
| 200 |
<h1>Index of <a href="#"><code>$current_directory_name</code></a></h1> |
| 201 |
<ul> |
| 202 |
<li><a href="#">.</a></li> |
| 203 |
<li><a href="..">..</a></li> |
| 204 |
EOF |
| 205 |
|
| 206 |
( |
| 207 |
cd "$target_dir" |
| 208 |
find * -maxdepth 0 -type d -print | sort | while read -r line |
| 209 |
do |
| 210 |
echo " <li><a href='$line/'>$line/</a></li>" |
| 211 |
done |
| 212 |
find * -maxdepth 0 -type f -print | sort | while read -r line |
| 213 |
do |
| 214 |
echo " <li><a href='$line'>$line</a></li>" |
| 215 |
done |
| 216 |
) |
| 217 |
|
| 218 |
cat <<EOF |
| 219 |
</ul> |
| 220 |
</body> |
| 221 |
</html> |
| 222 |
EOF |
| 223 |
} |
| 224 |
|
| 225 |
# Upload the current build artifacts |
| 226 |
gsutil -m cp -r "$LOCAL_STAGING_TEMPDIR/${BUILD_RELPATH%%/*}" "$GCS_ARCHIVE_ROOT" |
| 227 |
# Upload directory indices for subdirectories |
| 228 |
( |
| 229 |
cd "$LOCAL_BUILD_ROOT" |
| 230 |
find * -type d | while read -r directory |
| 231 |
do |
| 232 |
generate_directory_index "$directory" | gsutil -h 'Content-Type:text/html' cp - "$GCS_ARCHIVE_ROOT$BUILD_RELPATH$directory/$INDEX_FILENAME" |
| 233 |
done |
| 234 |
) |
| 235 |
# Upload the new /index.xml |
| 236 |
gsutil -h "Content-Type:application/xml" cp "$NEW_INDEX" "$GCS_INDEX" |
| 237 |
|
| 238 |
# Upload C# nugets to the dev nuget feed |
| 239 |
pushd "$UNZIPPED_CSHARP_PACKAGES" |
| 240 |
docker pull mcr.microsoft.com/dotnet/core/sdk:2.1 |
| 241 |
for nugetfile in *.nupkg |
| 242 |
do |
| 243 |
echo "Going to push $nugetfile" |
| 244 |
# use nuget from a docker container to push the nupkg |
| 245 |
set +x # IMPORTANT: avoid revealing the nuget api key by the command echo |
| 246 |
docker run -v "$(pwd):/nugets:ro" --rm=true mcr.microsoft.com/dotnet/core/sdk:2.1 bash -c "dotnet nuget push /nugets/$nugetfile -k $(cat ${KOKORO_GFILE_DIR}/artifactory_grpc_nuget_dev_api_key) --source https://grpc.jfrog.io/grpc/api/nuget/v3/grpc-nuget-dev" |
| 247 |
set -ex |
| 248 |
done |
| 249 |
popd |