aboutsummaryrefslogtreecommitdiffhomepage
path: root/tools/internal_ci/linux/grpc_publish_packages.sh
blob: 24bb4880ed8ef5288f74d607384a69bf8849f952 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/bin/bash
# Copyright 2018 The gRPC Authors
#
# Licensed 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.

set -ex

shopt -s nullglob

INPUT_ARTIFACTS=$KOKORO_GFILE_DIR/github/grpc/artifacts
INDEX_FILENAME=index.xml

BUILD_ID=${KOKORO_BUILD_ID:-$(uuidgen)}
BUILD_BRANCH_NAME=master
BUILD_GIT_COMMIT=${KOKORO_GIT_COMMIT:-unknown}
BUILD_TIMESTAMP=$(date -Iseconds)
BUILD_RELPATH=$(date "+%Y/%m")/$BUILD_ID/

GCS_ROOT=gs://packages.grpc.io/
GCS_ARCHIVE_PREFIX=archive/
GCS_ARCHIVE_ROOT=$GCS_ROOT$GCS_ARCHIVE_PREFIX
GCS_INDEX=$GCS_ROOT$INDEX_FILENAME

LOCAL_STAGING_TEMPDIR=$(mktemp -d)
LOCAL_BUILD_ROOT=$LOCAL_STAGING_TEMPDIR/$BUILD_RELPATH
LOCAL_BUILD_INDEX=$LOCAL_BUILD_ROOT$INDEX_FILENAME

mkdir -p "$LOCAL_BUILD_ROOT"

find "$INPUT_ARTIFACTS" -type f

UNZIPPED_CSHARP_PACKAGES=$(mktemp -d)
unzip "$INPUT_ARTIFACTS/csharp_nugets_windows_dotnetcli.zip" -d "$UNZIPPED_CSHARP_PACKAGES"
CSHARP_PACKAGES=(
  "$UNZIPPED_CSHARP_PACKAGES"/*
)

PYTHON_PACKAGES=(
  "$INPUT_ARTIFACTS"/grpcio-[0-9]*.tar.gz
  "$INPUT_ARTIFACTS"/grpcio-[0-9]*.whl
  "$INPUT_ARTIFACTS"/python_linux_extra_arm*/grpcio-[0-9]*.whl

  "$INPUT_ARTIFACTS"/grpcio-tools-[0-9]*.tar.gz
  "$INPUT_ARTIFACTS"/grpcio_tools-[0-9]*.whl
  "$INPUT_ARTIFACTS"/python_linux_extra_arm*/grpcio_tools-[0-9]*.whl

  "$INPUT_ARTIFACTS"/grpcio-health-checking-[0-9]*.tar.gz
  "$INPUT_ARTIFACTS"/grpcio-reflection-[0-9]*.tar.gz
  "$INPUT_ARTIFACTS"/grpcio-testing-[0-9]*.tar.gz
)

PHP_PACKAGES=(
  "$INPUT_ARTIFACTS"/grpc-[0-9]*.tgz
)

RUBY_PACKAGES=(
  "$INPUT_ARTIFACTS"/grpc-[0-9]*.gem
  "$INPUT_ARTIFACTS"/grpc-tools-[0-9]*.gem
)

function add_to_manifest() {
  local artifact_type=$1
  local artifact_file=$2
  local artifact_name
  artifact_name=$(basename "$artifact_file")
  local artifact_sha256
  artifact_sha256=$(openssl sha256 -r "$artifact_file" | cut -d " " -f 1)
  local artifact_target=$LOCAL_BUILD_ROOT/$artifact_type
  mkdir -p "$artifact_target"
  cp "$artifact_file" "$artifact_target"
  cat <<EOF
    <artifact name='$artifact_name'
              type='$artifact_type'
              path='$artifact_type/$artifact_name'
              sha256='$artifact_sha256' />
EOF
}

{
  cat <<EOF
<?xml version="1.0"?>
<?xml-stylesheet href="/web-assets/build-201807.xsl" type="text/xsl"?>
<build id='$BUILD_ID' timestamp='$BUILD_TIMESTAMP'>
  <metadata>
    <project>gRPC</project>
    <repository>https://github.com/grpc/grpc</repository>
    <branch>$BUILD_BRANCH_NAME</branch>
    <commit>$BUILD_GIT_COMMIT</commit>
  </metadata>
  <artifacts>
EOF

  for pkg in "${CSHARP_PACKAGES[@]}"; do add_to_manifest csharp "$pkg"; done
  for pkg in "${PHP_PACKAGES[@]}"; do add_to_manifest php "$pkg"; done
  for pkg in "${PYTHON_PACKAGES[@]}"; do add_to_manifest python "$pkg"; done
  for pkg in "${RUBY_PACKAGES[@]}"; do add_to_manifest ruby "$pkg"; done

  cat <<EOF
  </artifacts>
</build>
EOF
}> "$LOCAL_BUILD_INDEX"

LOCAL_BUILD_INDEX_SHA256=$(openssl sha256 -r "$LOCAL_BUILD_INDEX" | cut -d " " -f 1)

OLD_INDEX=$(mktemp)
NEW_INDEX=$(mktemp)

# Download the current /index.xml into $OLD_INDEX
gsutil cp "$GCS_INDEX" "$OLD_INDEX"

{
  # we want to add an entry as the first child under <builds> tag
  # we can get by without a real XML parser by rewriting the header,
  # injecting our new tag, and then dumping the rest of the file as is.
  cat <<EOF
<?xml version="1.0"?>
<?xml-stylesheet href="/web-assets/home.xsl" type="text/xsl"?>
<packages>
  <builds>
    <build id='$BUILD_ID'
           timestamp='$BUILD_TIMESTAMP'
           branch='$BUILD_BRANCH_NAME'
           commit='$BUILD_GIT_COMMIT'
           path='$GCS_ARCHIVE_PREFIX$BUILD_RELPATH$INDEX_FILENAME'
           sha256='$LOCAL_BUILD_INDEX_SHA256' />
EOF
  tail --lines=+5 "$OLD_INDEX"
}> "$NEW_INDEX"

# Upload the current build artifacts
gsutil -m cp -r "$LOCAL_STAGING_TEMPDIR/${BUILD_RELPATH%%/*}" "$GCS_ARCHIVE_ROOT"
# Upload the new /index.xml
gsutil -h "Content-Type:application/xml" cp "$NEW_INDEX" "$GCS_INDEX"