|
| 1 | +#!/usr/bin/env bash |
| 2 | +# |
| 3 | +# Copyright (C) 2015-2019 Virgil Security Inc. |
| 4 | +# |
| 5 | +# All rights reserved. |
| 6 | +# |
| 7 | +# Redistribution and use in source and binary forms, with or without |
| 8 | +# modification, are permitted provided that the following conditions are |
| 9 | +# met: |
| 10 | +# |
| 11 | +# (1) Redistributions of source code must retain the above copyright |
| 12 | +# notice, this list of conditions and the following disclaimer. |
| 13 | +# |
| 14 | +# (2) Redistributions in binary form must reproduce the above copyright |
| 15 | +# notice, this list of conditions and the following disclaimer in |
| 16 | +# the documentation and/or other materials provided with the |
| 17 | +# distribution. |
| 18 | +# |
| 19 | +# (3) Neither the name of the copyright holder nor the names of its |
| 20 | +# contributors may be used to endorse or promote products derived from |
| 21 | +# this software without specific prior written permission. |
| 22 | +# |
| 23 | +# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR |
| 24 | +# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 25 | +# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 26 | +# DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, |
| 27 | +# INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 28 | +# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
| 29 | +# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 30 | +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, |
| 31 | +# STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING |
| 32 | +# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 33 | +# POSSIBILITY OF SUCH DAMAGE. |
| 34 | +# |
| 35 | +# Lead Maintainer: Virgil Security Inc. <support@virgilsecurity.com> |
| 36 | +# |
| 37 | + |
| 38 | +get_version () { |
| 39 | + filename=$1 # Get first parameter as filename |
| 40 | + local __resultvar=$2 # Get second parameter to return result |
| 41 | + |
| 42 | + version="-1" |
| 43 | + |
| 44 | + while read line; do |
| 45 | + |
| 46 | + firstWord="$(cut -d' ' -f1 <<< "$line")" |
| 47 | + |
| 48 | + if [[ "$firstWord" = "version" ]]; |
| 49 | + then |
| 50 | + version="$(cut -d"'" -f2 <<< "$line")" |
| 51 | + fi |
| 52 | + |
| 53 | + done < ${filename} |
| 54 | + |
| 55 | + if [[ "$__resultvar" ]]; then |
| 56 | + eval ${__resultvar}="${version}" |
| 57 | + else |
| 58 | + echo "${version}" |
| 59 | + fi |
| 60 | +} |
| 61 | + |
| 62 | +generate_index_page() { |
| 63 | + cat >"index.html" << EOL |
| 64 | + <html> |
| 65 | + <head> |
| 66 | + <meta charset="utf-8"> |
| 67 | + <title>Virgil Security E3Kit Java/Kotlin</title> |
| 68 | + </head> |
| 69 | + <body style="display: flex; align-items: center; flex-direction: column;"> |
| 70 | +
|
| 71 | + <img style="display: block; margin-left: auto; margin-right: auto;" src="https://cdn.virgilsecurity.com/assets/images/github/logos/virgil-logo-red.png" width="230px" hspace="10" vspace="6" /> |
| 72 | +
|
| 73 | + <div style="width: r00px"> |
| 74 | + <h1>Virgil Security E3Kit JavaDoc</h1> |
| 75 | + <p> </p> |
| 76 | +
|
| 77 | + <h2 style="color:#110B91B0;">User modules</h2> |
| 78 | + <hr/> |
| 79 | + <h3>E3Kit</h3> |
| 80 | + <ul><li><a href="content/ethree-kotlin/${2}/ethree-kotlin/index.html">${2}</a></li></ul> |
| 81 | +
|
| 82 | + <h3>E3Kit Coroutines</h3> |
| 83 | + <ul><li><a href="content/ethree-kotlin-coroutines/${3}/ethree-kotlin-coroutines/index.html">${3}</a></li></ul> |
| 84 | +
|
| 85 | + <p> </p> |
| 86 | + <h2 style="color:#110B91B1;">Internal modules</h2> |
| 87 | + <hr/> |
| 88 | +
|
| 89 | + <h3>E3Kit Common</h3> |
| 90 | + <ul><li><a href="content/ethree-common/${1}/ethree-common/index.html">${1}</a></li></ul> |
| 91 | + </div> |
| 92 | +
|
| 93 | + <p> </p> |
| 94 | + <p style="text-align: center"> |
| 95 | + <a href="https://virgilsecurity.com">Virgil Security, Inc.</a> | <a href="https://github.com/VirgilSecurity/virgil-e3kit-kotlin">E3Kit Github</a> |
| 96 | + </p> |
| 97 | + </body> |
| 98 | + </html> |
| 99 | +EOL |
| 100 | +} |
| 101 | + |
| 102 | +if [[ "$TRAVIS_REPO_SLUG" == "VirgilSecurity/virgil-e3kit-kotlin" ]] && [[ "$TRAVIS_PULL_REQUEST" == "false" ]] && [[ "$TRAVIS_BRANCH" == "master" ]]; then |
| 103 | + |
| 104 | + echo -e "Publishing javadoc...\n" |
| 105 | + |
| 106 | + # Generate docs |
| 107 | + ./gradlew :ethree-common:javadocJar |
| 108 | + ./gradlew :ethree-kotlin:javadocJar |
| 109 | + ./gradlew :ethree-kotlin-coroutines:javadocJar |
| 110 | + |
| 111 | + versionCommon="-1" |
| 112 | + versionEthree="-1" |
| 113 | + versionEthreeCoroutines="-1" |
| 114 | + |
| 115 | + # Get each module version |
| 116 | + get_version "ethree-common/build.gradle" versionCommon |
| 117 | + get_version "ethree-kotlin/build.gradle" versionEthree |
| 118 | + get_version "ethree-kotlin-coroutines/build.gradle" versionEthreeCoroutines |
| 119 | + |
| 120 | + # Create each module docs temporary folder |
| 121 | + mkdir $HOME/javadoc-latest/ |
| 122 | + mkdir $HOME/javadoc-latest/${versionCommon}/ |
| 123 | + mkdir $HOME/javadoc-latest/${versionEthree}/ |
| 124 | + mkdir $HOME/javadoc-latest/${versionEthreeCoroutines}/ |
| 125 | + cp -R ethree-common/build/javadoc/. $HOME/javadoc-latest/${versionCommon}/ |
| 126 | + cp -R ethree-kotlin/build/javadoc/. $HOME/javadoc-latest/${versionEthree}/ |
| 127 | + cp -R ethree-kotlin-coroutines/build/javadoc/. $HOME/javadoc-latest/${versionEthreeCoroutines}/ |
| 128 | + |
| 129 | + # Get last gh-pages docs |
| 130 | + cd $HOME |
| 131 | + git config --global user.email "travis@travis-ci.org" |
| 132 | + git config --global user.name "travis-ci" |
| 133 | + git clone --quiet --branch=gh-pages https://${GH_TOKEN}@github.com/VirgilSecurity/virgil-e3kit-kotlin gh-pages > /dev/null |
| 134 | + |
| 135 | + # Remove old docs |
| 136 | + cd gh-pages |
| 137 | + git rm index.html |
| 138 | + git rm -rf content |
| 139 | + |
| 140 | + # Create main index page for all modules |
| 141 | + versions=(${versionCommon} ${versionEthree} ${versionEthreeCoroutines}) |
| 142 | + generate_index_page ${versions[*]} |
| 143 | + |
| 144 | + # Move each module docs to actual folder |
| 145 | + mkdir content |
| 146 | + mkdir content/ethree-common/ |
| 147 | + mkdir content/ethree-kotlin/ |
| 148 | + mkdir content/ethree-kotlin-coroutines/ |
| 149 | + mv $HOME/javadoc-latest/${versionCommon} content/ethree-common/ |
| 150 | + mv $HOME/javadoc-latest/${versionEthree} content/ethree-kotlin/ |
| 151 | + mv $HOME/javadoc-latest/${versionEthreeCoroutines} content/ethree-kotlin-coroutines/ |
| 152 | + |
| 153 | + # Add new docs to index and commit |
| 154 | + git add -f . |
| 155 | + git commit -m "Latest javadoc on successful travis build $TRAVIS_BUILD_NUMBER auto-pushed to gh-pages" |
| 156 | + git push -fq origin gh-pages > /dev/null |
| 157 | + |
| 158 | + echo -e "Published Javadoc to gh-pages.\n" |
| 159 | +fi |
0 commit comments