Skip to content

Commit

Permalink
Fix github action
Browse files Browse the repository at this point in the history
If the ci runs on a push to the main branch, the readme checks should
be skipped.
  • Loading branch information
eikek committed Sep 27, 2024
1 parent f29a442 commit 62ae2d1
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 9 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- uses: cachix/install-nix-action@v27
- name: sbt ci ${{ github.ref }}
env:
README_BASE_REF: origin/${{ github.base_ref }}
README_BASE_REF: ${{ github.base_ref && format('origin/{0}', github.base_ref) || '_skip_' }}
run: nix develop .#ci --command sbt ci
ci:
runs-on: ubuntu-latest
Expand Down
32 changes: 24 additions & 8 deletions project/ReadmePlugin.scala
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ object ReadmePlugin extends AutoPlugin {
override def requires = MdocPlugin && GitPlugin
object autoImport {
val readmeUpdate = inputKey[Unit]("Update the root README.md")
val readmeBaseRef = settingKey[String]("The base ref to check modification against")
val readmeBaseRef =
settingKey[Option[String]]("The base ref to check modification against")
val readmeCheckModification = taskKey[Unit](
"Check the diff against the target branch for modifications to generated files"
)
Expand All @@ -30,21 +31,36 @@ object ReadmePlugin extends AutoPlugin {
mdocOut := (LocalRootProject / baseDirectory).value / "README.md",
fork := true,
readmeAdditionalFiles := Map.empty,
readmeBaseRef := sys.env
.get("README_BASE_REF")
.map(_.trim)
.filter(_.nonEmpty)
.orElse(Some("HEAD"))
.flatMap {
case "_skip_" => None
case ref => Some(s"${ref}^{tree}")
},
readmeCheckModification := {
val bref = readmeBaseRef.value
val dir = (LocalRootProject / baseDirectory).value
val additional = readmeAdditionalFiles.value
val readmeIn = mdocIn.value
val readmeOut = mdocOut.value
val logger = streams.value.log
checkModification(logger, bref, dir, readmeIn, readmeOut, additional, dir / "docs")
bref match {
case Some(ref) =>
checkModification(
logger,
ref,
dir,
readmeIn,
readmeOut,
additional,
dir / "docs"
)
case None => logger.info("Skipping readme modification checks")
}
},
readmeBaseRef := sys.env
.get("README_BASE_REF")
.map(_.trim)
.filter(_.nonEmpty)
.map(ref => s"${ref}^{tree}")
.getOrElse("HEAD^{tree}"),
readmeUpdate := {
mdoc.evaluated
val logger = streams.value.log
Expand Down

0 comments on commit 62ae2d1

Please sign in to comment.