Skip to content

Commit 6b942f9

Browse files
authored
Merge pull request #183 from danicheg/tlSitePublishTags
Add the `tlSitePublishTags` setting
2 parents 2113388 + 687cf51 commit 6b942f9

File tree

2 files changed

+48
-24
lines changed

2 files changed

+48
-24
lines changed

docs/customization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ Instead of using the super-plugins, for finer-grained control you can always add
6363
### sbt-typelevel-site
6464
- `TypelevelSitePlugin`: Sets up an [mdoc](https://scalameta.org/mdoc/)/[Laika](https://planet42.github.io/Laika/)-generated microsite, automatically published to GitHub pages in CI.
6565
- `tlSitePublishBranch` (setting): The branch to publish the site from on every push. Set this to `None` if you only want to update the site on tag releases. (default: `main`)
66+
- `tlSitePublishTags` (setting): Defines whether the site should be published on tag releases. Note on setting this to `true` requires the `tlSitePublishBranch` setting to be set to `None`. (default: `false`)
6667
- `tlSiteApiUrl` (setting): URL to the API docs. (default: `None`)
6768
- `tlSiteHeliumConfig` (setting): the Laika Helium config. (default: how the sbt-typelevel site looks)
6869

site/src/main/scala/org/typelevel/sbt/TypelevelSitePlugin.scala

Lines changed: 47 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@ object TypelevelSitePlugin extends AutoPlugin {
5656
"A sequence of workflow steps which publishes the site (default: peaceiris/actions-gh-pages)")
5757
lazy val tlSitePublishBranch = settingKey[Option[String]](
5858
"The branch to publish the site from on every push. Set this to None if you only want to update the site on tag releases. (default: main)")
59+
lazy val tlSitePublishTags = settingKey[Boolean](
60+
"Defines whether the site should be published on tag releases. Note on setting this to true requires the 'tlSitePublishBranch' setting to be set to None. (default: false)")
5961
lazy val tlSite = taskKey[Unit]("Generate the site (default: runs mdoc then laika)")
6062
lazy val tlSitePreview = taskKey[Unit](
6163
"Start a live-reload preview server (combines mdoc --watch with laikaPreview)")
@@ -73,6 +75,7 @@ object TypelevelSitePlugin extends AutoPlugin {
7375

7476
override def buildSettings = Seq(
7577
tlSitePublishBranch := Some("main"),
78+
tlSitePublishTags := tlSitePublishBranch.value.isEmpty,
7679
tlSiteApiUrl := None,
7780
tlSiteRelatedProjects := Seq(TypelevelProject.Cats),
7881
tlSiteKeepFiles := true,
@@ -160,30 +163,50 @@ object TypelevelSitePlugin extends AutoPlugin {
160163
name = Some("Generate site")
161164
)
162165
),
163-
tlSitePublish := List(
164-
WorkflowStep.Use(
165-
UseRef.Public("peaceiris", "actions-gh-pages", "v3.8.0"),
166-
Map(
167-
"github_token" -> s"$${{ secrets.GITHUB_TOKEN }}",
168-
"publish_dir" -> (ThisBuild / baseDirectory)
169-
.value
170-
.toPath
171-
.toAbsolutePath
172-
.relativize((laikaSite / target).value.toPath)
173-
.toString,
174-
"keep_files" -> tlSiteKeepFiles.value.toString
175-
),
176-
name = Some("Publish site"),
177-
cond = {
178-
val predicate = tlSitePublishBranch
179-
.value // Either publish from branch or on tags, not both
180-
.fold[RefPredicate](RefPredicate.StartsWith(Ref.Tag("v")))(b =>
181-
RefPredicate.Equals(Ref.Branch(b)))
182-
val publicationCond = GenerativePlugin.compileBranchPredicate("github.ref", predicate)
183-
Some(s"github.event_name != 'pull_request' && $publicationCond")
184-
}
185-
)
186-
),
166+
tlSitePublish := {
167+
def publishSiteWorkflowStep(publishPredicate: RefPredicate) =
168+
List(
169+
WorkflowStep.Use(
170+
UseRef.Public("peaceiris", "actions-gh-pages", "v3.8.0"),
171+
Map(
172+
"github_token" -> s"$${{ secrets.GITHUB_TOKEN }}",
173+
"publish_dir" -> (ThisBuild / baseDirectory)
174+
.value
175+
.toPath
176+
.toAbsolutePath
177+
.relativize((laikaSite / target).value.toPath)
178+
.toString,
179+
"keep_files" -> tlSiteKeepFiles.value.toString
180+
),
181+
name = Some("Publish site"),
182+
cond = {
183+
val predicate = publishPredicate
184+
val publicationCond =
185+
GenerativePlugin.compileBranchPredicate("github.ref", predicate)
186+
Some(s"github.event_name != 'pull_request' && $publicationCond")
187+
}
188+
)
189+
)
190+
191+
val tlSitePublishTagsV = tlSitePublishTags.value
192+
val tlSitePublishBranchV = tlSitePublishBranch.value
193+
194+
(tlSitePublishTagsV, tlSitePublishBranchV) match {
195+
case (true, Some(_)) =>
196+
sys.error(
197+
s"'tlSitePublishTags' setting is set to 'true' which conflicts with 'tlSitePublishBranch' which is non-empty. " +
198+
s"Site publishing is available from tags or a particular branch, not from both.")
199+
200+
case (true, None) =>
201+
publishSiteWorkflowStep(RefPredicate.StartsWith(Ref.Tag("v")))
202+
203+
case (false, Some(branch)) =>
204+
publishSiteWorkflowStep(RefPredicate.Equals(Ref.Branch(branch)))
205+
206+
case (false, None) =>
207+
List.empty
208+
}
209+
},
187210
ThisBuild / githubWorkflowAddedJobs +=
188211
WorkflowJob(
189212
"site",

0 commit comments

Comments
 (0)