Skip to content

Commit

Permalink
Integrate sbt-gh-pages to create GH Pages from Scaladoc
Browse files Browse the repository at this point in the history
  • Loading branch information
aldemirenes committed Aug 17, 2019
1 parent 7f2485b commit 6afbb62
Show file tree
Hide file tree
Showing 9 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ env:
# SONA_PASS
- secure: oDu2dXzektYr/7K5nw7EL2qDUR5AhO4Uz6XGHoOQsN1gJiovdsa5nJeDHgo2YFGpJljyTo+lABbxpGIFQpcnKGIG9eAaXIyYpRlEiksTUnZdwIlCXkRMg2l9cUr30ZDOoVS8QpQbCDdogOSqJ+RUShSuiXR8Qi2e0RfrsVucgkNogQ6w1IoB9kV8CAYsnJVzi/oenTJZjEh5qrKiUALpkiHGjB9WSIHQ80sAO/rwnr88w++HcOIqgnvhJ3/Ig3N6201Slud5pF2yVz4MxzY8bedetqNil5ffosYiU7dladOiKTVj8efZPx0cGq0dhpAZFVhehlXyu4EA24NRgKYvAIc0xWVVm49IBaMpDDI/nh24uF9fBPt2+Apj5BY/ETpKS5tFqFaGkBjlL9KFL3l2DfnWC8AfTHlBXFlkH8tKPSN4so612QAmWuULtrVuQpV8DF40HNwJoR2Lyyy5aHrZtpdjHsp3OJI83QfCxH2yTYhes4eHAxi4ynZDSDolt6mrjx651mmlQCsJWJ5KdWHQwjqzgRP8q1/bCaDYdODhrz0K1JPl6YYA+dzwRP+rFeSQbzG0yGo12p7FZGpq36/Hq9C/HSw6WVDN3Lr8CUxZr1rDhtmAvaMJG5EyYDXpNGn9j2DJX76A1Ifu7KXCp8h+FTLPa1CIxJruNxEA6vFSdqA=
- SONA_USER=snowplow
- ENCRYPTION_LABEL: 1ec7ed6de651
1 change: 1 addition & 0 deletions .travis/deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ pwd

project_version=$(sbt version -Dsbt.log.noformat=true | perl -ne 'print $1 if /(\d+\.\d+\.\d+[^\r\n]*)/')
if [ "${project_version}" == "${tag_version}" ]; then
./.travis/deploy_docs.sh
sbt +publish
sbt +bintraySyncMavenCentral
else
Expand Down
17 changes: 17 additions & 0 deletions .travis/deploy_docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

ENCRYPTED_KEY_VAR="encrypted_${ENCRYPTION_LABEL}_key"
ENCRYPTED_IV_VAR="encrypted_${ENCRYPTION_LABEL}_iv"
ENCRYPTED_KEY=${!ENCRYPTED_KEY_VAR}
ENCRYPTED_IV=${!ENCRYPTED_IV_VAR}

git config --global user.name "$USER"
git config --global user.email "$TRAVIS_BUILD_NUMBER@$TRAVIS_COMMIT"

openssl aes-256-cbc -K $ENCRYPTED_KEY -iv $ENCRYPTED_IV -in project/travis-deploy-key.enc -out project/travis-deploy-key -d
chmod 600 project/travis-deploy-key

eval "$(ssh-agent -s)"
ssh-add project/travis-deploy-key

sbt ghpagesPushSite
3 changes: 3 additions & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,13 @@ lazy val root = project.in(file("."))
scalaVersion := "2.12.8",
crossScalaVersions := Seq("2.11.12", "2.12.8")
))
.enablePlugins(SiteScaladocPlugin)
.enablePlugins(GhpagesPlugin)
.settings(BuildSettings.buildSettings)
.settings(BuildSettings.publishSettings)
.settings(BuildSettings.mimaSettings)
.settings(BuildSettings.scoverageSettings)
.settings(BuildSettings.ghPagesSettings)
.settings(Seq(
shellPrompt := { _ => name.value + " > " }
))
Expand Down
12 changes: 12 additions & 0 deletions project/BuildSettings.scala
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ import com.typesafe.tools.mima.plugin.MimaPlugin
// Scoverage plugin
import scoverage.ScoverageKeys._

import com.typesafe.sbt.sbtghpages.GhpagesPlugin.autoImport._
import com.typesafe.sbt.site.SitePlugin.autoImport.makeSite
import com.typesafe.sbt.SbtGit.GitKeys.{gitBranch, gitRemoteRepo}

object BuildSettings {

// Basic settings for our app
Expand Down Expand Up @@ -91,4 +95,12 @@ object BuildSettings {
(coverageReport dependsOn (test in Test)).value
}
)

val ghPagesSettings = Seq(
ghpagesPushSite := (ghpagesPushSite dependsOn makeSite).value,
ghpagesNoJekyll := false,
gitRemoteRepo := "[email protected]:snowplow/snowplow-scala-analytics-sdk.git",
gitBranch := Some("gh-pages"),
excludeFilter in ghpagesCleanSite := "index.html"
)
}
51 changes: 51 additions & 0 deletions project/docs_init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash

# This script is used for initializing the gh-pages branch

PROJECT_NAME=snowplow-scala-analytics-sdk
[email protected]:snowplow/snowplow-scala-analytics-sdk.git

# Using a fresh, temporary clone is safest for this procedure
pushd /tmp
git clone $PROJECT_REPO
cd $PROJECT_NAME

# Create branch with no history or content
git checkout --orphan gh-pages
git rm -rf .

# Create index.html file in order to redirect main page
# to /latest/api
cat > index.html <<- EOM
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project Documentation</title>
<script language="JavaScript">
<!--
function doRedirect()
{
window.location.replace("latest/api");
}
doRedirect();
//-->
</script>
</head>
<body>
<a href="latest/api">Go to the project documentation
</a>
</body>
</html>
EOM

git add index.html

# Establish the branch existence
git commit --allow-empty -m "Initialize gh-pages branch"
git push origin gh-pages

# Return to original working copy clone, we're finished with the /tmp one
popd
rm -rf /tmp/$PROJECT_NAME
21 changes: 21 additions & 0 deletions project/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Project Documentation</title>
<script language="JavaScript">
<!--
function doRedirect()
{
window.location.replace("latest/api");
}

doRedirect();
//-->
</script>
</head>
<body>
<a href="latest/api">Go to the project documentation
</a>
</body>
</html>
5 changes: 4 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.3")
addSbtPlugin("com.typesafe" % "sbt-mima-plugin" % "0.5.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-site" % "1.4.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-git" % "1.0.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % "0.6.3")
Binary file added project/travis-deploy-key.enc
Binary file not shown.

0 comments on commit 6afbb62

Please sign in to comment.