2 # Copyright 2018 The gRPC Authors
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
8 # http://www.apache.org/licenses/LICENSE-2.0
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.
20 cd "$(dirname "$0")/../../.."
22 GRPC_VERSION=$(grep -e "^ *version: " build_handwritten.yaml | head -n 1 | sed 's/.*: //')
24 INPUT_ARTIFACTS=$KOKORO_GFILE_DIR/github/grpc/artifacts
25 INDEX_FILENAME=index.xml
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/
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
38 LOCAL_STAGING_TEMPDIR=$(mktemp -d)
39 LOCAL_BUILD_ROOT=$LOCAL_STAGING_TEMPDIR/$BUILD_RELPATH
40 LOCAL_BUILD_INDEX=$LOCAL_BUILD_ROOT$INDEX_FILENAME
42 mkdir -p "$LOCAL_BUILD_ROOT"
44 find "$INPUT_ARTIFACTS" -type f
47 PROTOC_PLUGINS_ZIPPED_PACKAGES=$(mktemp -d)
48 for zip_dir in protoc_windows_{x86,x64}
50 zip -jr "$PROTOC_PLUGINS_ZIPPED_PACKAGES/grpc-$zip_dir-$GRPC_VERSION.zip" "$INPUT_ARTIFACTS/$zip_dir/"*
52 for tar_dir in protoc_linux_{x86,x64} protoc_macos_x64
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" .
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"
65 UNZIPPED_CSHARP_PACKAGES=$(mktemp -d)
66 unzip "$INPUT_ARTIFACTS/csharp_nugets_windows_dotnetcli.zip" -d "$UNZIPPED_CSHARP_PACKAGES"
68 "$UNZIPPED_CSHARP_PACKAGES"/*
69 "$INPUT_ARTIFACTS"/grpc_unity_package.[0-9]*.zip
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
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
83 PYTHON_GRPCIO_HEALTH_CHECKING_PACKAGES=(
84 "$INPUT_ARTIFACTS"/grpcio-health-checking-[0-9]*.tar.gz
86 PYTHON_GRPCIO_REFLECTION_PACKAGES=(
87 "$INPUT_ARTIFACTS"/grpcio-reflection-[0-9]*.tar.gz
89 PYTHON_GRPCIO_TESTING_PACKAGES=(
90 "$INPUT_ARTIFACTS"/grpcio-testing-[0-9]*.tar.gz
95 "$INPUT_ARTIFACTS"/grpc-[0-9]*.tgz
100 "$INPUT_ARTIFACTS"/grpc-[0-9]*.gem
101 "$INPUT_ARTIFACTS"/grpc-tools-[0-9]*.gem
104 function add_to_manifest() {
105 local artifact_type=$1
106 local artifact_file=$2
107 local artifact_prefix=$3
109 artifact_name=$(basename "$artifact_file")
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"
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' />
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">
132 <project>gRPC</project>
133 <repository>https://github.com/grpc/grpc</repository>
134 <branch>$BUILD_BRANCH_NAME</branch>
135 <commit>$BUILD_GIT_COMMIT</commit>
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
154 }> "$LOCAL_BUILD_INDEX"
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)
162 # Download the current /index.xml into $OLD_INDEX
163 gsutil cp "$GCS_INDEX" "$OLD_INDEX"
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.
170 <?xml version="1.0"?>
171 <?xml-stylesheet href="/web-assets/home.xsl" type="text/xsl"?>
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' />
182 tail --lines=+5 "$OLD_INDEX"
186 function generate_directory_index()
189 local current_directory_name
190 current_directory_name=$(basename "$target_dir")
193 <html xmlns="http://www.w3.org/1999/xhtml" lang="" xml:lang="">
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" />
200 <h1>Index of <a href="#"><code>$current_directory_name</code></a></h1>
202 <li><a href="#">.</a></li>
203 <li><a href="..">..</a></li>
208 find * -maxdepth 0 -type d -print | sort | while read -r line
210 echo " <li><a href='$line/'>$line/</a></li>"
212 find * -maxdepth 0 -type f -print | sort | while read -r line
214 echo " <li><a href='$line'>$line</a></li>"
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
229 cd "$LOCAL_BUILD_ROOT"
230 find * -type d | while read -r directory
232 generate_directory_index "$directory" | gsutil -h 'Content-Type:text/html' cp - "$GCS_ARCHIVE_ROOT$BUILD_RELPATH$directory/$INDEX_FILENAME"
235 # Upload the new /index.xml
236 gsutil -h "Content-Type:application/xml" cp "$NEW_INDEX" "$GCS_INDEX"
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
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"