Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | buildId="$1" |
| 5 | target="$2" |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 6 | sendUpToDateScan=false |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 7 | |
| 8 | function usage() { |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 9 | echo "usage: $0 <buildId> <target> [--include-up-to-date]" |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 10 | echo |
| 11 | echo "Downloads build scan information for the corresponding build and uploads it to the enterprise server configured in settings.gradle" |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 12 | 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 Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 14 | exit 1 |
| 15 | } |
| 16 | |
| 17 | if [ "$buildId" == "" ]; then |
| 18 | usage |
| 19 | fi |
| 20 | |
| 21 | if [ "$target" == "" ]; then |
| 22 | usage |
| 23 | fi |
| 24 | |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 25 | if [ "$3" != "" ]; then |
| 26 | if [ "$3" == "--include-up-to-date" ]; then |
| 27 | sendUpToDateScan=true |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 28 | else |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 29 | usage |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 30 | fi |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 31 | fi |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 32 | # find scan dir |
| 33 | if [ "$OUT_DIR" != "" ]; then |
| 34 | effectiveGradleUserHome="$OUT_DIR/.gradle" |
| 35 | else |
| 36 | if [ "$GRADLE_USER_HOME" != "" ]; then |
| 37 | effectiveGradleUserHome="$GRADLE_USER_HOME" |
| 38 | else |
| 39 | effectiveGradleUserHome="$HOME/.gradle" |
| 40 | fi |
| 41 | fi |
| 42 | scanDir="$effectiveGradleUserHome/build-scan-data" |
| 43 | |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 44 | function 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 Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 57 | function unzipScan() { |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 58 | filename="$1" |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 59 | echo |
| 60 | echo unzipping build scan |
| 61 | rm -rf "$scanDir" |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 62 | unzip -q /tmp/"$filename" -d "$scanDir" |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 63 | } |
Jeff Gaston | 1aadce0d | 2022-01-26 18:28:02 -0500 | [diff] [blame] | 64 | |
| 65 | function uploadScan() { |
| 66 | log="$scanDir/upload-failure.log" |
| 67 | rm -f "$log" |
| 68 | echo |
| 69 | echo uploading build scan |
| 70 | ./gradlew buildScanPublishPrevious |
| 71 | sleep 2 |
| 72 | if cat "$log" 2>/dev/null; then |
| 73 | echo upload failed |
| 74 | fi |
| 75 | } |
Jeff Gaston | 9b7c32c | 2022-03-09 19:00:51 -0500 | [diff] [blame] | 76 | |
| 77 | function sendScan() { |
| 78 | filename="$1" |
| 79 | downloadScan "$filename" |
| 80 | unzipScan "$filename" |
| 81 | uploadScan |
| 82 | } |
| 83 | |
| 84 | sendScan scan.zip |
| 85 | echo uploaded scan |
| 86 | if [ "$sendUpToDateScan" == "true" ]; then |
| 87 | sendScan scan-up-to-date.zip |
| 88 | echo uploaded scan of second, up-to-date build |
| 89 | fi |