Skip to content

Commit

Permalink
Setup asciidoc-to-html build system
Browse files Browse the repository at this point in the history
Our markdown documentation is published to GitHub pages via its
automatic markdown files publishing support[1]. However, this mechanism
does not support asciidoc files.

We are in the process of converting all of our documentation to
asciidoc, so we'll need to setup our own GitHub pages build and
deployment system.

Let's reuse the asciidoc-to-html build system in addressbook-level4[2]
by copying the relevant code/files.

[1] https://github.com/blog/2289-publishing-with-github-pages-now-as-easy-as-1-2-3
[2] https://github.com/se-edu/addressbook-level4
  • Loading branch information
pyokagan committed Jul 3, 2018
1 parent cf3446a commit 62136d8
Show file tree
Hide file tree
Showing 6 changed files with 532 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ test/data/

# Gradle files
/.gradle/
/build/
28 changes: 28 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
language: java
matrix:
include:
- jdk: oraclejdk9

script: >-
./gradlew
deploy:
skip_cleanup: true
provider: script
script: ./config/travis/deploy_github_pages.sh
on:
branch: master

addons:
apt:
packages:
- oracle-java9-installer

before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/

cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/
35 changes: 35 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Gradle Configuration File
// For more details take a look at the Java Quickstart chapter in the Gradle
// user guide available at http://gradle.org/docs/4.8.1/userguide/tutorial_java_projects.html

plugins {
id 'org.asciidoctor.convert' version '1.5.6'
}

asciidoctor {
backends 'html5'
sourceDir 'docs'
outputDir "${buildDir}/docs"

attributes = [
linkcss: true,
stylesheet: 'gh-pages.css',
'source-highlighter': 'coderay',
icons: 'font',
experimental: true,
sectlinks: true,
idprefix: '', // for compatibility with GitHub preview
idseparator: '-',
]
}

// Copies stylesheets into the directory containing generated HTML files as
// Asciidoctor does not copy linked CSS files to the output directory when rendering.
// This is needed for linked stylesheets and embedded stylesheets which import other files.
task copyStylesheets(type: Copy) {
from "${asciidoctor.sourceDir}/stylesheets"
into "${asciidoctor.outputDir}/html5/stylesheets"
}
asciidoctor.dependsOn copyStylesheets

defaultTasks 'clean', 'asciidoctor'
42 changes: 42 additions & 0 deletions config/travis/deploy_github_pages.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
#!/bin/sh
# Pushes files generated by Asciidoctor and associated files to gh-pages branch for commits to master branch.

set -o errexit # exit with nonzero exit code if any line fails

if [ -z "$GITHUB_TOKEN" ]; then
echo 'GITHUB_TOKEN is not set up in Travis. Skipping deploy.'
exit 0
fi;

set -o nounset # exit if variable is unset

cd build/docs/html5

git init
git config user.name 'Deployment Bot (Travis)'
git config user.email '[email protected]'

git config credential.helper 'store --file=.git/credentials'
echo "https://${GITHUB_TOKEN}:@github.com" > .git/credentials

git remote add upstream "https://github.com/${TRAVIS_REPO_SLUG}.git"

# Reset to gh-pages branch, or create orphan branch if gh-pages does not exist in remote.
if git ls-remote --exit-code --heads upstream gh-pages; then
git fetch --depth=1 upstream gh-pages
git reset upstream/gh-pages
elif [ $? -eq 2 ]; then # exit code of git ls-remote is 2 if branch does not exist
git checkout --orphan gh-pages
else # error occurred
exit $?
fi

# Exit if there are no changes to gh-pages files.
if changes=$(git status --porcelain) && [ -z "$changes" ]; then
echo 'No changes to GitHub Pages files; exiting.'
exit 0
fi

git add -A .
git commit -m "Rebuild pages at ${TRAVIS_COMMIT}"
git push --quiet upstream HEAD:gh-pages
Loading

0 comments on commit 62136d8

Please sign in to comment.