xref: /aosp_15_r20/external/truth/util/generate-latest-docs.sh (revision b3996a89512f34bffd8f9a69f0bc726f1b19016a)
1#!/bin/bash
2# A script to automatically deploy javadocs.
3#
4# This script is useful both in a CI regular build, where it will generate
5# javadocs (aggregated) via a maven build, and deploy them to github pages. This script
6# is derived from instructions given in this blog article:
7# http://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/
8#
9# If the RELEASE_VERSION environment variable is set, then it will perform a similar
10# action, but push to a versioned api docs folder, under the current user's credentials
11# rather than using an encrypted secret via github's GH_TOKEN mechanism.  Users who
12# use the script this way must have a .ssh key which they have declared on github.com
13# per the instructions here: https://help.github.com/articles/generating-ssh-keys/
14#
15set -euE
16
17echo -e "Publishing javadoc...\n"
18
19if [ -n "${RELEASE_VERSION:-}" ]; then
20  # Release
21  version_subdir=api/${RELEASE_VERSION}
22  commit_message="Release $RELEASE_VERSION javadoc pushed to gh-pages."
23  github_url="[email protected]:google/truth.git"
24else
25  # CI
26  version_subdir=api/latest
27  commit_message="Latest javadoc on successful CI build auto-pushed to gh-pages."
28  github_url="https://x-access-token:${GITHUB_TOKEN}@github.com/google/truth.git"
29fi
30
31mvn javadoc:aggregate
32perl -ni -e 'print unless /Tolerant.*Comparison/ || /SubjectBuilderCallback/ || /UsingCorrespondence/ || /AsIterable/ || /Correspondence[.][A-Z]/ || /FluentAssertion/ || /PathSubject/ || /Re2jSubjects/ || /Ordered/' target/site/apidocs/allclasses-frame.html
33find target/site/apidocs -name '*.html' | xargs perl -077pi -e 's#<li class="blockList"><a name="nested.classes.inherited.from.class.com.google.common.truth.\w*Subject">.*?</li>##msg; if (m#<!-- ======== NESTED CLASS SUMMARY ======== -->(.*?)(?=<!-- =)#ms) { if ($1 !~ m#nested.classes.inherited.from|memberSummary#) { s#<!-- ======== NESTED CLASS SUMMARY ======== -->.*?(?=<!-- =)##msg; } }'
34target_dir="$(pwd)/target"
35cd ${target_dir}
36rm -rf gh-pages
37git clone --quiet --branch=gh-pages "${github_url}" gh-pages > /dev/null
38cd gh-pages
39
40if [[ -z "${RELEASE_VERSION:-}" ]]; then
41  git config --global user.name "$GITHUB_ACTOR"
42  git config --global user.email "$GITHUB_ACTOR@users.noreply.github.com"
43fi
44api_version_dir="${target_dir}/gh-pages/${version_subdir}"
45git rm -rf ${api_version_dir} || true
46cp -ar ${target_dir}/site/apidocs ${api_version_dir}
47git add -A -f ${api_version_dir}
48git commit -m "${commit_message}"
49git push -fq origin gh-pages > /dev/null
50
51echo -e "Published Javadoc to gh-pages.\n"
52