Skip to content

Commit

Permalink
Merge pull request SolutionGuidance#478 from brainwane/fix-gh-pages
Browse files Browse the repository at this point in the history
De-automate Javadocs publication to GitHub Pages
  • Loading branch information
brainwane committed Jan 10, 2018
2 parents e19e5c7 + 64b8103 commit 6b026e0
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 31 deletions.
5 changes: 0 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ before_script:

install: true

# The build step here also builds our Javadocs.
script:
- cd psm-app
- ./gradlew --no-daemon --console=plain
Expand All @@ -40,10 +39,6 @@ script:
test
- cd ../

# Push the new Javadocs to our GitHub Pages site.
after_success:
- ./scripts/push-javadoc-to-gh-pages.sh

# Build the Continuous Deployment private key
before_deploy:
- ./scripts/travis-ssh-add.sh
Expand Down
10 changes: 4 additions & 6 deletions scripts/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ administrators or our build systems.

* `rhel-install.sh` is an automated script Red Hat sysadmins can use
to install the PSM.
* `push-javadoc-to-gh-pages.sh` lets TravisCI build our automated API
documentation using Javadoc and push it to the `gh-pages` branch,
which can automatically update [our GitHub Pages
site](https://solutionguidance.github.io/psm/). It's [currently
under
construction](https://github.com/solutionguidance/psm/pull/478).
* `push-javadoc-to-gh-pages.sh` lets a developer build our automated
API documentation using Javadoc and push it to the `gh-pages`
branch, which updates [our GitHub Pages
site](https://solutionguidance.github.io/psm/javadoc/api-docs/).
* `drools-microservice.sh` sets up a copy of jBPM and Guvnor on a
standalone server, which the core application can then be configured
to communicate with.
Expand Down
74 changes: 54 additions & 20 deletions scripts/push-javadoc-to-gh-pages.sh
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 -

0 comments on commit 6b026e0

Please sign in to comment.