From b4fc75b1370f84dfd15113a9c53a035e3cc4ba8d Mon Sep 17 00:00:00 2001 From: Pritam Kadam Date: Thu, 1 Feb 2018 23:13:04 +0530 Subject: [PATCH 1/5] Support for maintaining old versions of site by enabling ghpagesKeepVersions flag. --- README.md | 10 ++++++++ .../typesafe/sbt/sbtghpages/GhpagesKeys.scala | 1 + .../sbt/sbtghpages/GhpagesPlugin.scala | 23 ++++++++++++++----- 3 files changed, 28 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 8296204..c945bca 100644 --- a/README.md +++ b/README.md @@ -154,6 +154,16 @@ sbt-ghpages will only delete files which are matched by the FileFilter specified For example, to prevent sbt-ghpages from deleting the "CNAME" file located at the root of your site, and any file named "versions.html", add the following to your build.sbt: +## Maintaining Old Versions +By setting just `ghpagesKeepVersions` flag, you can maintain history of all your old and current versions of site/documents. +Behind the scenes, this flag plays two important roles: +1. Set's the `includeFilter in ghpagesCleanSite` to include all the files from current versions. + (That means, if you publish same version again, old content from that version will be replaced by new content) +2. While publishing site to gh-pages, new directory with current version's name is created and all the site contents will be + copied to that directory + +Avoid setting `includeFilter in ghpagesCleanSite` explicitly to protect old files as this is set by plugin to protect files when `ghpagesKeepVersions := true` + ```scala excludeFilter in ghpagesCleanSite := new FileFilter{ diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala index ecbf184..4a90063 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala @@ -5,6 +5,7 @@ import sbt._ import Keys._ trait GhpagesKeys { + lazy val ghpagesKeepVersions = settingKey[Boolean]("If this flag is set, ghpages will not clean existing versions of site and make sure that new site is pushed inside current version directory") lazy val ghpagesRepository = settingKey[File]("sandbox environment where git project ghpages branch is checked out.") lazy val ghpagesBranch = settingKey[String]("Name of the git branch in which to store ghpages content. Defaults to gh-pages.") lazy val ghpagesNoJekyll = settingKey[Boolean]("If this flag is set, ghpages will automatically generate a .nojekyll file to prevent github from running jekyll on pushed sites.") diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala index a18af83..705d77e 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala @@ -1,7 +1,7 @@ package com.typesafe.sbt package sbtghpages -import sbt._ +import sbt.{FileFilter, _} import Keys._ import com.typesafe.sbt.SbtGit.GitKeys import com.typesafe.sbt.git.GitRunner @@ -11,9 +11,9 @@ import com.typesafe.sbt.site.SitePlugin // Plugin to make use of github pages. object GhpagesPlugin extends AutoPlugin { override val trigger: PluginTrigger = noTrigger - override val requires: Plugins = SitePlugin && GitPlugin + override val requires: Plugins = SitePlugin && GitPlugin override lazy val globalSettings: Seq[Setting[_]] = ghpagesGlobalSettings - override lazy val projectSettings: Seq[Setting[_]] = ghpagesProjectSettings + override lazy val projectSettings: Seq[Setting[_]] = ghpagesProjectSettings object autoImport extends GhpagesKeys import autoImport._ @@ -22,6 +22,7 @@ object GhpagesPlugin extends AutoPlugin { def ghpagesGlobalSettings: Seq[Setting[_]] = Seq( ghpagesBranch := "gh-pages", + ghpagesKeepVersions := false, ghpagesNoJekyll := true ) @@ -30,7 +31,7 @@ object GhpagesPlugin extends AutoPlugin { ghpagesRepository := { val buildHash: String = Hash.toHex(Hash.apply(sbt.Keys.thisProjectRef.value.build.toASCIIString)) - file(System.getProperty("user.home")) / ".sbt" / "ghpages" / buildHash / organization.value / name.value + file(System.getProperty("user.home")) / ".sbt" / "ghpages" / buildHash / organization.value / name.value }, gitBranch in ghpagesUpdatedRepository := gitBranch.?.value getOrElse Some(ghpagesBranch.value), ghpagesUpdatedRepository := updatedRepo(ghpagesRepository, gitRemoteRepo, gitBranch in ghpagesUpdatedRepository).value, @@ -38,10 +39,18 @@ object GhpagesPlugin extends AutoPlugin { ghpagesPrivateMappings := (mappings in SitePlugin.autoImport.makeSite).value, ghpagesSynchLocal := synchLocalTask.value, ghpagesCleanSite := cleanSiteTask.value, - includeFilter in ghpagesCleanSite := AllPassFilter, + includeFilter in ghpagesCleanSite := includeFilterInCleanSiteTask.value, excludeFilter in ghpagesCleanSite := NothingFilter ) + private def includeFilterInCleanSiteTask = + Def.setting { + if (ghpagesKeepVersions.value) new FileFilter { + override def accept(pathname: File): Boolean = pathname.getAbsolutePath.contains(s"/${version.value}") + } + else AllPassFilter + } + private def updatedRepo(repo: SettingKey[File], remote: SettingKey[String], branch: SettingKey[Option[String]]) = Def.task { val local = repo.value @@ -59,7 +68,8 @@ object GhpagesPlugin extends AutoPlugin { val incl = (includeFilter in ghpagesCleanSite).value val excl = (excludeFilter in ghpagesCleanSite).value // TODO - an sbt.Synch with cache of previous mappings to make this more efficient. */ - val betterMappings = mappings map { case (file, target) => (file, repo / target) } + val betterMappings = if (ghpagesKeepVersions.value) mappings map { case (file, target) => (file, repo / version.value / target) } + else mappings map { case (file, target) => (file, repo / target) } // First, remove 'stale' files. cleanSiteForRealz(repo, GitKeys.gitRunner.value, s, incl, excl) // Now copy files. @@ -81,6 +91,7 @@ object GhpagesPlugin extends AutoPlugin { } val commitMessage = sys.env.getOrElse("SBT_GHPAGES_COMMIT_MESSAGE", "updated site") + private def pushSiteTask = Def.task { val git = GitKeys.gitRunner.value From 970061d8cc92e46da7a64d663408658a2008f38d Mon Sep 17 00:00:00 2001 From: kpritam Date: Sun, 29 Mar 2020 00:21:17 +0530 Subject: [PATCH 2/5] Add test for ghpagesKeepVersions key --- .gitignore | 1 + .../sbt/sbtghpages/GhpagesPlugin.scala | 46 +++++++++++-------- src/sbt-test/ghpages/site/build.sbt | 10 ++++ src/sbt-test/ghpages/site/expected/hello.html | 10 ++++ src/sbt-test/ghpages/site/project/plugins.sbt | 1 + .../ghpages/site/src/main/_template/page.st | 9 ++++ src/sbt-test/ghpages/site/src/main/hello.md | 3 ++ src/sbt-test/ghpages/site/test | 32 +++++++++++++ 8 files changed, 94 insertions(+), 18 deletions(-) create mode 100644 src/sbt-test/ghpages/site/build.sbt create mode 100644 src/sbt-test/ghpages/site/expected/hello.html create mode 100644 src/sbt-test/ghpages/site/project/plugins.sbt create mode 100644 src/sbt-test/ghpages/site/src/main/_template/page.st create mode 100644 src/sbt-test/ghpages/site/src/main/hello.md create mode 100644 src/sbt-test/ghpages/site/test diff --git a/.gitignore b/.gitignore index d69f9a3..8e400ed 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ *~ target/ boot/ +.idea \ No newline at end of file diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala index b2a6a75..01e7e19 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala @@ -2,11 +2,12 @@ package com.typesafe.sbt package sbtghpages import sbt.{FileFilter, _} -import Keys._ +import Keys.{mappings, _} import com.typesafe.sbt.SbtGit.GitKeys import com.typesafe.sbt.git.GitRunner import GitKeys.{gitBranch, gitRemoteRepo} import com.typesafe.sbt.site.SitePlugin + import scala.util.control.NonFatal // Plugin to make use of github pages. @@ -17,6 +18,7 @@ object GhpagesPlugin extends AutoPlugin { override lazy val projectSettings: Seq[Setting[_]] = ghpagesProjectSettings object autoImport extends GhpagesKeys + import autoImport._ // TODO - Add some sort of locking to the repository so only one thread accesses it at a time... @@ -38,20 +40,28 @@ object GhpagesPlugin extends AutoPlugin { gitBranch in ghpagesUpdatedRepository := gitBranch.?.value getOrElse Some(ghpagesBranch.value), ghpagesUpdatedRepository := updatedRepo(ghpagesRepository, gitRemoteRepo, gitBranch in ghpagesUpdatedRepository).value, ghpagesPushSite := pushSiteTask.value, - ghpagesPrivateMappings := (mappings in SitePlugin.autoImport.makeSite).value, + ghpagesPrivateMappings := ghpagesPrivateMappingsTask.value, ghpagesSynchLocal := synchLocalTask.value, ghpagesCleanSite := cleanSiteTask.value, includeFilter in ghpagesCleanSite := includeFilterInCleanSiteTask.value, excludeFilter in ghpagesCleanSite := NothingFilter ) + private def ghpagesPrivateMappingsTask = Def.task { + val makeSiteMappings = (mappings in SitePlugin.autoImport.makeSite).value + val updatedMappings = + if (ghpagesKeepVersions.value) makeSiteMappings map { case (file, target) => (file, version.value + "/" + target) } + else makeSiteMappings + updatedMappings + } + private def includeFilterInCleanSiteTask = Def.setting { if (ghpagesKeepVersions.value) new FileFilter { override def accept(pathname: File): Boolean = pathname.getAbsolutePath.contains(s"/${version.value}") } else AllPassFilter - } + } private def updatedRepo(repo: SettingKey[File], remote: SettingKey[String], branch: SettingKey[Option[String]]) = Def.task { @@ -70,13 +80,12 @@ object GhpagesPlugin extends AutoPlugin { val incl = (includeFilter in ghpagesCleanSite).value val excl = (excludeFilter in ghpagesCleanSite).value // TODO - an sbt.Synch with cache of previous mappings to make this more efficient. */ - val betterMappings = if (ghpagesKeepVersions.value) mappings map { case (file, target) => (file, repo / version.value / target) } - else mappings map { case (file, target) => (file, repo / target) } + val betterMappings = mappings map { case (file, target) => (file, repo / target) } // First, remove 'stale' files. cleanSiteForRealz(repo, GitKeys.gitRunner.value, s, incl, excl) // Now copy files. IO.copy(betterMappings) - if(ghpagesNoJekyll.value) IO.touch(repo / ".nojekyll") + if (ghpagesNoJekyll.value) IO.touch(repo / ".nojekyll") repo } @@ -84,11 +93,12 @@ object GhpagesPlugin extends AutoPlugin { Def.task { cleanSiteForRealz(ghpagesUpdatedRepository.value, GitKeys.gitRunner.value, streams.value, (includeFilter in ghpagesCleanSite).value, (excludeFilter in ghpagesCleanSite).value) } + private def cleanSiteForRealz(dir: File, git: GitRunner, s: TaskStreams, incl: FileFilter, excl: FileFilter): Unit = { val toClean = IO.listFiles(dir) - .filter(f ⇒ f.getName != ".git" && incl.accept(f) && !excl.accept(f)).map(_.getAbsolutePath).toList - if(!toClean.isEmpty) - git(("rm" :: "-r" :: "-f" :: "--ignore-unmatch" :: toClean) :_*)(dir, s.log) + .filter(f ⇒ f.getName != ".git" && incl.accept(f) && !excl.accept(f)).map(_.getAbsolutePath).toList + if (!toClean.isEmpty) + git("rm" :: "-r" :: "-f" :: "--ignore-unmatch" :: toClean: _*)(dir, s.log) () } @@ -111,14 +121,14 @@ object GhpagesPlugin extends AutoPlugin { } /** TODO - Create ghpages in the first place if it doesn't exist. - *$ cd /path/to/fancypants - *$ git symbolic-ref HEAD refs/heads/gh-pages - *$ rm .git/index - *$ git clean -fdx - * - *$ echo "My GitHub Page" > index.html - *$ git add . - *$ git commit -a -m "First pages commit" - *$ git push origin gh-pages + * $ cd /path/to/fancypants + * $ git symbolic-ref HEAD refs/heads/gh-pages + * $ rm .git/index + * $ git clean -fdx + * + * $ echo "My GitHub Page" > index.html + * $ git add . + * $ git commit -a -m "First pages commit" + * $ git push origin gh-pages */ } diff --git a/src/sbt-test/ghpages/site/build.sbt b/src/sbt-test/ghpages/site/build.sbt new file mode 100644 index 0000000..9a01780 --- /dev/null +++ b/src/sbt-test/ghpages/site/build.sbt @@ -0,0 +1,10 @@ +enablePlugins(GhpagesPlugin) +enablePlugins(ParadoxSitePlugin) + +ghpagesKeepVersions := true +git.remoteRepo := "git://github.com/sbt/sbt-ghpages.git" +ghpagesBranch := "scripted-test" +sourceDirectory in Paradox := baseDirectory.value / "src" / "main" +sourceDirectory in(Paradox, paradoxTheme) := (sourceDirectory in Paradox).value / "_template" +ghpagesRepository := target.value / "ghpages" +paradoxTheme := None diff --git a/src/sbt-test/ghpages/site/expected/hello.html b/src/sbt-test/ghpages/site/expected/hello.html new file mode 100644 index 0000000..7a0d1dd --- /dev/null +++ b/src/sbt-test/ghpages/site/expected/hello.html @@ -0,0 +1,10 @@ + + + +Hello · site + + +

Hello

+

Hello World!

+ + diff --git a/src/sbt-test/ghpages/site/project/plugins.sbt b/src/sbt-test/ghpages/site/project/plugins.sbt new file mode 100644 index 0000000..09a6614 --- /dev/null +++ b/src/sbt-test/ghpages/site/project/plugins.sbt @@ -0,0 +1 @@ +addSbtPlugin("com.typesafe.sbt" % "sbt-ghpages" % sys.props("plugin.version")) diff --git a/src/sbt-test/ghpages/site/src/main/_template/page.st b/src/sbt-test/ghpages/site/src/main/_template/page.st new file mode 100644 index 0000000..9e0cd03 --- /dev/null +++ b/src/sbt-test/ghpages/site/src/main/_template/page.st @@ -0,0 +1,9 @@ + + + +$page.title$ · $page.properties.("project.name")$ + + +$page.content$ + + diff --git a/src/sbt-test/ghpages/site/src/main/hello.md b/src/sbt-test/ghpages/site/src/main/hello.md new file mode 100644 index 0000000..2e34ae8 --- /dev/null +++ b/src/sbt-test/ghpages/site/src/main/hello.md @@ -0,0 +1,3 @@ +# Hello + +Hello World! \ No newline at end of file diff --git a/src/sbt-test/ghpages/site/test b/src/sbt-test/ghpages/site/test new file mode 100644 index 0000000..cc27a16 --- /dev/null +++ b/src/sbt-test/ghpages/site/test @@ -0,0 +1,32 @@ +####################################################################################### +# Test that site is generated in version number directory (ghpagesKeepVersions = true) +####################################################################################### +> 'set version := "1.0.0"' +> ghpagesSynchLocal + +$ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html +# Verify files does not get generated at top level +-$ must-mirror target/ghpages/hello.html expected/hello.html + +> 'set version := "2.0.0"' +> ghpagesSynchLocal + +# Verify files get generated in 2.0.0 folder +$ must-mirror target/ghpages/2.0.0/hello.html expected/hello.html + +# Verify existing versions are preserved +$ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html + +####################################################################################### +# Test that site is generated in top level directory (ghpagesKeepVersions = false) +####################################################################################### +> 'set version := "3.0.0"' +> 'set ghpagesKeepVersions := false' +> ghpagesSynchLocal + +# Verify files get generated in top level folder when ghpagesKeepVersions flag is false +$ must-mirror target/ghpages/hello.html expected/hello.html + +# Verify existing versions are preserved +$ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html +$ must-mirror target/ghpages/2.0.0/hello.html expected/hello.html \ No newline at end of file From a278ef747ce076218426849d70cd79c97d5d717c Mon Sep 17 00:00:00 2001 From: Pritam Kadam Date: Sun, 5 Apr 2020 11:54:45 +0530 Subject: [PATCH 3/5] Support automatic pointing to latest/last published version using ghpagesCopyLatestVersionAtRoot key, update README and test accordingly --- README.md | 27 ++++++++++++------- .../typesafe/sbt/sbtghpages/GhpagesKeys.scala | 1 + .../sbt/sbtghpages/GhpagesPlugin.scala | 13 ++++++--- src/sbt-test/ghpages/site/test | 24 +++++++++++------ 4 files changed, 44 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index c519d0e..e0b5259 100644 --- a/README.md +++ b/README.md @@ -154,16 +154,6 @@ sbt-ghpages will only delete files which are matched by the FileFilter specified For example, to prevent sbt-ghpages from deleting the "CNAME" file located at the root of your site, and any file named "versions.html", add the following to your build.sbt: -## Maintaining Old Versions -By setting just `ghpagesKeepVersions` flag, you can maintain history of all your old and current versions of site/documents. -Behind the scenes, this flag plays two important roles: -1. Set's the `includeFilter in ghpagesCleanSite` to include all the files from current versions. - (That means, if you publish same version again, old content from that version will be replaced by new content) -2. While publishing site to gh-pages, new directory with current version's name is created and all the site contents will be - copied to that directory - -Avoid setting `includeFilter in ghpagesCleanSite` explicitly to protect old files as this is set by plugin to protect files when `ghpagesKeepVersions := true` - ```scala excludeFilter in ghpagesCleanSite := new FileFilter{ @@ -173,6 +163,23 @@ excludeFilter in ghpagesCleanSite := For more information on creating more complex filters, please refer to the [sbt FileFilter documentation](http://www.scala-sbt.org/1.x/docs/Paths.html#File+Filters). +## Maintaining Old Versions +By setting `ghpagesKeepVersions` flag, you can maintain history of all your old and current versions of site/document. +Behind the scenes, this flag does following things: +1. Default site mappings gets prefixed with `version.value + "/"` +1. Set's the `includeFilter in ghpagesCleanSite` to include all the files from current versions. + (That means, if you publish same version again, old content from that version will be replaced by new content) +1. While publishing site to `gh-pages`, new directory with current version's name gets created and all the site content gets + copied to that directory + +## Automatic Pointing To The Latest Version +Set `ghpagesCopyLatestVersionAtRoot` flag to automatically point site to the latest version (i.e. last published version). +In this case, site content gets copied to root directory along with their version specific directory. + +**Note:** +1. Avoid setting `includeFilter in ghpagesCleanSite` explicitly to protect old files as this is set by a plugin to protect files when `ghpagesKeepVersions := true` +1. `ghpagesCopyLatestVersionAtRoot` taken into consideration only when `ghpagesKeepVersions := true` +1. `*-SNAPSHOT` version (i.e. `version.toLowerCase.contains("snapshot")`) does not get copied to top-level even when `ghpagesCopyLatestVersionAtRoot` is set ## LICENSE ## diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala index a7c617b..bc31db0 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesKeys.scala @@ -6,6 +6,7 @@ import Keys._ trait GhpagesKeys { lazy val ghpagesKeepVersions = settingKey[Boolean]("If this flag is set, ghpages will not clean existing versions of site and make sure that new site is pushed inside current version directory") + lazy val ghpagesCopyLatestVersionAtRoot = settingKey[Boolean]("If this flag is set, ghpages will keep a copy of site at root level directory so that site will always point to latest version. Note: Snapshots versions are not copied to root") lazy val ghpagesCommitOptions = settingKey[Seq[String]]("commit options") lazy val ghpagesRepository = settingKey[File]("sandbox environment where git project ghpages branch is checked out.") lazy val ghpagesBranch = settingKey[String]("Name of the git branch in which to store ghpages content. Defaults to gh-pages.") diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala index 01e7e19..1aa367a 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala @@ -26,6 +26,7 @@ object GhpagesPlugin extends AutoPlugin { def ghpagesGlobalSettings: Seq[Setting[_]] = Seq( ghpagesBranch := "gh-pages", ghpagesKeepVersions := false, + ghpagesCopyLatestVersionAtRoot := false, ghpagesNoJekyll := true ) @@ -47,11 +48,17 @@ object GhpagesPlugin extends AutoPlugin { excludeFilter in ghpagesCleanSite := NothingFilter ) + private def isSnapshot = Def.task(version.value.toLowerCase.contains("snapshot")) + private def ghpagesPrivateMappingsTask = Def.task { - val makeSiteMappings = (mappings in SitePlugin.autoImport.makeSite).value + val defaultMappings = (mappings in SitePlugin.autoImport.makeSite).value val updatedMappings = - if (ghpagesKeepVersions.value) makeSiteMappings map { case (file, target) => (file, version.value + "/" + target) } - else makeSiteMappings + if (ghpagesKeepVersions.value) { + val mappingsWithVersionDir = defaultMappings map { case (file, target) => (file, version.value + "/" + target) } + if (ghpagesCopyLatestVersionAtRoot.value && !isSnapshot.value) defaultMappings ++ mappingsWithVersionDir + else mappingsWithVersionDir + } + else defaultMappings updatedMappings } diff --git a/src/sbt-test/ghpages/site/test b/src/sbt-test/ghpages/site/test index cc27a16..efc7185 100644 --- a/src/sbt-test/ghpages/site/test +++ b/src/sbt-test/ghpages/site/test @@ -8,25 +8,33 @@ $ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html # Verify files does not get generated at top level -$ must-mirror target/ghpages/hello.html expected/hello.html -> 'set version := "2.0.0"' +####################################################################################### +# Test that SNAPSHOT versions always gets generated in version number directory (ghpagesKeepVersions = true) +# even when ghpagesCopyLatestVersionAtRoot is true +####################################################################################### +> 'set version := "2.0.0-SNAPSHOT"' +> 'set ghpagesCopyLatestVersionAtRoot := true' > ghpagesSynchLocal -# Verify files get generated in 2.0.0 folder -$ must-mirror target/ghpages/2.0.0/hello.html expected/hello.html +# Verify files get generated in 2.0.0-SNAPSHOT folder +$ must-mirror target/ghpages/2.0.0-SNAPSHOT/hello.html expected/hello.html +-$ must-mirror target/ghpages/hello.html expected/hello.html # Verify existing versions are preserved $ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html ####################################################################################### -# Test that site is generated in top level directory (ghpagesKeepVersions = false) +# Test that site is generated in version number directory (ghpagesKeepVersions = true) +# as well as at root directory (ghpagesCopyLatestVersionAtRoot = true) ####################################################################################### -> 'set version := "3.0.0"' -> 'set ghpagesKeepVersions := false' +> 'set version := "2.0.0"' +> 'set ghpagesCopyLatestVersionAtRoot := true' > ghpagesSynchLocal -# Verify files get generated in top level folder when ghpagesKeepVersions flag is false +# Verify files get generated in 2.0.0 folder +$ must-mirror target/ghpages/2.0.0/hello.html expected/hello.html $ must-mirror target/ghpages/hello.html expected/hello.html # Verify existing versions are preserved $ must-mirror target/ghpages/1.0.0/hello.html expected/hello.html -$ must-mirror target/ghpages/2.0.0/hello.html expected/hello.html \ No newline at end of file +$ must-mirror target/ghpages/2.0.0-SNAPSHOT/hello.html expected/hello.html \ No newline at end of file From 73eb305cf2b84194acdf01a765acbc127961d1b3 Mon Sep 17 00:00:00 2001 From: Pritam Kadam Date: Mon, 6 Apr 2020 16:30:43 +0530 Subject: [PATCH 4/5] Make isSnapshot a dynamic task --- src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala index 1aa367a..1596c50 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala @@ -48,7 +48,7 @@ object GhpagesPlugin extends AutoPlugin { excludeFilter in ghpagesCleanSite := NothingFilter ) - private def isSnapshot = Def.task(version.value.toLowerCase.contains("snapshot")) + private def isSnapshot = Def.taskDyn(Def.task(version.value.toLowerCase.contains("snapshot"))) private def ghpagesPrivateMappingsTask = Def.task { val defaultMappings = (mappings in SitePlugin.autoImport.makeSite).value From d6cc02f1aa467688968b9dba61ac414313992a34 Mon Sep 17 00:00:00 2001 From: Pritam Kadam Date: Mon, 6 Apr 2020 17:01:04 +0530 Subject: [PATCH 5/5] Statically evaluate isSnapshot --- .../scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala index 1596c50..8d95030 100644 --- a/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala +++ b/src/main/scala/com/typesafe/sbt/sbtghpages/GhpagesPlugin.scala @@ -6,6 +6,7 @@ import Keys.{mappings, _} import com.typesafe.sbt.SbtGit.GitKeys import com.typesafe.sbt.git.GitRunner import GitKeys.{gitBranch, gitRemoteRepo} +import com.typesafe.sbt.sbtghpages.GhpagesPlugin.isSnapshot import com.typesafe.sbt.site.SitePlugin import scala.util.control.NonFatal @@ -48,14 +49,15 @@ object GhpagesPlugin extends AutoPlugin { excludeFilter in ghpagesCleanSite := NothingFilter ) - private def isSnapshot = Def.taskDyn(Def.task(version.value.toLowerCase.contains("snapshot"))) + private def isSnapshot = Def.task(version.value.toLowerCase.contains("snapshot")) private def ghpagesPrivateMappingsTask = Def.task { val defaultMappings = (mappings in SitePlugin.autoImport.makeSite).value + val snapshot = isSnapshot.value val updatedMappings = if (ghpagesKeepVersions.value) { val mappingsWithVersionDir = defaultMappings map { case (file, target) => (file, version.value + "/" + target) } - if (ghpagesCopyLatestVersionAtRoot.value && !isSnapshot.value) defaultMappings ++ mappingsWithVersionDir + if (ghpagesCopyLatestVersionAtRoot.value && !snapshot) defaultMappings ++ mappingsWithVersionDir else mappingsWithVersionDir } else defaultMappings