Skip to content

Commit

Permalink
Fix publishMicrosite dynamic task (#229)
Browse files Browse the repository at this point in the history
  • Loading branch information
juanpedromoreno authored Oct 2, 2017
1 parent aafd7d0 commit 611ab1d
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 34 deletions.
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import sbt.Resolver.sonatypeRepo

resolvers ++= Seq(sonatypeRepo("snapshots"), sonatypeRepo("releases"))
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.7.2")
addSbtPlugin("com.47deg" % "sbt-org-policies" % "0.7.5")

libraryDependencies += {
lazy val sbtVersionValue = (sbtVersion in pluginCrossBuild).value
Expand Down
62 changes: 30 additions & 32 deletions src/main/scala/microsites/MicrositeKeys.scala
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
)
.value
},
publishMicrosite := (Def.taskDyn {
publishMicrosite := Def.taskDyn {
val siteDir: File = (target in makeSite).value
val noJekyll: Boolean = ghpagesNoJekyll.value
val branch: String = ghpagesBranch.value
Expand All @@ -265,47 +265,45 @@ trait MicrositeAutoImportSettings extends MicrositeKeys {
val githubRepo: String = micrositeGithubRepo.value
val githubToken: Option[String] = micrositeGithubToken.value

val cleanAndMakeMicroSite = Def.sequential(clean, makeMicrosite).value
val cleanAndMakeMicroSite: Unit = Def.sequential(clean, makeMicrosite).value

Def.task {
lazy val log: Logger = streams.value.log
lazy val log: Logger = streams.value.log

(pushSiteWith.name, gitHosting.name, cleanAndMakeMicroSite) match {
case (GHPagesPlugin.name, _, _) =>
ghpagesPushSite.value
case (GitHub4s.name, GitHub.name, _) if githubToken.nonEmpty =>
val commitMessage = sys.env.getOrElse("SBT_GHPAGES_COMMIT_MESSAGE", "updated site")
(pushSiteWith.name, gitHosting.name, cleanAndMakeMicroSite) match {
case (GHPagesPlugin.name, _, _) =>
Def.task(ghpagesPushSite.value)
case (GitHub4s.name, GitHub.name, _) if githubToken.nonEmpty =>
val commitMessage = sys.env.getOrElse("SBT_GHPAGES_COMMIT_MESSAGE", "updated site")

log.info(s"""Committing files from ${siteDir.getAbsolutePath} into branch '$branch'
log.info(s"""Committing files from ${siteDir.getAbsolutePath} into branch '$branch'
| * repo: $githubOwner/$githubRepo
| * commitMessage: $commitMessage""".stripMargin)

val ghOps: GitHubOps = new GitHubOps(githubOwner, githubRepo, githubToken)
val ghOps: GitHubOps = new GitHubOps(githubOwner, githubRepo, githubToken)

if (noJekyll) IO.touch(siteDir / ".nojekyll")
if (noJekyll) IO.touch(siteDir / ".nojekyll")

ghOps.commitDir(branch, commitMessage, siteDir) match {
case Right(_) => log.info("Success committing files")
case Left(e) =>
log.error(s"Error committing files")
e.printStackTrace()
}
ghOps.commitDir(branch, commitMessage, siteDir) match {
case Right(_) => log.info("Success committing files")
case Left(e) =>
log.error(s"Error committing files")
e.printStackTrace()
}

cleanAndMakeMicroSite
case (GitHub4s.name, GitHub.name, _) =>
log.error(
s"You must provide a GitHub token through the `micrositeGithubToken` setting for pushing with github4s")
cleanAndMakeMicroSite
case (GitHub4s.name, hosting, _) =>
log.warn(s"github4s doens't have support for $hosting")
cleanAndMakeMicroSite
case _ =>
log.error(
s"""Unexpected match case (pushSiteWith, gitHosting) = ("${pushSiteWith.name}", "${gitHosting.name}")""")
cleanAndMakeMicroSite
}
Def.task(cleanAndMakeMicroSite)
case (GitHub4s.name, GitHub.name, _) =>
log.error(
s"You must provide a GitHub token through the `micrositeGithubToken` setting for pushing with github4s")
Def.task(cleanAndMakeMicroSite)
case (GitHub4s.name, hosting, _) =>
log.warn(s"github4s doens't have support for $hosting")
Def.task(cleanAndMakeMicroSite)
case _ =>
log.error(
s"""Unexpected match case (pushSiteWith, gitHosting) = ("${pushSiteWith.name}", "${gitHosting.name}")""")
Def.task(cleanAndMakeMicroSite)
}
}).value
}.value
)

val publishMicrositeCommand: Command = Command(publishMicrositeCommandKey)(_ => OptNotSpace) {
Expand Down
2 changes: 1 addition & 1 deletion version.sbt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version in ThisBuild := "0.7.2-SNAPSHOT"
version in ThisBuild := "0.7.2"

0 comments on commit 611ab1d

Please sign in to comment.