1#!/bin/bash -e 2 3# Copyright 2020 Google Inc. All rights reserved. 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# A script to update the Go prebuilts from a build completed on Android CI. 18 19set -eo pipefail 20 21if [ -z $1 ]; then 22 echo "usage: $0 <build number>" 23 exit 1 24fi 25 26readonly BUILD_NUMBER=$1 27readonly GERRIT_TOPIC="update-go-${BUILD_NUMBER}" 28 29cd "$(dirname $0)" 30 31readonly tmpdir=$(mktemp -d) 32 33function finish { 34 if [ ! -z "${tmpdir}" ]; then 35 rm -rf "${tmpdir}" 36 fi 37} 38trap finish EXIT 39 40function fetch_artifact() { 41 local target=$1; shift 42 local artifact=$1; shift 43 local output=$1; shift 44 /google/data/ro/projects/android/fetch_artifact \ 45 --branch aosp-build-tools-release \ 46 --bid ${BUILD_NUMBER} \ 47 --target ${target}\ 48 "${artifact}" "${output}" 49} 50 51# Downloads the relevant go.zip and creates a CL with its contents. 52function upload_cl() { 53 # aosp-build-tools-release target 54 local target=$1; shift 55 56 # os directory name of the go prebuilts 57 local arch=$1; shift 58 59 zipfile="${tmpdir}/${arch}.zip" 60 61 echo "Downloading ${arch} go.zip from ab/${BUILD_NUMBER}.." 62 fetch_artifact "${target}" go.zip "${zipfile}" 63 64 pushd "../../prebuilts/go/${arch}" > /dev/null 65 66 echo "Uploading new ${arch} go.zip to Gerrit.." 67 repo start "${GERRIT_TOPIC}" 68 69 git rm -rf . 70 unzip -q -d "$(pwd)" "${zipfile}" 71 git add -A . 72 git commit -m "Update ${arch} Go prebuilts from ab/${BUILD_NUMBER} 73 74https://ci.android.com/builds/branches/aosp-build-tools-release/grid?head=${BUILD_NUMBER}&tail=${BUILD_NUMBER} 75 76Update script: toolchain/go/update-prebuilts.sh 77 78Test: Treehugger presubmit" 79 repo upload --cbr -t -y . -o banned-words~skip -o nokeycheck 80 81 popd 82} 83 84# upload_cl <aosp-build-tools-release target> <prebuilts dir> 85upload_cl linux linux-x86 86upload_cl darwin_mac darwin-x86 87 88echo "Uploaded CLs: https://android-review.googlesource.com/q/topic:%22${GERRIT_TOPIC}%22+status:open" 89echo "Done." 90