|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Licensed to the Apache Software Foundation (ASF) under one |
| 4 | +# or more contributor license agreements. See the NOTICE file |
| 5 | +# distributed with this work for additional information |
| 6 | +# regarding copyright ownership. The ASF licenses this file |
| 7 | +# to you under the Apache License, Version 2.0 (the |
| 8 | +# "License"); you may not use this file except in compliance |
| 9 | +# with the License. You may obtain a copy of the License at |
| 10 | +# |
| 11 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +# |
| 13 | +# Unless required by applicable law or agreed to in writing, |
| 14 | +# software distributed under the License is distributed on an |
| 15 | +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 16 | +# KIND, either express or implied. See the License for the |
| 17 | +# specific language governing permissions and limitations |
| 18 | +# under the License. |
| 19 | + |
| 20 | +set -euo pipefail |
| 21 | + |
| 22 | +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) |
| 23 | +SOURCE_ROOT=$(cd "${SCRIPT_DIR}/../.." && pwd) |
| 24 | + |
| 25 | +RELEASE_VERSION="" |
| 26 | +GIT_REF="" |
| 27 | +OUTPUT_DIR="${SOURCE_ROOT}/release" |
| 28 | +SIGNING_KEY="" |
| 29 | + |
| 30 | +usage() { |
| 31 | + cat <<'EOF' |
| 32 | +Create an Apache Paimon C++ source release from an immutable Git ref. |
| 33 | +
|
| 34 | +Usage: |
| 35 | + create_source_release.sh --version VERSION --git-ref REF [options] |
| 36 | +
|
| 37 | +Required: |
| 38 | + --version VERSION Release version, for example 0.2.3 |
| 39 | + --git-ref REF Commit or signed RC tag to archive |
| 40 | +
|
| 41 | +Options: |
| 42 | + --output-dir DIR Output directory (default: <repository>/release) |
| 43 | + --signing-key KEY_ID Create an ASCII-armored detached OpenPGP signature |
| 44 | + -h, --help Show this help |
| 45 | +
|
| 46 | +The script creates: |
| 47 | + apache-paimon-cpp-VERSION-src.tgz |
| 48 | + apache-paimon-cpp-VERSION-src.tgz.sha512 |
| 49 | + apache-paimon-cpp-VERSION-src.tgz.asc (when --signing-key is provided) |
| 50 | +
|
| 51 | +Existing artifacts are never overwritten. |
| 52 | +EOF |
| 53 | +} |
| 54 | + |
| 55 | +fail() { |
| 56 | + echo "Error: $*" >&2 |
| 57 | + exit 1 |
| 58 | +} |
| 59 | + |
| 60 | +calculate_sha512() { |
| 61 | + local file=$1 |
| 62 | + if command -v sha512sum >/dev/null 2>&1; then |
| 63 | + sha512sum "${file}" | awk '{print $1}' |
| 64 | + elif command -v shasum >/dev/null 2>&1; then |
| 65 | + shasum -a 512 "${file}" | awk '{print $1}' |
| 66 | + else |
| 67 | + fail "sha512sum or shasum is required" |
| 68 | + fi |
| 69 | +} |
| 70 | + |
| 71 | +while [[ $# -gt 0 ]]; do |
| 72 | + case "$1" in |
| 73 | + --version) |
| 74 | + [[ $# -ge 2 ]] || fail "--version requires a value" |
| 75 | + RELEASE_VERSION=$2 |
| 76 | + shift 2 |
| 77 | + ;; |
| 78 | + --git-ref) |
| 79 | + [[ $# -ge 2 ]] || fail "--git-ref requires a value" |
| 80 | + GIT_REF=$2 |
| 81 | + shift 2 |
| 82 | + ;; |
| 83 | + --output-dir) |
| 84 | + [[ $# -ge 2 ]] || fail "--output-dir requires a value" |
| 85 | + OUTPUT_DIR=$2 |
| 86 | + shift 2 |
| 87 | + ;; |
| 88 | + --signing-key) |
| 89 | + [[ $# -ge 2 ]] || fail "--signing-key requires a value" |
| 90 | + SIGNING_KEY=$2 |
| 91 | + shift 2 |
| 92 | + ;; |
| 93 | + -h|--help) |
| 94 | + usage |
| 95 | + exit 0 |
| 96 | + ;; |
| 97 | + *) |
| 98 | + fail "unknown argument: $1" |
| 99 | + ;; |
| 100 | + esac |
| 101 | +done |
| 102 | + |
| 103 | +[[ -n "${RELEASE_VERSION}" ]] || fail "--version is required" |
| 104 | +[[ -n "${GIT_REF}" ]] || fail "--git-ref is required" |
| 105 | +[[ "${RELEASE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]] || |
| 106 | + fail "release version must use MAJOR.MINOR.PATCH format" |
| 107 | + |
| 108 | +git -C "${SOURCE_ROOT}" rev-parse --verify "${GIT_REF}^{commit}" >/dev/null 2>&1 || |
| 109 | + fail "Git ref does not resolve to a commit: ${GIT_REF}" |
| 110 | + |
| 111 | +for required_file in CMakeLists.txt LICENSE NOTICE; do |
| 112 | + git -C "${SOURCE_ROOT}" cat-file -e "${GIT_REF}:${required_file}" 2>/dev/null || |
| 113 | + fail "${required_file} is missing from ${GIT_REF}" |
| 114 | +done |
| 115 | + |
| 116 | +CMAKE_VERSION=$( |
| 117 | + git -C "${SOURCE_ROOT}" show "${GIT_REF}:CMakeLists.txt" | |
| 118 | + sed -n 's/^[[:space:]]*VERSION[[:space:]]\+\([0-9][0-9.]*\).*$/\1/p' | |
| 119 | + head -n 1 |
| 120 | +) |
| 121 | +[[ "${CMAKE_VERSION}" == "${RELEASE_VERSION}" ]] || |
| 122 | + fail "CMake version ${CMAKE_VERSION:-<missing>} does not match ${RELEASE_VERSION}" |
| 123 | + |
| 124 | +DOCS_VERSION=$( |
| 125 | + git -C "${SOURCE_ROOT}" show "${GIT_REF}:docs/source/conf.py" | |
| 126 | + sed -n 's/^version = "\([^"]*\)"$/\1/p' | |
| 127 | + head -n 1 |
| 128 | +) |
| 129 | +[[ "${DOCS_VERSION}" == "${RELEASE_VERSION}" ]] || |
| 130 | + fail "documentation version ${DOCS_VERSION:-<missing>} does not match ${RELEASE_VERSION}" |
| 131 | + |
| 132 | +ARTIFACT_NAME="apache-paimon-cpp-${RELEASE_VERSION}-src.tgz" |
| 133 | +ARCHIVE_ROOT="paimon-cpp-${RELEASE_VERSION}" |
| 134 | + |
| 135 | +mkdir -p "${OUTPUT_DIR}" |
| 136 | +OUTPUT_DIR=$(cd "${OUTPUT_DIR}" && pwd) |
| 137 | + |
| 138 | +for suffix in "" ".sha512" ".asc"; do |
| 139 | + [[ ! -e "${OUTPUT_DIR}/${ARTIFACT_NAME}${suffix}" ]] || |
| 140 | + fail "refusing to overwrite ${OUTPUT_DIR}/${ARTIFACT_NAME}${suffix}" |
| 141 | +done |
| 142 | + |
| 143 | +TEMP_DIR=$(mktemp -d) |
| 144 | +trap 'rm -rf "${TEMP_DIR}"' EXIT |
| 145 | + |
| 146 | +echo "Creating ${ARTIFACT_NAME} from ${GIT_REF}..." |
| 147 | +git -C "${SOURCE_ROOT}" -c tar.umask=0022 archive \ |
| 148 | + --format=tar \ |
| 149 | + --prefix="${ARCHIVE_ROOT}/" \ |
| 150 | + "${GIT_REF}" | |
| 151 | + gzip -n >"${TEMP_DIR}/${ARTIFACT_NAME}" |
| 152 | + |
| 153 | +SHA512=$(calculate_sha512 "${TEMP_DIR}/${ARTIFACT_NAME}") |
| 154 | +printf '%s %s\n' "${SHA512}" "${ARTIFACT_NAME}" \ |
| 155 | + >"${TEMP_DIR}/${ARTIFACT_NAME}.sha512" |
| 156 | + |
| 157 | +if [[ -n "${SIGNING_KEY}" ]]; then |
| 158 | + command -v gpg >/dev/null 2>&1 || fail "gpg is required to sign the artifact" |
| 159 | + echo "Signing ${ARTIFACT_NAME} with ${SIGNING_KEY}..." |
| 160 | + gpg --armor \ |
| 161 | + --local-user "${SIGNING_KEY}" \ |
| 162 | + --detach-sign \ |
| 163 | + --output "${TEMP_DIR}/${ARTIFACT_NAME}.asc" \ |
| 164 | + "${TEMP_DIR}/${ARTIFACT_NAME}" |
| 165 | +fi |
| 166 | + |
| 167 | +mv "${TEMP_DIR}/${ARTIFACT_NAME}" "${OUTPUT_DIR}/" |
| 168 | +mv "${TEMP_DIR}/${ARTIFACT_NAME}.sha512" "${OUTPUT_DIR}/" |
| 169 | +if [[ -n "${SIGNING_KEY}" ]]; then |
| 170 | + mv "${TEMP_DIR}/${ARTIFACT_NAME}.asc" "${OUTPUT_DIR}/" |
| 171 | +fi |
| 172 | + |
| 173 | +echo "Created release artifacts in ${OUTPUT_DIR}:" |
| 174 | +echo " ${ARTIFACT_NAME}" |
| 175 | +echo " ${ARTIFACT_NAME}.sha512" |
| 176 | +if [[ -n "${SIGNING_KEY}" ]]; then |
| 177 | + echo " ${ARTIFACT_NAME}.asc" |
| 178 | +else |
| 179 | + echo " Signature not created; pass --signing-key for an official release candidate." |
| 180 | +fi |
0 commit comments