File: verify_rc.sh

package info (click to toggle)
golang-github-apache-arrow-go 18.2.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 32,200 kB
  • sloc: asm: 477,547; ansic: 5,369; cpp: 759; sh: 585; makefile: 319; python: 190; sed: 5
file content (229 lines) | stat: -rwxr-xr-x 5,656 bytes parent folder | download
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
#!/usr/bin/env 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.

set -eu

SOURCE_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
TOP_SOURCE_DIR="$(dirname "$(dirname "${SOURCE_DIR}")")"

if [ "$#" -ne 2 ]; then
  echo "Usage: $0 <version> <rc>"
  echo " e.g.: $0 18.0.0 1"
  exit 1
fi

set -o pipefail
set -x

VERSION="$1"
RC="$2"

ARROW_DIST_BASE_URL="https://dist.apache.org/repos/dist/dev/arrow"
DOWNLOAD_RC_BASE_URL="https://github.com/apache/arrow-go/releases/download/v${VERSION}-rc${RC}"
ARCHIVE_BASE_NAME="apache-arrow-go-${VERSION}"

: "${VERIFY_DEFAULT:=1}"
: "${VERIFY_DOWNLOAD:=${VERIFY_DEFAULT}}"
: "${VERIFY_FORCE_USE_GO_BINARY:=0}"
: "${VERIFY_SIGN:=${VERIFY_DEFAULT}}"

VERIFY_SUCCESS=no

setup_tmpdir() {
  cleanup() {
    go clean -modcache || :
    if [ "${VERIFY_SUCCESS}" = "yes" ]; then
      rm -rf "${VERIFY_TMPDIR}"
    else
      echo "Failed to verify release candidate. See ${VERIFY_TMPDIR} for details."
    fi
  }

  if [ -z "${VERIFY_TMPDIR:-}" ]; then
    VERIFY_TMPDIR="$(mktemp -d -t "$1.XXXXX")"
    trap cleanup EXIT
  else
    mkdir -p "${VERIFY_TMPDIR}"
  fi
}

download() {
  curl \
    --fail \
    --location \
    --remote-name \
    --show-error \
    --silent \
    "$1"
}

download_rc_file() {
  if [ "${VERIFY_DOWNLOAD}" -gt 0 ]; then
    download "${DOWNLOAD_RC_BASE_URL}/$1"
  else
    cp "${TOP_SOURCE_DIR}/$1" "$1"
  fi
}

import_gpg_keys() {
  if [ "${VERIFY_SIGN}" -gt 0 ]; then
    download "${ARROW_DIST_BASE_URL}/KEYS"
    gpg --import KEYS
  fi
}

if type shasum >/dev/null 2>&1; then
  sha256_verify="shasum -a 256 -c"
  sha512_verify="shasum -a 512 -c"
else
  sha256_verify="sha256sum -c"
  sha512_verify="sha512sum -c"
fi

fetch_archive() {
  download_rc_file "${ARCHIVE_BASE_NAME}.tar.gz"
  if [ "${VERIFY_SIGN}" -gt 0 ]; then
    download_rc_file "${ARCHIVE_BASE_NAME}.tar.gz.asc"
    gpg --verify "${ARCHIVE_BASE_NAME}.tar.gz.asc" "${ARCHIVE_BASE_NAME}.tar.gz"
  fi
  download_rc_file "${ARCHIVE_BASE_NAME}.tar.gz.sha256"
  ${sha256_verify} "${ARCHIVE_BASE_NAME}.tar.gz.sha256"
  download_rc_file "${ARCHIVE_BASE_NAME}.tar.gz.sha512"
  ${sha512_verify} "${ARCHIVE_BASE_NAME}.tar.gz.sha512"
}

ensure_source_directory() {
  tar xf "${ARCHIVE_BASE_NAME}".tar.gz

  if [ -d "${TOP_SOURCE_DIR}/arrow-testing/data" ]; then
    cp -a "${TOP_SOURCE_DIR}/arrow-testing" "${ARCHIVE_BASE_NAME}/"
  else
    git clone \
      https://github.com/apache/arrow-testing.git \
      "${ARCHIVE_BASE_NAME}/arrow-testing"
  fi
  if [ -d "${TOP_SOURCE_DIR}/parquet-testing/data" ]; then
    cp -a "${TOP_SOURCE_DIR}/parquet-testing" "${ARCHIVE_BASE_NAME}/"
  else
    git clone \
      https://github.com/apache/parquet-testing.git \
      "${ARCHIVE_BASE_NAME}/parquet-testing"
  fi

  ARROW_TEST_DATA="${ARCHIVE_BASE_NAME}/arrow-testing/data"
  export ARROW_TEST_DATA
  PARQUET_TEST_DATA="${ARCHIVE_BASE_NAME}/parquet-testing/data"
  export PARQUET_TEST_DATA
  PARQUET_TEST_BAD_DATA="${ARCHIVE_BASE_NAME}/parquet-testing/bad_data"
  export PARQUET_TEST_BAD_DATA
}

latest_go_version() {
  local -a options
  options=(
    --fail
    --location
    --show-error
    --silent
  )
  if [ -n "${GITHUB_TOKEN:-}" ]; then
    options+=("--header" "Authorization: Bearer ${GITHUB_TOKEN}")
  fi
  curl \
    "${options[@]}" \
    https://api.github.com/repos/golang/go/git/matching-refs/tags/go |
    grep -o '"ref": "refs/tags/go.*"' |
    tail -n 1 |
    sed \
      -e 's,^"ref": "refs/tags/go,,g' \
      -e 's/"$//g'
}

ensure_go() {
  if [ "${VERIFY_FORCE_USE_GO_BINARY}" -le 0 ]; then
    if go version; then
      GOPATH="${VERIFY_TMPDIR}/gopath"
      export GOPATH
      mkdir -p "${GOPATH}"
      return
    fi
  fi

  local go_version
  go_version=$(latest_go_version)
  local go_os
  go_os="$(uname)"
  case "${go_os}" in
  Darwin)
    go_os="darwin"
    ;;
  Linux)
    go_os="linux"
    ;;
  esac
  local go_arch
  go_arch="$(arch)"
  case "${go_arch}" in
  i386 | x86_64)
    go_arch="amd64"
    ;;
  aarch64)
    go_arch="arm64"
    ;;
  esac
  local go_binary_tar_gz
  go_binary_tar_gz="go${go_version}.${go_os}-${go_arch}.tar.gz"
  local go_binary_url
  go_binary_url="https://go.dev/dl/${go_binary_tar_gz}"
  curl \
    --fail \
    --location \
    --output "${go_binary_tar_gz}" \
    --show-error \
    --silent \
    "${go_binary_url}"
  tar xf "${go_binary_tar_gz}"
  GOROOT="$(pwd)/go"
  export GOROOT
  GOPATH="$(pwd)/gopath"
  export GOPATH
  mkdir -p "${GOPATH}"
  PATH="${GOROOT}/bin:${GOPATH}/bin:${PATH}"
}

test_source_distribution() {
  "${TOP_SOURCE_DIR}/ci/scripts/build.sh" "$(pwd)"
  "${TOP_SOURCE_DIR}/ci/scripts/test.sh" "$(pwd)"
  # TODO: Integration test
}

setup_tmpdir "arrow-go-${VERSION}-${RC}"
echo "Working in sandbox ${VERIFY_TMPDIR}"
cd "${VERIFY_TMPDIR}"

import_gpg_keys
fetch_archive
ensure_source_directory
ensure_go
pushd "${ARCHIVE_BASE_NAME}"
test_source_distribution
popd

VERIFY_SUCCESS=yes
echo "RC looks good!"