blob: 79c60a42f810a12b27801b7aeb6c800f2f7ab041 [file] [log] [blame]
Jeff Gaston1aadce0d2022-01-26 18:28:02 -05001#!/bin/bash
2set -e
3
4buildId="$1"
5target="$2"
Jeff Gaston9b7c32c2022-03-09 19:00:51 -05006sendUpToDateScan=false
Jeff Gaston1aadce0d2022-01-26 18:28:02 -05007
8function usage() {
Jeff Gaston9b7c32c2022-03-09 19:00:51 -05009 echo "usage: $0 <buildId> <target> [--include-up-to-date]"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050010 echo
11 echo "Downloads build scan information for the corresponding build and uploads it to the enterprise server configured in settings.gradle"
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050012 echo
13 echo " --include-up-to-date Also upload scan-up-to-date.zip, the scan of the second build which should be mostly UP-TO-DATE"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050014 exit 1
15}
16
17if [ "$buildId" == "" ]; then
18 usage
19fi
20
21if [ "$target" == "" ]; then
22 usage
23fi
24
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050025if [ "$3" != "" ]; then
26 if [ "$3" == "--include-up-to-date" ]; then
27 sendUpToDateScan=true
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050028 else
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050029 usage
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050030 fi
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050031fi
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050032# find scan dir
Aurimas Liutikas99548e62024-12-03 08:40:18 -080033if [ -z "${OUT_DIR+x}" ] ; then
34 SCRIPT_PATH="$(cd $(dirname $0) && pwd -P)"
35 export OUT_DIR=$SCRIPT_PATH/../../../out
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050036fi
Aurimas Liutikas99548e62024-12-03 08:40:18 -080037effectiveGradleUserHome="$OUT_DIR/.gradle"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050038scanDir="$effectiveGradleUserHome/build-scan-data"
39
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050040function downloadScan() {
41 filename="$1"
42 echo downloading build scan from $buildId $target
43 if [ "$target" == "androidx_incremental" ]; then
44 downloadPath="incremental/$filename"
45 else
46 downloadPath="$filename"
47 fi
48 cd /tmp
49 /google/data/ro/projects/android/fetch_artifact --bid $buildId --target $target "$downloadPath"
50 cd -
51}
52
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050053function unzipScan() {
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050054 filename="$1"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050055 echo
56 echo unzipping build scan
57 rm -rf "$scanDir"
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050058 unzip -q /tmp/"$filename" -d "$scanDir"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050059}
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050060
61function uploadScan() {
62 log="$scanDir/upload-failure.log"
63 rm -f "$log"
64 echo
65 echo uploading build scan
Aurimas Liutikas628d3b52024-01-19 00:56:39 +000066 ./gradlew :buildScanPublishPrevious
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050067 sleep 2
68 if cat "$log" 2>/dev/null; then
69 echo upload failed
70 fi
71}
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050072
73function sendScan() {
74 filename="$1"
75 downloadScan "$filename"
76 unzipScan "$filename"
77 uploadScan
78}
79
Aurimas Liutikascb2e40a2025-02-25 08:31:54 -080080sendScan scan.1.zip
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050081echo uploaded scan
82if [ "$sendUpToDateScan" == "true" ]; then
83 sendScan scan-up-to-date.zip
84 echo uploaded scan of second, up-to-date build
85fi