|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +# Copyright The Kubernetes Authors. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Downloads release binaries from artifacts.k8s.io and uploads them |
| 18 | +# to the corresponding GitHub release, replacing the shipbot tool. |
| 19 | +# |
| 20 | +# Usage: promote-to-github.sh <version> |
| 21 | +# e.g. promote-to-github.sh 1.30.0 |
| 22 | + |
| 23 | +set -o errexit |
| 24 | +set -o nounset |
| 25 | +set -o pipefail |
| 26 | + |
| 27 | +REPO="kubernetes/kops" |
| 28 | +BASE_URL="https://artifacts.k8s.io/binaries/kops" |
| 29 | + |
| 30 | +# Binaries to upload: source-path -> github-name |
| 31 | +declare -A BINARIES=( |
| 32 | + ["darwin/amd64/kops"]="kops-darwin-amd64" |
| 33 | + ["darwin/amd64/kops.sha256"]="kops-darwin-amd64.sha256" |
| 34 | + ["darwin/arm64/kops"]="kops-darwin-arm64" |
| 35 | + ["darwin/arm64/kops.sha256"]="kops-darwin-arm64.sha256" |
| 36 | + ["linux/amd64/kops"]="kops-linux-amd64" |
| 37 | + ["linux/amd64/kops.sha256"]="kops-linux-amd64.sha256" |
| 38 | + ["linux/arm64/kops"]="kops-linux-arm64" |
| 39 | + ["linux/arm64/kops.sha256"]="kops-linux-arm64.sha256" |
| 40 | + ["windows/amd64/kops.exe"]="kops-windows-amd64" |
| 41 | + ["windows/amd64/kops.exe.sha256"]="kops-windows-amd64.sha256" |
| 42 | + ["linux/amd64/nodeup"]="nodeup-linux-amd64" |
| 43 | + ["linux/amd64/nodeup.sha256"]="nodeup-linux-amd64.sha256" |
| 44 | + ["linux/arm64/nodeup"]="nodeup-linux-arm64" |
| 45 | + ["linux/arm64/nodeup.sha256"]="nodeup-linux-arm64.sha256" |
| 46 | + ["linux/amd64/protokube"]="protokube-linux-amd64" |
| 47 | + ["linux/amd64/protokube.sha256"]="protokube-linux-amd64.sha256" |
| 48 | + ["linux/arm64/protokube"]="protokube-linux-arm64" |
| 49 | + ["linux/arm64/protokube.sha256"]="protokube-linux-arm64.sha256" |
| 50 | + ["linux/amd64/channels"]="channels-linux-amd64" |
| 51 | + ["linux/amd64/channels.sha256"]="channels-linux-amd64.sha256" |
| 52 | + ["linux/arm64/channels"]="channels-linux-arm64" |
| 53 | + ["linux/arm64/channels.sha256"]="channels-linux-arm64.sha256" |
| 54 | +) |
| 55 | + |
| 56 | +if [[ $# -ne 1 ]]; then |
| 57 | + echo "Usage: $0 <version>" >&2 |
| 58 | + echo " e.g. $0 1.30.0" >&2 |
| 59 | + exit 1 |
| 60 | +fi |
| 61 | + |
| 62 | +VERSION="$1" |
| 63 | +# Strip leading 'v' if provided |
| 64 | +VERSION="${VERSION#v}" |
| 65 | +TAG="v${VERSION}" |
| 66 | + |
| 67 | +if ! command -v gh &>/dev/null; then |
| 68 | + echo "Error: gh (GitHub CLI) is required but not found in PATH" >&2 |
| 69 | + exit 1 |
| 70 | +fi |
| 71 | + |
| 72 | +WORKDIR=$(mktemp -d) |
| 73 | +trap 'rm -rf "${WORKDIR}"' EXIT |
| 74 | + |
| 75 | +echo "Downloading binaries from ${BASE_URL}/${VERSION}/ ..." |
| 76 | + |
| 77 | +for source in "${!BINARIES[@]}"; do |
| 78 | + github_name="${BINARIES[$source]}" |
| 79 | + dest="${WORKDIR}/${github_name}" |
| 80 | + url="${BASE_URL}/${VERSION}/${source}" |
| 81 | + |
| 82 | + echo " ${source} -> ${github_name}" |
| 83 | + if ! curl -fsSL --retry 3 -o "${dest}" "${url}"; then |
| 84 | + echo "Error: failed to download ${url}" >&2 |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | +done |
| 88 | + |
| 89 | +echo "Uploading binaries to GitHub release ${TAG} ..." |
| 90 | + |
| 91 | +if ! gh release upload "${TAG}" --repo "${REPO}" "${WORKDIR}"/*; then |
| 92 | + echo "Error: failed to upload binaries to GitHub release ${TAG}" >&2 |
| 93 | + exit 1 |
| 94 | +fi |
0 commit comments