xref: /aosp_15_r20/external/libva/doc/ghdeploydoxy.sh (revision 54e60f844a168e9a219354de272cd517ee8cd4b7)
1*54e60f84SAndroid Build Coastguard Worker#!/bin/bash
2*54e60f84SAndroid Build Coastguard Worker################################################################################
3*54e60f84SAndroid Build Coastguard Worker# Notes         :
4*54e60f84SAndroid Build Coastguard Worker# Preconditions:
5*54e60f84SAndroid Build Coastguard Worker# - Packages doxygen doxygen-doc doxygen-latex doxygen-gui graphviz
6*54e60f84SAndroid Build Coastguard Worker#   must be installed.
7*54e60f84SAndroid Build Coastguard Worker# - Doxygen configuration file must have the destination directory empty and
8*54e60f84SAndroid Build Coastguard Worker#   source code directory.
9*54e60f84SAndroid Build Coastguard Worker# - A gh-pages branch should already exist.
10*54e60f84SAndroid Build Coastguard Worker#
11*54e60f84SAndroid Build Coastguard Worker# Required global variables:
12*54e60f84SAndroid Build Coastguard Worker# - DOXYFILE            : The Doxygen configuration file.
13*54e60f84SAndroid Build Coastguard Worker# - GH_REPO_NAME        : The name of the repository.
14*54e60f84SAndroid Build Coastguard Worker# - GH_REPO_REF         : The GitHub reference to the repository.
15*54e60f84SAndroid Build Coastguard Worker# - GH_REPO_TOKEN       : The GitHub application token.
16*54e60f84SAndroid Build Coastguard Worker#
17*54e60f84SAndroid Build Coastguard Worker# This script will generate Doxygen documentation and push the documentation to
18*54e60f84SAndroid Build Coastguard Worker# the gh-pages branch of a repository specified by GH_REPO_REF.
19*54e60f84SAndroid Build Coastguard Worker# Before this script is used there should already be a gh-pages branch in the
20*54e60f84SAndroid Build Coastguard Worker# repository.
21*54e60f84SAndroid Build Coastguard Worker#
22*54e60f84SAndroid Build Coastguard Worker################################################################################
23*54e60f84SAndroid Build Coastguard Worker
24*54e60f84SAndroid Build Coastguard Worker################################################################################
25*54e60f84SAndroid Build Coastguard Worker##### Setup this script and get the current gh-pages branch.               #####
26*54e60f84SAndroid Build Coastguard Workerecho 'Setting up the script...'
27*54e60f84SAndroid Build Coastguard Worker# Exit with nonzero exit code if anything fails
28*54e60f84SAndroid Build Coastguard Workerset -e
29*54e60f84SAndroid Build Coastguard Worker
30*54e60f84SAndroid Build Coastguard WorkerGH_REPO_NAME=
31*54e60f84SAndroid Build Coastguard WorkerGH_REPO_REF=
32*54e60f84SAndroid Build Coastguard WorkerGH_REPO_TOKEN=
33*54e60f84SAndroid Build Coastguard Worker
34*54e60f84SAndroid Build Coastguard Workerusage() { echo "Usage: `basename $0` options (-n value) (-r value) (-t value)" 1>&2; exit 1; }
35*54e60f84SAndroid Build Coastguard Worker
36*54e60f84SAndroid Build Coastguard Workerif ( ! getopts ":n:r:t:" opt); then
37*54e60f84SAndroid Build Coastguard Worker      usage
38*54e60f84SAndroid Build Coastguard Workerfi
39*54e60f84SAndroid Build Coastguard Worker
40*54e60f84SAndroid Build Coastguard Workerwhile getopts :n:r:t: opt; do
41*54e60f84SAndroid Build Coastguard Worker  case $opt in
42*54e60f84SAndroid Build Coastguard Worker  n)
43*54e60f84SAndroid Build Coastguard Worker      GH_REPO_NAME=$OPTARG
44*54e60f84SAndroid Build Coastguard Worker      ;;
45*54e60f84SAndroid Build Coastguard Worker  r)
46*54e60f84SAndroid Build Coastguard Worker      GH_REPO_REF=$OPTARG
47*54e60f84SAndroid Build Coastguard Worker      ;;
48*54e60f84SAndroid Build Coastguard Worker  t)
49*54e60f84SAndroid Build Coastguard Worker      GH_REPO_TOKEN=$OPTARG
50*54e60f84SAndroid Build Coastguard Worker      ;;
51*54e60f84SAndroid Build Coastguard Worker  *)
52*54e60f84SAndroid Build Coastguard Worker      usage
53*54e60f84SAndroid Build Coastguard Worker      ;;
54*54e60f84SAndroid Build Coastguard Worker  esac
55*54e60f84SAndroid Build Coastguard Workerdone
56*54e60f84SAndroid Build Coastguard Worker
57*54e60f84SAndroid Build Coastguard Workershift $((OPTIND - 1))
58*54e60f84SAndroid Build Coastguard Worker
59*54e60f84SAndroid Build Coastguard Worker[ -n "$GH_REPO_NAME" ] || {
60*54e60f84SAndroid Build Coastguard Worker    echo "ERROR: -n GH_REPO_NAME is not defined" >/dev/stderr
61*54e60f84SAndroid Build Coastguard Worker    exit 1
62*54e60f84SAndroid Build Coastguard Worker}
63*54e60f84SAndroid Build Coastguard Worker
64*54e60f84SAndroid Build Coastguard Worker[ -n "$GH_REPO_REF" ] || {
65*54e60f84SAndroid Build Coastguard Worker    echo "ERROR: -r GH_REPO_REF is not defined" >/dev/stderr
66*54e60f84SAndroid Build Coastguard Worker    exit 1
67*54e60f84SAndroid Build Coastguard Worker}
68*54e60f84SAndroid Build Coastguard Worker
69*54e60f84SAndroid Build Coastguard Worker[ -n "$GH_REPO_TOKEN" ] || {
70*54e60f84SAndroid Build Coastguard Worker    echo "ERROR: -t GH_REPO_TOKEN is not defined" >/dev/stderr
71*54e60f84SAndroid Build Coastguard Worker    exit 1
72*54e60f84SAndroid Build Coastguard Worker}
73*54e60f84SAndroid Build Coastguard Worker
74*54e60f84SAndroid Build Coastguard Worker################################################################################
75*54e60f84SAndroid Build Coastguard Worker##### Upload the documentation to the gh-pages branch of the repository.   #####
76*54e60f84SAndroid Build Coastguard Worker# Only upload if Doxygen successfully created the documentation.
77*54e60f84SAndroid Build Coastguard Worker# Check this by verifying that the html directory and the file html/index.html
78*54e60f84SAndroid Build Coastguard Worker# both exist. This is a good indication that Doxygen did it's work.
79*54e60f84SAndroid Build Coastguard Workerif [ -d "html-out" ] && [ -f "html-out/index.html" ]; then
80*54e60f84SAndroid Build Coastguard Worker
81*54e60f84SAndroid Build Coastguard Worker    # Create a clean working directory for this script.
82*54e60f84SAndroid Build Coastguard Worker    mkdir code_docs
83*54e60f84SAndroid Build Coastguard Worker    cd code_docs
84*54e60f84SAndroid Build Coastguard Worker
85*54e60f84SAndroid Build Coastguard Worker    # Get the current gh-pages branch
86*54e60f84SAndroid Build Coastguard Worker    git clone -b gh-pages https://git@$GH_REPO_REF
87*54e60f84SAndroid Build Coastguard Worker    cd $GH_REPO_NAME
88*54e60f84SAndroid Build Coastguard Worker
89*54e60f84SAndroid Build Coastguard Worker    ##### Configure git.
90*54e60f84SAndroid Build Coastguard Worker    # Set the push default to simple i.e. push only the current branch.
91*54e60f84SAndroid Build Coastguard Worker    git config --global push.default simple
92*54e60f84SAndroid Build Coastguard Worker
93*54e60f84SAndroid Build Coastguard Worker    # Remove everything currently in the gh-pages branch.
94*54e60f84SAndroid Build Coastguard Worker    # GitHub is smart enough to know which files have changed and which files have
95*54e60f84SAndroid Build Coastguard Worker    # stayed the same and will only update the changed files. So the gh-pages branch
96*54e60f84SAndroid Build Coastguard Worker    # can be safely cleaned, and it is sure that everything pushed later is the new
97*54e60f84SAndroid Build Coastguard Worker    # documentation.
98*54e60f84SAndroid Build Coastguard Worker    CURRENTCOMMIT=`git rev-parse HEAD`
99*54e60f84SAndroid Build Coastguard Worker    git reset --hard `git rev-list HEAD | tail -n 1` # Reset working tree to initial commit
100*54e60f84SAndroid Build Coastguard Worker    git reset --soft $CURRENTCOMMIT # Move HEAD back to where it was
101*54e60f84SAndroid Build Coastguard Worker
102*54e60f84SAndroid Build Coastguard Worker    # Move doxy files into local gh-pages branch folder
103*54e60f84SAndroid Build Coastguard Worker    mv ../../html-out/* .
104*54e60f84SAndroid Build Coastguard Worker
105*54e60f84SAndroid Build Coastguard Worker    # Need to create a .nojekyll file to allow filenames starting with an underscore
106*54e60f84SAndroid Build Coastguard Worker    # to be seen on the gh-pages site. Therefore creating an empty .nojekyll file.
107*54e60f84SAndroid Build Coastguard Worker    # Presumably this is only needed when the SHORT_NAMES option in Doxygen is set
108*54e60f84SAndroid Build Coastguard Worker    # to NO, which it is by default. So creating the file just in case.
109*54e60f84SAndroid Build Coastguard Worker    echo "" > .nojekyll
110*54e60f84SAndroid Build Coastguard Worker
111*54e60f84SAndroid Build Coastguard Worker    echo 'Uploading documentation to the gh-pages branch...'
112*54e60f84SAndroid Build Coastguard Worker    # Add everything in this directory (the Doxygen code documentation) to the
113*54e60f84SAndroid Build Coastguard Worker    # gh-pages branch.
114*54e60f84SAndroid Build Coastguard Worker    # GitHub is smart enough to know which files have changed and which files have
115*54e60f84SAndroid Build Coastguard Worker    # stayed the same and will only update the changed files.
116*54e60f84SAndroid Build Coastguard Worker    git add --all
117*54e60f84SAndroid Build Coastguard Worker
118*54e60f84SAndroid Build Coastguard Worker    # Commit the added files with a title and description containing the Travis CI
119*54e60f84SAndroid Build Coastguard Worker    # build number and the GitHub commit reference that issued this build.
120*54e60f84SAndroid Build Coastguard Worker    git commit -m "Deploy code docs to GitHub Pages"
121*54e60f84SAndroid Build Coastguard Worker
122*54e60f84SAndroid Build Coastguard Worker    # Force push to the remote gh-pages branch.
123*54e60f84SAndroid Build Coastguard Worker    # The ouput is redirected to /dev/null to hide any sensitive credential data
124*54e60f84SAndroid Build Coastguard Worker    # that might otherwise be exposed.
125*54e60f84SAndroid Build Coastguard Worker    git push --force "https://${GH_REPO_TOKEN}@${GH_REPO_REF}" > /dev/null 2>&1
126*54e60f84SAndroid Build Coastguard Workerelse
127*54e60f84SAndroid Build Coastguard Worker    echo '' >&2
128*54e60f84SAndroid Build Coastguard Worker    echo 'Warning: No documentation (html) files have been found!' >&2
129*54e60f84SAndroid Build Coastguard Worker    echo 'Warning: Not going to push the documentation to GitHub!' >&2
130*54e60f84SAndroid Build Coastguard Worker    exit 1
131*54e60f84SAndroid Build Coastguard Workerfi
132