-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
618 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# This file was autogenerated using `zio-sbt` via `sbt generateGithubWorkflow` | ||
# task and should be included in the git repository. Please do not edit | ||
# it manually. | ||
|
||
name: Website | ||
'on': | ||
release: | ||
types: | ||
- published | ||
jobs: | ||
publish-docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Git Checkout | ||
with: | ||
fetch-depth: '0' | ||
uses: actions/[email protected] | ||
- name: Setup Scala | ||
with: | ||
node-version: 16.x | ||
registry-url: https://registry.npmjs.org | ||
uses: actions/[email protected] | ||
- env: | ||
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} | ||
name: Publish Docs to NPM Registry | ||
run: sbt docs/publishToNpm | ||
name: Publish Docs to The NPM Registry | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.3.6") | ||
|
||
libraryDependencies += "dev.zio" %% "zio" % "2.0.2" | ||
libraryDependencies += "dev.zio" %% "zio" % "2.0.4" | ||
libraryDependencies += "io.circe" %% "circe-yaml" % "0.14.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,7 +16,7 @@ | |
|
||
package zio.sbt | ||
|
||
import java.nio.file.{Files, Path, Paths} | ||
import java.nio.file.{Path, Paths} | ||
|
||
import scala.sys.process.* | ||
|
||
|
@@ -207,7 +207,7 @@ object WebsitePlugin extends sbt.AutoPlugin { | |
|
||
Unsafe.unsafe { implicit unsafe => | ||
Runtime.default.unsafe | ||
.run(WebsitePluginUtils.generateReadme(websiteDir.value.resolve("docs/index.md").toString)) | ||
.run(WebsiteUtils.generateReadme(websiteDir.value.resolve("docs/index.md").toString)) | ||
.getOrThrowFiberFailure() | ||
} | ||
val logger = streams.value.log | ||
|
@@ -221,81 +221,12 @@ object WebsitePlugin extends sbt.AutoPlugin { | |
val template = | ||
s"""|# This file was autogenerated using `zio-sbt` via `sbt generateGithubWorkflow` | ||
|# task and should be included in the git repository. Please do not edit | ||
|# it manually. | ||
|# it manually. | ||
| | ||
|name: website | ||
| | ||
|on: | ||
| release: | ||
| types: [ published ] | ||
| | ||
|jobs: | ||
| publish-docs: | ||
| runs-on: ubuntu-20.04 | ||
| timeout-minutes: 30 | ||
| steps: | ||
| - uses: actions/[email protected] | ||
| with: | ||
| fetch-depth: 0 | ||
| - name: Setup Scala and Java | ||
| uses: actions/[email protected] | ||
| with: | ||
| distribution: temurin | ||
| java-version: 17 | ||
| check-latest: true | ||
| - uses: actions/setup-node@v3 | ||
| with: | ||
| node-version: '16.x' | ||
| registry-url: 'https://registry.npmjs.org' | ||
| - name: Publishing Docs to NPM Registry | ||
| run: sbt docs/publishToNpm | ||
| env: | ||
| NODE_AUTH_TOKEN: $${{ secrets.NPM_TOKEN }} | ||
|${WebsiteUtils.websiteWorkflow} | ||
|""".stripMargin | ||
|
||
IO.write(new File(".github/workflows/site.yml"), template) | ||
} | ||
|
||
} | ||
|
||
object WebsitePluginUtils { | ||
import zio.* | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
def removeYamlHeader(markdown: String): String = | ||
markdown | ||
.split("\n") | ||
.dropWhile(_ == "---") | ||
.dropWhile(_ != "---") | ||
.dropWhile(_ == "---") | ||
.mkString("\n") | ||
|
||
def readFile(pathname: String): Task[String] = | ||
ZIO.attemptBlocking { | ||
val source = scala.io.Source.fromFile(new File(pathname)) | ||
val result = source.getLines().mkString("\n") | ||
source.close() | ||
result | ||
} | ||
|
||
def generateReadme(sourcePath: String): Task[Unit] = | ||
for { | ||
template <- readFile("README.template.md") | ||
mainContent <- readFile(sourcePath).map(md => removeYamlHeader(md)) | ||
comment = | ||
"""|[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.) | ||
|[//]: # (So please do not edit it manually. Instead, edit `README.template.md` file. This command will replace any) | ||
|[//]: # ({{ main_content }} template tag inside the `README.template.md` file with the main content of the) | ||
|[//]: # ("docs/index.md" file.) | ||
|""".stripMargin | ||
readme <- ZIO.succeed(comment + '\n' + template.replaceFirst("\\{\\{.*main_content.*}}", mainContent)) | ||
_ <- ZIO.attemptBlocking( | ||
Files.write( | ||
Paths.get("README.md"), | ||
readme.getBytes(StandardCharsets.UTF_8) | ||
) | ||
) | ||
} yield () | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
package zio.sbt | ||
|
||
import java.nio.file.{Files, Paths} | ||
|
||
import io.circe.syntax.* | ||
import sbt.File | ||
|
||
import zio.* | ||
import zio.sbt.githubactions.* | ||
|
||
object WebsiteUtils { | ||
|
||
import java.nio.charset.StandardCharsets | ||
|
||
def removeYamlHeader(markdown: String): String = | ||
markdown | ||
.split("\n") | ||
.dropWhile(_ == "---") | ||
.dropWhile(_ != "---") | ||
.dropWhile(_ == "---") | ||
.mkString("\n") | ||
|
||
def readFile(pathname: String): Task[String] = | ||
ZIO.attemptBlocking { | ||
val source = scala.io.Source.fromFile(new File(pathname)) | ||
val result = source.getLines().mkString("\n") | ||
source.close() | ||
result | ||
} | ||
|
||
def generateReadme(sourcePath: String): Task[Unit] = | ||
for { | ||
template <- readFile("README.template.md") | ||
mainContent <- readFile(sourcePath).map(md => removeYamlHeader(md)) | ||
comment = | ||
"""|[//]: # (This file was autogenerated using `zio-sbt-website` plugin via `sbt generateReadme` command.) | ||
|[//]: # (So please do not edit it manually. Instead, edit `README.template.md` file. This command will replace any) | ||
|[//]: # ({{ main_content }} template tag inside the `README.template.md` file with the main content of the) | ||
|[//]: # ("docs/index.md" file.) | ||
|""".stripMargin | ||
readme <- ZIO.succeed(comment + '\n' + template.replaceFirst("\\{\\{.*main_content.*}}", mainContent)) | ||
_ <- ZIO.attemptBlocking( | ||
Files.write( | ||
Paths.get("README.md"), | ||
readme.getBytes(StandardCharsets.UTF_8) | ||
) | ||
) | ||
} yield () | ||
|
||
val websiteWorkflow: String = | ||
io.circe.yaml | ||
.Printer(dropNullKeys = true) | ||
.pretty( | ||
Workflow( | ||
name = "Website", | ||
triggers = Seq(Trigger.Release(Seq("published"))), | ||
jobs = Seq( | ||
Job( | ||
id = "publish-docs", | ||
name = "Publish Docs to The NPM Registry", | ||
steps = Seq( | ||
Step.StepSequence( | ||
Seq( | ||
Step.SingleStep( | ||
name = "Git Checkout", | ||
uses = Some(ActionRef("actions/[email protected]")), | ||
parameters = Map("fetch-depth" -> "0".asJson) | ||
), | ||
Step.SingleStep( | ||
name = "Setup Scala", | ||
uses = Some(ActionRef("actions/[email protected]")), | ||
parameters = Map( | ||
"node-version" -> "16.x".asJson, | ||
"registry-url" -> "https://registry.npmjs.org".asJson | ||
) | ||
), | ||
Step.SingleStep( | ||
name = "Publish Docs to NPM Registry", | ||
run = Some("sbt docs/publishToNpm"), | ||
env = Map( | ||
"NODE_AUTH_TOKEN" -> "${{ secrets.NPM_TOKEN }}" | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
) | ||
).asJson | ||
) | ||
|
||
} |
Oops, something went wrong.