Jeff Gaston | fb64aca | 2023-06-15 12:26:24 -0400 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | set -e |
| 3 | |
| 4 | function usage() { |
| 5 | echo "Usage: $0 <buildId> <target> [<numBuilds>]" |
| 6 | echo "Fetches the build number log for <buildId> <target> and reruns the last <numBuilds> of that target that happened on the corresponding server" |
| 7 | exit 1 |
| 8 | } |
| 9 | |
| 10 | buildId="$1" |
| 11 | target="$2" |
| 12 | if [ "$buildId" == "" ]; then |
| 13 | usage |
| 14 | fi |
| 15 | if [ "$target" == "" ]; then |
| 16 | usage |
| 17 | fi |
| 18 | numBuilds="$3" |
| 19 | if [ "$numBuilds" == "" ]; then |
| 20 | numBuilds="2" |
| 21 | fi |
| 22 | |
| 23 | cd "$(dirname $0)/.." |
| 24 | |
| 25 | function cleanup() { |
| 26 | ./gradlew --stop || true |
| 27 | rm ../../out -rf |
| 28 | mkdir -p ../../out |
| 29 | } |
| 30 | cleanup |
| 31 | |
| 32 | function echoAndDo() { |
| 33 | echo "$*" |
| 34 | eval "$*" |
| 35 | } |
| 36 | |
| 37 | function fetch_artifact() { |
| 38 | fetchBuildId="$1" |
| 39 | remotePath="$2" |
| 40 | localDir="$3" |
| 41 | cd "$localDir" |
| 42 | echoAndDo /google/data/ro/projects/android/fetch_artifact --bid "$fetchBuildId" --target "$target" "$remotePath" |
| 43 | cd - |
| 44 | } |
| 45 | function downloadBuildNumberLog() { |
| 46 | if [ "$target" == "androidx_incremental" ]; then |
| 47 | buildNumberLog=incremental/build_number.log |
| 48 | else |
| 49 | buildNumberLog=build_number.log |
| 50 | fi |
| 51 | echo Downloading build number history for build $buildId |
| 52 | fetch_artifact "$buildId" "$buildNumberLog" ../../out |
| 53 | } |
| 54 | downloadBuildNumberLog |
| 55 | |
| 56 | buildNumberHistory="$(cat ../../out/build_number.log | tail -n "$numBuilds")" |
| 57 | echo Will run $target for sources from these builds: $buildNumberHistory . |
| 58 | |
| 59 | function checkoutSources() { |
| 60 | checkoutBuildId="$1" |
| 61 | echo checking out sources for build $checkoutBuildId |
| 62 | |
| 63 | fetch_artifact "$checkoutBuildId" BUILD_INFO ../../out/ |
| 64 | superprojectRevision="$(jq -r ".parsed_manifest.superproject.revision" ../../out/BUILD_INFO)" |
| 65 | |
| 66 | echo checking out superproject revision $superprojectRevision |
| 67 | |
| 68 | cd ../../ |
| 69 | git fetch origin "$superprojectRevision" |
| 70 | git checkout "$superprojectRevision" |
| 71 | git submodule update |
| 72 | cd - |
| 73 | echo done checking out sources for build $checkoutBuildId |
| 74 | } |
| 75 | function runBuild() { |
| 76 | bash "./busytown/$target.sh" |
| 77 | } |
| 78 | |
| 79 | for previousBuildId in $buildNumberHistory; do |
| 80 | checkoutSources $previousBuildId |
| 81 | if runBuild; then |
| 82 | echo build of $previousBuildId succeeded |
| 83 | else |
| 84 | echo build of $previousBuildId failed |
| 85 | exit 1 |
| 86 | fi |
| 87 | done |