forked from SolutionGuidance/psm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request SolutionGuidance#478 from brainwane/fix-gh-pages
De-automate Javadocs publication to GitHub Pages
- Loading branch information
Showing
3 changed files
with
58 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,64 @@ | ||
#!/bin/bash | ||
set -ex | ||
|
||
# Adaptation of code from https://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ | ||
# Script for a developer to use to push new version of Javadoc to | ||
# GitHub Pages site. | ||
# Before running, ensure that you have committed any local changes | ||
# in your current branch. | ||
# | ||
# Code partially adapted from | ||
# https://benlimmer.com/2013/12/26/automatically-publish-javadoc-to-gh-pages-with-travis-ci/ | ||
|
||
if [ "$TRAVIS_REPO_SLUG" == "SolutionGuidance/psm" ] \ | ||
&& [ "$TRAVIS_JDK_VERSION" == "openjdk8" ] \ | ||
&& [ "$TRAVIS_PULL_REQUEST" == "false" ] \ | ||
&& [ "$TRAVIS_BRANCH" == "master" ]; then | ||
set -x # Avoiding -e because we need an exit code on `git diff` | ||
|
||
echo -e "Publishing Javadoc...\n" | ||
if [[ "$(pwd)" != "$(git rev-parse --show-toplevel)" ]] | ||
then | ||
set +x | ||
echo "Please run this from the root of the project by running:" | ||
echo " ./scripts/push-javadoc-to-gh-pages.sh" | ||
echo "This script switches branches;" | ||
echo "running from the root ensures you won't end up in a deleted directory." | ||
exit 1 | ||
fi | ||
|
||
COMMIT=$(git rev-parse HEAD) | ||
echo "Generating Javadoc..." | ||
|
||
cp -R cms-web/build/reports/api-docs $HOME/javadoc-latest | ||
cd psm-app | ||
./gradlew clean cms-web:apiDocs || exit 1 | ||
|
||
cd $HOME | ||
git clone --quiet --branch=gh-pages \ | ||
https://${GH_TOKEN}@github.com/SolutionGuidance/psm gh-pages > /dev/null | ||
DOCSDIR=$(mktemp -d /tmp/docXXXX) | ||
cp -R cms-web/build/reports/api-docs $DOCSDIR || exit 1 | ||
cd .. | ||
|
||
cd gh-pages | ||
git rm -rf ./javadoc | ||
cp -Rf $HOME/javadoc-latest ./javadoc | ||
git add -f . | ||
git commit -m "Javadoc published from Travis build ${TRAVIS_BUILD_NUMBER}" \ | ||
-m "Generated from commit ${TRAVIS_COMMIT}, pushed to gh-pages" \ | ||
--author="Travis CI automated push <psm-dev@googlegroups.com>" | ||
git push -fq origin gh-pages > /dev/null | ||
echo "Publishing Javadoc..." | ||
|
||
git fetch git@github.com:SolutionGuidance/psm.git gh-pages || exit 1 | ||
git rev-parse --verify --quiet "gh-pages" # Check whether branch exists | ||
if [ $? -eq 0 ] # Check for truth | ||
then | ||
git checkout gh-pages || exit 1 # Will fail if you have uncommitted local changes. | ||
git pull git@github.com:SolutionGuidance/psm.git gh-pages || exit 1 | ||
else | ||
git fetch git@github.com:SolutionGuidance/psm.git gh-pages:gh-pages || exit 1 | ||
git checkout gh-pages || exit 1 # Will fail if you have uncommitted local changes. | ||
fi | ||
|
||
echo -e "Published Javadoc to gh-pages branch.\n" | ||
git rm -rf ./javadoc || exit 1 | ||
mv -f $DOCSDIR ./javadoc || exit 1 | ||
git add -f ./javadoc/. | ||
|
||
git diff --staged --quiet --exit-code # Check for changed files | ||
if [ $? -eq 1 ] # Check for differences | ||
then | ||
git commit -m "Publish Javadocs from $COMMIT and push to gh-pages" || exit 1 | ||
git push -q git@github.com:SolutionGuidance/psm.git gh-pages || exit 1 | ||
echo "Published Javadocs from $COMMIT to gh-pages branch." | ||
else | ||
echo "No changes; nothing to commit." | ||
fi | ||
|
||
echo "Finished." | ||
|
||
# Return to branch and directory where user started | ||
|
||
git checkout - |