blob: 4e6e99f28d8867c8617b7863c5673318f618e06e [file] [log] [blame]
#!/usr/bin/env bash
# Copyright 2016 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style
# license that can be found in the LICENSE file.
set -euf -o pipefail
readonly JIRI_REPO_URL="https://fuchsia.googlesource.com/jiri"
readonly GS_BUCKET_URL="https://fuchsia-build.storage.googleapis.com/jiri"
# Accept the first argument as a list of OSes to build for. Possible values
# are valid GOOS strings from [linux darwin]
if [[ $# -ge 1 ]]; then
readonly TARGETS="${1}"
else
readonly TARGETS="linux darwin"
fi
# Accept the first argument as a list of OSes to build for. Possible values
# are valid GOARCH strings from [amd64 arm64]
if [[ $# -eq 2 ]]; then
readonly ARCHS="${2}"
else
readonly ARCHS="amd64 arm64"
fi
# Determine and validate the version of jiri.
readonly HOST_OS=$(uname | tr '[:upper:]' '[:lower:]')
readonly COMMIT_URL="${JIRI_REPO_URL}/+refs/heads/master?format=JSON"
readonly VERSION=$(curl -sSf "${COMMIT_URL}" | sed -n 's/.*"value": "\([0-9a-f]\{40\}\)"/\1/p')
if [[ -z ${VERSION} ]]; then
echo "Cannot determine the latest jiri version" 1>&2
exit 1
fi
# Do all our work in a temporary directory, then rm it when we're done.
readonly TEMP_DIR="$(mktemp -d)"
trap "rm -rf -- "${TEMP_DIR}"" EXIT
failed=false
RED='\033[0;31m'
NC='\033[0m'
for target in ${TARGETS}; do
for arch in ${ARCHS}; do
if [[ "$target" == "darwin" && "$arch" == "arm64" ]]; then
continue
fi
os=$(echo ${target} | sed 's/darwin/mac/')
tmpdir="${TEMP_DIR}/jiri-${os}-${arch}"
mkdir -p ${tmpdir}
# Download the jiri binary.
if ! curl -sSf -o "${tmpdir}/jiri" "${GS_BUCKET_URL}/${target}-${arch}/${VERSION}"; then
echo -e "${RED}Failed downloading prebuilt jiri binary.${NC}" 1>&2
echo -e "${RED}${GS_BUCKET_URL}/${target}-${arch}/${VERSION}${NC}"
if [[ "$arch" != "arm64" ]]; then
failed=true
fi
continue
fi
chmod 755 "${tmpdir}/jiri"
# Upload the jiri binary to CIPD
cipd create -name "fuchsia/tools/jiri/${os}-${arch}" -in "${tmpdir}" -ref latest -tag "git_repository:https://fuchsia.googlesource.com/jiri" -tag "git_revision:${VERSION}"
done
done
# fail if any os-arch failed
if [[ "$failed" = true ]]; then
echo -e "${RED}Failure${NC}"
exit 1
fi