forked from googleapis/google-cloud-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
uploaddocs.sh
executable file
·81 lines (66 loc) · 3.13 KB
/
uploaddocs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/bin/sh
set -e
if [[ -z "$1" || -z "$2" || -z "$3" || -z "$4" || -z "$5" ]]
then
echo "Usage: uploaddocs.sh <nupkg directory> <docs output directory> <service account json> <googleapis.dev staging bucket> <devsite staging bucket>"
exit 1
fi
declare -r NUPKG_DIR=$1
declare -r DOCS_OUTPUT_DIR=$2
declare -r SERVICE_ACCOUNT_JSON=$(realpath $3)
declare -r GOOGLEAPIS_DEV_STAGING_BUCKET=$4
declare -r DEVSITE_STAGING_BUCKET=$5
# Make sure we have the most recent version of pip, then install the gcp-docuploader package
python -m pip install --upgrade pip
python -m pip install -q gcp-docuploader
for nupkg in $NUPKG_DIR/*.nupkg
do
pair=$(basename $nupkg | sed -r 's/^(.*)\.([0-9]+\.[0-9]+\.[0-9]+(-.*)?)\.nupkg$/\1 \2/g')
pkg=$(echo $pair | cut -d\ -f 1)
version=$(echo $pair | cut -d\ -f 2)
# Currently we don't generate documentation for libraries such as
# Google.Cloud.Spanner.V1.Common. When we've moved entirely to googleapis.dev,
# we can change this to generate reference documentation for all packages.
if [[ -d $DOCS_OUTPUT_DIR/$pkg/site ]]
then
echo "Uploading docs for package $pkg version $version"
pushd $DOCS_OUTPUT_DIR/$pkg/site > /dev/null
# We need to perform a few fix-ups of the docfx generated site for googleapis.dev:
# - Remove the "All APIs" link, as that page isn't included on googleapis.dev
# - Fix up links from one API to another (e.g. from Google.Cloud.Spanner.Data to Google.Cloud.Spanner.V1)
# - Add an xrefmap baseUrl
if grep -q "All APIs" toc.html
then
echo "Removing 'All APIs' link"
sed -i '16,18d' toc.html
else
echo "No 'All APIs' link to remove"
fi
# We assume all non-reference html files are just in the root directory
# Regex is nasty due to all the escaping, but we're basically capturing
# href="../{foo}/"
# and replacing it with
# href="../{foo}/latest/
# It's slightly annoying to use latest, but otherwise we need
# to know the precise API version we're depending on.
sed -ie 's/href="\.\.\/\([^\//]*\)\//href="\.\.\/\1\/latest\//g' *.html
if ! head xrefmap.yml | grep -q baseUrl
then
sed -i "1s/^/baseUrl: https:\/\/googleapis.dev\/dotnet\/$pkg\/$version\/\n/" xrefmap.yml
fi
# TODO: Product page
echo "Generating metadata (googleapis.dev)"
python -m docuploader create-metadata --name $pkg --version $version --language dotnet --github-repository googleapis/google-cloud-dotnet
echo "Final upload stage (googleapis.dev)"
python -m docuploader upload . --credentials $SERVICE_ACCOUNT_JSON --staging-bucket $GOOGLEAPIS_DEV_STAGING_BUCKET
# For DevSite, we just upload the yaml in the obj/api directory
cd ../obj/api
echo "Generating metadata (DevSite)"
python -m docuploader create-metadata --name $pkg --version $version --language dotnet --github-repository googleapis/google-cloud-dotnet
echo "Final upload stage (DevSite)"
python -m docuploader upload . --credentials $SERVICE_ACCOUNT_JSON --staging-bucket $DEVSITE_STAGING_BUCKET --destination-prefix docfx
popd > /dev/null
else
echo "Skipping $pkg; no documentation generated"
fi
done