aboutsummaryrefslogtreecommitdiff
path: root/update-prebuilts.sh
blob: 6d990af71d8775c86eacf5b1494217c5e5327ec2 (plain)
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
#!/bin/bash -e

# Copyright 2020 Google Inc. All rights reserved.
#
# Licensed 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.

# A script to update the Go prebuilts from a build completed on Android CI.

set -eo pipefail

if [ -z $1 ]; then
  echo "usage: $0 <build number>"
  exit 1
fi

readonly BUILD_NUMBER=$1
readonly GERRIT_TOPIC="update-go-${BUILD_NUMBER}"

cd "$(dirname $0)"

readonly tmpdir=$(mktemp -d)

function finish {
  if [ ! -z "${tmpdir}" ]; then
    rm -rf "${tmpdir}"
  fi
}
trap finish EXIT

function fetch_artifact() {
  local target=$1; shift
  local artifact=$1; shift
  local output=$1; shift
  /google/data/ro/projects/android/fetch_artifact \
    --branch aosp-build-tools-release \
    --bid ${BUILD_NUMBER} \
    --target ${target}\
    "${artifact}" "${output}"
}

# Downloads the relevant go.zip and creates a CL with its contents.
function upload_cl() {
  # aosp-build-tools-release target
  local target=$1; shift

  # os directory name of the go prebuilts
  local arch=$1; shift

  zipfile="${tmpdir}/${arch}.zip"

  echo "Downloading ${arch} go.zip from ab/${BUILD_NUMBER}.."
  fetch_artifact "${target}" go.zip "${zipfile}"

  pushd "../../prebuilts/go/${arch}" > /dev/null

  echo "Uploading new ${arch} go.zip to Gerrit.."
  repo start "${GERRIT_TOPIC}"

  git rm -rf .
  unzip -q -d "$(pwd)" "${zipfile}"
  git add -A .
  git commit -m "Update ${arch} Go prebuilts from ab/${BUILD_NUMBER}

https://ci.android.com/builds/branches/aosp-build-tools-release/grid?head=${BUILD_NUMBER}&tail=${BUILD_NUMBER}

Update script: toolchain/go/update-prebuilts.sh

Test: Treehugger presubmit"
  repo upload --cbr -t -y .

  popd
}

# upload_cl <aosp-build-tools-release target> <prebuilts dir>
upload_cl linux linux-x86
upload_cl darwin_mac darwin-x86

echo "Uploaded CLs: https://android-review.googlesource.com/q/topic:%22${GERRIT_TOPIC}%22+status:open"
echo "Done."