Julia McClellan | 7434c11 | 2022-11-21 14:12:47 -0500 | [diff] [blame] | 1 | #!/bin/bash |
| 2 | # |
| 3 | # Script to generate a CL with Android Test Hub test dashboard configurations |
| 4 | # for all libraries, which will display recent test failures. The test dashboard |
| 5 | # with failures for all AndroidX libraries is at go/androidx-ath, each of these |
| 6 | # dashboards will display a subset of these failures. |
| 7 | # |
| 8 | # Creates the set of libraries by grouping the test configs from the latest |
| 9 | # build by prefix. For libraries that already have test dashboards, just the |
| 10 | # query line is updated. |
| 11 | # |
| 12 | # If the library flag is used, the configuration is created/updated for just the |
| 13 | # one provided library instead of for all libraries. |
| 14 | # |
| 15 | # Sample usage to create/update dashboards for all libraries: |
| 16 | # |
| 17 | # ./development/create_library_test_dashboard.sh |
| 18 | # |
| 19 | # Sample usage to create/update dashboard for just the paging library: |
| 20 | # |
| 21 | # ./development/create_library_test_dashboard.sh --library paging |
| 22 | |
| 23 | source gbash.sh || exit |
| 24 | |
| 25 | DEFINE_string library "" "If provided, the one library to create a dashboard for." |
| 26 | |
| 27 | # Parse the command line arguments |
| 28 | gbash::init_google "$@" |
| 29 | |
| 30 | printf "\n" |
| 31 | printf "=================================================================== \n" |
| 32 | printf "== Fetch test configs from the latest green builds \n" |
| 33 | printf "=================================================================== \n" |
| 34 | |
| 35 | # Fetch entries from both branches, as they can be different |
| 36 | branches=("aosp-androidx-main" "androidx-platform-dev") |
| 37 | |
| 38 | allZipEntries="" |
| 39 | for branch in ${branches[@]}; do |
| 40 | # Find the ID of the latest build |
| 41 | # --latest and --list_zip_entries don't work together for fetch_artifact: b/226554339 |
| 42 | latestBuild=$(/google/data/ro/projects/android/ab lkgb \ |
| 43 | --branch $branch --target androidx_device_tests \ |
| 44 | --raw --custom_raw_format '{o[buildId]}') |
| 45 | if [ -z "$latestBuild" ]; then |
| 46 | printf "ERROR: Failed to fetch ID of latest green build for $branch \n" |
| 47 | exit |
| 48 | else |
| 49 | printf "Using latest green build $latestBuild of $branch \n" |
| 50 | fi |
| 51 | |
| 52 | # Get the list of test configs from the latest build |
| 53 | branchZipEntries=$(/google/data/ro/projects/android/fetch_artifact \ |
| 54 | --bid $latestBuild --target androidx_device_tests \ |
| 55 | --list_zip_entries androidTest.zip) |
| 56 | |
| 57 | if [ -z "$branchZipEntries" ]; then |
| 58 | printf "ERROR: Failed to fetch test configs from build $latestBuild for $branch \n" |
| 59 | exit |
| 60 | fi |
| 61 | |
| 62 | allZipEntries+="$branchZipEntries\n" |
| 63 | done |
| 64 | |
| 65 | # Create list of unique .xml file names |
| 66 | testZipEntries=$(grep ".xml" <<< $allZipEntries | sort | uniq) |
| 67 | |
| 68 | # Use the one library provided, or all library names (based on prefixes of the |
| 69 | # test entries) if no library was provided. |
| 70 | if [ -z $FLAGS_library ]; then |
| 71 | # The config file names are of the form `library-rest-of-config-name.xml` or |
| 72 | # `libraryRestOfConfigName.xml`. Truncate them to just `library`. |
| 73 | libraryNames=$(sed 's/\(\([a-z]\|[0-9]\)*\)\([A-Z]\|-\).*/\1/' <<< $testZipEntries \ |
| 74 | | uniq) |
| 75 | else |
| 76 | libraryNames=$FLAGS_library |
| 77 | fi |
| 78 | |
| 79 | printf "\n" |
| 80 | printf "=================================================================== \n" |
| 81 | printf "== Create (if needed) and sync g4 workspace \n" |
| 82 | printf "=================================================================== \n" |
| 83 | |
| 84 | client="$(p4 g4d -f androidx-test-dashboards --multichange)" |
| 85 | cd "$client" |
| 86 | |
| 87 | # Revert all local changes to prevent merge conflicts when syncing. |
| 88 | # This is OK since we always want to start with a fresh CitC client |
| 89 | g4 revert ... |
| 90 | g4 sync |
| 91 | |
| 92 | printf "\n" |
| 93 | printf "=================================================================== \n" |
| 94 | printf "== Create a CL with the test dashboard configuration \n" |
| 95 | printf "=================================================================== \n" |
| 96 | |
| 97 | for library in $libraryNames; do |
| 98 | filePath="wireless/android/busytown/ath_config/configs/prod/androidx/$library.gcl" |
| 99 | |
| 100 | # Filter test entries to ones starting with the library name |
| 101 | # Separate entries with "|" delimiter and remove trailing "|" |
| 102 | libraryTests=$(grep "^${library}\(-\|[A-Z]\)" <<< "$testZipEntries" \ |
| 103 | | tr '\n' "|" \ |
| 104 | | sed "s/|$//") |
| 105 | query="query = 'branch:(aosp-androidx-main|androidx-platform-dev) module:($libraryTests)'" |
| 106 | |
| 107 | if [ -f "$filePath" ]; then |
| 108 | # Update just the query line if the file already exists |
| 109 | printf "Updating dashboard configuration for $library\n" |
| 110 | sed -i "s/query = '.*'/$query/" $filePath |
| 111 | else |
| 112 | printf "Creating dashboard configuration for $library\n" |
| 113 | cat > $filePath <<EOL |
| 114 | // To preview this dashboard, visit android-build.googleplex.com/builds/tests/search |
| 115 | // and copy the query string below into the search bar. |
| 116 | ath_config = { |
| 117 | $query |
| 118 | |
| 119 | tab = 'TAB_TESTS' |
| 120 | |
| 121 | filters = { |
| 122 | failure_rate = { |
| 123 | high_failure_rate = true |
| 124 | med_failure_rate = true |
| 125 | } |
| 126 | } |
| 127 | } |
| 128 | EOL |
| 129 | fi |
| 130 | done |
| 131 | |
| 132 | # Construct CL description |
| 133 | clDesc="Create and update AndroidX library test dashboards |
| 134 | |
| 135 | The following script was used to create this config: |
| 136 | https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/create_library_test_dashboard.sh |
| 137 | " |
| 138 | |
| 139 | # Grab the CL number generated from running `g4 change`. |
| 140 | clNum=$(g4 change --desc "$clDesc" | tail -1 | awk '{print $2}') |
| 141 | printf "View pending changes at http://cl/${clNum} \n" |
| 142 | |