blob: 884556741b67c1c1f91fab283491186998adb7eb [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
33if [ "$OUT_DIR" != "" ]; then
34 effectiveGradleUserHome="$OUT_DIR/.gradle"
35else
36 if [ "$GRADLE_USER_HOME" != "" ]; then
37 effectiveGradleUserHome="$GRADLE_USER_HOME"
38 else
39 effectiveGradleUserHome="$HOME/.gradle"
40 fi
41fi
42scanDir="$effectiveGradleUserHome/build-scan-data"
43
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050044function downloadScan() {
45 filename="$1"
46 echo downloading build scan from $buildId $target
47 if [ "$target" == "androidx_incremental" ]; then
48 downloadPath="incremental/$filename"
49 else
50 downloadPath="$filename"
51 fi
52 cd /tmp
53 /google/data/ro/projects/android/fetch_artifact --bid $buildId --target $target "$downloadPath"
54 cd -
55}
56
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050057function unzipScan() {
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050058 filename="$1"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050059 echo
60 echo unzipping build scan
61 rm -rf "$scanDir"
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050062 unzip -q /tmp/"$filename" -d "$scanDir"
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050063}
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050064
65function uploadScan() {
66 log="$scanDir/upload-failure.log"
67 rm -f "$log"
68 echo
69 echo uploading build scan
Aurimas Liutikas628d3b52024-01-19 00:56:39 +000070 ./gradlew :buildScanPublishPrevious
Jeff Gaston1aadce0d2022-01-26 18:28:02 -050071 sleep 2
72 if cat "$log" 2>/dev/null; then
73 echo upload failed
74 fi
75}
Jeff Gaston9b7c32c2022-03-09 19:00:51 -050076
77function sendScan() {
78 filename="$1"
79 downloadScan "$filename"
80 unzipScan "$filename"
81 uploadScan
82}
83
84sendScan scan.zip
85echo uploaded scan
86if [ "$sendUpToDateScan" == "true" ]; then
87 sendScan scan-up-to-date.zip
88 echo uploaded scan of second, up-to-date build
89fi