1#!/bin/bash 2# 3# Script to fetch generated API references docs and stage them. 4# 5# Examples: 6# 7# Stage refdocs from a given build ID (to the default staging DB): 8# 9# ./stageReferenceDocsWithDackka.sh --buildId 1234567 10# 11# Stage locally-generated refdocs (to the default staging DB) *. 12# The directory path must be absolute (can't contain ~): 13# 14# /stageReferenceDocsWithDackka.sh --buildId 0 15# --sourceDir=/dir/to/androidx-main/out/androidx/docs-public/build 16# 17# Stage ToT refdocs from a given build ID, to a specified DB, using a specific 18# date string for the generated CL: 19# 20# ./stageReferenceDocsWithDackka.sh --buildId 1234567 --db androidx-docs 21# --dateStr "April 29, 2021" --useToT 22# 23# === 24# 25# * buildId still needs to be specified when staging locally-generated refdocs, 26# but the value is unused and ignored. 27# 28# === 29# 30 31source gbash.sh || exit 32 33readonly defaultDb="" 34DEFINE_string buildId --required "" "The build ID from the Android build server. This is ignored when specifying the 'sourceDir' flag." 35DEFINE_string dateStr "<insert date here>" "Date string used for CL message. Enclose date in double quotes (ex: \"April 29, 2021\")" 36DEFINE_string db "$defaultDb" "The database used for staging. Omitting this value will stage changes to the staging DB." 37DEFINE_string sourceDir "" "Local directory to fetch doc artifacts from. Directory must be absolute (can't contain ~)." 38DEFINE_bool useToT false "Stage docs from tip-of-tree docs build rather than public docs build" 39DEFINE_bool buildNativeDocs false "Build and stage native docs generated with doxygen" 40 41gbash::init_google "$@" 42 43# Change directory to this script's location and store the directory 44cd "$(dirname $0)" 45scriptDirectory=$(pwd) 46 47# Working directories for the refdocs 48outDir="$scriptDirectory/out" 49readonly newDir="reference-docs" 50readonly doxygenNewDir="reference-docs-doxygen" 51 52# Remove and recreate the existing out directory to avoid conflicts from previous runs 53rm -rf $outDir 54mkdir -p $outDir/$newDir 55mkdir -p $outDir/$doxygenNewDir 56cd $outDir 57 58if [ "$FLAGS_sourceDir" == "" ]; then 59 printf "=================================================================== \n" 60 printf "== Download the doc zip files from the build server \n" 61 printf "=================================================================== \n" 62 63 if (( FLAGS_useToT )); then 64 printf "Downloading docs-tip-of-tree zip files \n" 65 androidxDackkaZip="docs-tip-of-tree-${FLAGS_buildId}.zip" 66 else 67 printf "Downloading docs-public zip files \n" 68 androidxDackkaZip="docs-public-${FLAGS_buildId}.zip" 69 fi 70 71 if (( "${FLAGS_buildId::1}" == "P" )); then 72 /google/data/ro/projects/android/fetch_artifact --bid $FLAGS_buildId --target androidx_incremental incremental/$androidxDackkaZip 73 else 74 /google/data/ro/projects/android/fetch_artifact --bid $FLAGS_buildId --target androidx $androidxDackkaZip 75 fi 76 77 # Let's double check we succeeded before continuing 78 if [[ -f "$androidxDackkaZip" ]]; then 79 echo "Download completed" 80 else 81 printf "\n" 82 printf "=================================================================== \n" 83 echo "Failed to download doc zip files. Please double check your build ID and try again." 84 exit 1 85 fi 86 87 printf "\n" 88 printf "=================================================================== \n" 89 printf "== Unzip the doc zip files \n" 90 printf "=================================================================== \n" 91 92 unzip $androidxDackkaZip -d $newDir 93else 94 printf "=================================================================== \n" 95 printf "== Copying doc sources from local directory $FLAGS_sourceDir \n" 96 printf "=================================================================== \n" 97 98 cp -r "$FLAGS_sourceDir/docs/." $newDir 99 100fi 101 102if (( FLAGS_buildNativeDocs )); then 103 printf "\n" 104 printf "=================================================================== \n" 105 printf "== Generate Doxygen docs \n" 106 printf "=================================================================== \n" 107 108 ../generateDoxygenDocs.sh 109fi 110 111cd $newDir/reference 112 113if (( FLAGS_buildNativeDocs )); then 114 cd $outDir 115 # Copy over doxygen generated refdocs 116 rsync -avh --ignore-existing $doxygenNewDir/reference/ $newDir/reference/ 117 118 # Include doxygen toc files in main toc 119 cd $newDir 120 find reference -name _doxygen.yaml -exec python3 $scriptDirectory/helpers/insert_include_into_toc.py {} \; 121fi 122 123printf "\n" 124printf "=================================================================== \n" 125printf "== Create (if needed) and sync g4 workspace \n" 126printf "=================================================================== \n" 127 128client="$(p4 g4d -f androidx-ref-docs-stage --multichange)" 129cd "$client" 130 131# Revert all local changes to prevent merge conflicts when syncing. 132# This is OK since we always want to start with a fresh CitC client 133g4 revert ... 134g4 sync 135 136printf "\n" 137printf "=================================================================== \n" 138printf "== Prep directories and copy refdocs to CitC client \n" 139printf "=================================================================== \n" 140 141cd third_party/devsite/android/en/reference 142 143cd kotlin/androidx 144ls | grep -v "package\|class\|book\|toc\|constraint\|test\|index\|redirects" | xargs -I {} rm -rf {} 145cd ../../androidx 146ls | grep -v "package\|class\|book\|toc\|constraint\|test\|index\|redirects" | xargs -I {} rm -rf {} 147cd .. 148 149cp -r $outDir/$newDir/reference/* . 150 151printf "\n" 152printf "=================================================================== \n" 153printf "== Create a changelist of pending refdoc changes \n" 154printf "=================================================================== \n" 155 156stagingLinkJava="go/dac-stage/reference/androidx/packages" 157stagingLinkKotlin="go/dac-stage/reference/kotlin/androidx/packages" 158 159# Add the db param to links if the target database is not the default staging DB. 160if [ "$FLAGS_db" != "$defaultdb" ]; then 161 stagingLinkJava+="?db=$FLAGS_db" 162 stagingLinkKotlin+="?db=$FLAGS_db" 163fi 164 165# Construct CL description 166clDesc="Androidx $FLAGS_dateStr Ref Docs 167 168DO NOT SUBMIT 169 170GO LIVE TIME: $FLAGS_dateStr @ 10:00 AM PST 171 172Staged: 173* Java: $stagingLinkJava 174* Kotlin: $stagingLinkKotlin 175 176All docs build id: $FLAGS_buildId 177 178The following scripts were used to create these docs: 179 180https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:development/referenceDocs/ 181" 182 183# Grab the CL number generated from running `g4 change`. 184clNum=$(g4 change --desc "$clDesc" | tail -1 | awk '{print $2}') 185printf "View pending changes at http://cl/${clNum} \n" 186 187printf "\n" 188printf "=================================================================== \n" 189printf "== Stage changes \n" 190printf "=================================================================== \n" 191 192# Construct the devsite command and parameters 193devsiteCmd="/google/data/ro/projects/devsite/devsite2 stage" 194devsiteCmd+=" --use_large_thread_pools" 195devsiteCmd+=" --upload_safety_check_mode=ignore" 196 197# Add the --db flag if the target database is not the default staging DB. 198if [ "$FLAGS_db" != "$defaultDb" ]; then 199 devsiteCmd+=" --db=$FLAGS_db" 200fi 201 202# Step back to catch both reference/ docs and css styles in assets/ 203cd .. 204 205# Directories to stage 206devsiteCmd+=" reference/android/support" 207devsiteCmd+=" reference/androidx" 208devsiteCmd+=" reference/kotlin/android/support" 209devsiteCmd+=" reference/kotlin/androidx" 210devsiteCmd+=" assets/css/reference-docs.css" 211 212printf "Running devsite command:\n" 213printf "$devsiteCmd\n" 214 215$devsiteCmd 216 217# Print devsite command and CL link again in case they scrolled off the screen or 218# scrollback buffer 219printf "\n" 220printf "Ran devsite command:\n" 221printf "$devsiteCmd\n" 222printf "\n" 223printf "View pending changes at http://cl/${clNum} \n" 224