[go: nahoru, domu]

blob: 26503a741e4875c15a554180506b87c240ae5f0b [file] [log] [blame]
Julia McClellan7434c112022-11-21 14:12:47 -05001#!/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
23source gbash.sh || exit
24
25DEFINE_string library "" "If provided, the one library to create a dashboard for."
26
27# Parse the command line arguments
28gbash::init_google "$@"
29
30printf "\n"
31printf "=================================================================== \n"
32printf "== Fetch test configs from the latest green builds \n"
33printf "=================================================================== \n"
34
35# Fetch entries from both branches, as they can be different
36branches=("aosp-androidx-main" "androidx-platform-dev")
37
38allZipEntries=""
39for 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"
63done
64
65# Create list of unique .xml file names
66testZipEntries=$(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.
70if [ -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)
75else
76 libraryNames=$FLAGS_library
77fi
78
79printf "\n"
80printf "=================================================================== \n"
81printf "== Create (if needed) and sync g4 workspace \n"
82printf "=================================================================== \n"
83
84client="$(p4 g4d -f androidx-test-dashboards --multichange)"
85cd "$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
89g4 revert ...
90g4 sync
91
92printf "\n"
93printf "=================================================================== \n"
94printf "== Create a CL with the test dashboard configuration \n"
95printf "=================================================================== \n"
96
97for 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.
116ath_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}
128EOL
129 fi
130done
131
132# Construct CL description
133clDesc="Create and update AndroidX library test dashboards
134
135The following script was used to create this config:
136https://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`.
140clNum=$(g4 change --desc "$clDesc" | tail -1 | awk '{print $2}')
141printf "View pending changes at http://cl/${clNum} \n"
142