Skip to content

Commit

Permalink
Merge pull request #2347 from alexarchambault/fix-website-ci
Browse files Browse the repository at this point in the history
Fix website CI
  • Loading branch information
alexarchambault committed Jan 31, 2022
2 parents 68e654e + 25b0c8d commit f869d79
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 22 deletions.
8 changes: 5 additions & 3 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -790,7 +790,8 @@ def updateWebsite(dryRun: Boolean = false) = {
versionedDocsBranch,
ghTokenOpt = Some(token),
newVersion = version,
dryRun = dryRun
dryRun = dryRun,
cloneUnder = T.dest / "repo"
)

// copyDemoFiles()
Expand All @@ -800,8 +801,9 @@ def updateWebsite(dryRun: Boolean = false) = {
token,
"coursier/coursier",
branch = "gh-pages",
dryRun = dryRun
)()
dryRun = dryRun,
dest = T.dest / "gh-pages"
)
}
}

Expand Down
48 changes: 30 additions & 18 deletions project/docs.sc
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
def copyDocusaurusVersionedData(
repo: String,
branch: String,
docusaurusDir: os.Path
) = T.command {
docusaurusDir: os.Path,
cloneUnder: os.Path
): Unit = {

val remote = s"https://github.com/$repo.git"

val cloneUnder = T.dest / "repo"

os.proc("git", "clone", remote, "-b", branch, cloneUnder.toString).call(
stdin = os.Inherit,
stdout = os.Inherit,
Expand Down Expand Up @@ -35,21 +34,30 @@ def copyDocusaurusVersionedData(
}
}

private def runAndLog(secrets: Seq[String])(command: os.Shellable*) = {
val msg = secrets.foldLeft(s"Running ${command.flatMap(_.value)}") { (msg0, secret) =>
msg0.replace(secret, "****")
}
System.err.println(msg)
os.proc(command: _*)
}

def updateVersionedDocs(
docusaurusDir: os.Path,
repo: String,
branch: String,
ghTokenOpt: Option[String],
newVersion: String,
dryRun: Boolean
) = T.command {
dryRun: Boolean,
cloneUnder: os.Path
): Unit = {

val remote = s"https://${ghTokenOpt.map(_ + "@").getOrElse("")}github.com/$repo.git"

val cloneUnder = T.dest / "repo"
os.makeDir.all(cloneUnder)

os.proc("git", "clone", remote, "-b", branch, cloneUnder.toString).call(
System.err.println()
runAndLog(ghTokenOpt.toSeq)("git", "clone", remote, "-b", branch, cloneUnder.toString).call(
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
Expand All @@ -58,20 +66,20 @@ def updateVersionedDocs(
// TODO Check if newVersion is already in versions.json

// FIXME We don't necessarily run on Travis CI
os.proc("git", "config", "user.name", "Github Actions").call(
runAndLog(ghTokenOpt.toSeq)("git", "config", "user.name", "Github Actions").call(
cwd = cloneUnder,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
)
os.proc("git", "config", "user.email", "actions@github.com").call(
runAndLog(ghTokenOpt.toSeq)("git", "config", "user.email", "actions@github.com").call(
cwd = cloneUnder,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
)

os.proc("yarn", "run", "version", newVersion).call(
runAndLog(ghTokenOpt.toSeq)("yarn", "run", "version", newVersion).call(
cwd = docusaurusDir,
stdin = os.Inherit,
stdout = os.Inherit,
Expand All @@ -80,17 +88,21 @@ def updateVersionedDocs(

val toCopy = os.list(docusaurusDir).filter(_.last.startsWith("version"))

for (elem <- toCopy)
os.copy.into(elem, cloneUnder)
for (elem <- toCopy) {
val dest = cloneUnder / elem.last
if (os.exists(dest))
os.remove.all(dest)
os.copy(elem, dest)
}

os.proc("git", "add", toCopy.map(_.last)).call(
runAndLog(ghTokenOpt.toSeq)("git", "add", toCopy.map(_.last)).call(
cwd = cloneUnder,
stdin = os.Inherit,
stdout = os.Inherit,
stderr = os.Inherit
)

os.proc("git", "commit", "-m", s"Add doc for $newVersion").call(
runAndLog(ghTokenOpt.toSeq)("git", "commit", "-m", s"Add doc for $newVersion").call(
cwd = cloneUnder,
stdin = os.Inherit,
stdout = os.Inherit,
Expand All @@ -99,7 +111,7 @@ def updateVersionedDocs(
if (dryRun)
System.err.println(s"Would have pushed new docs to $repo")
else
os.proc("git", "push", "origin", branch).call(
runAndLog(ghTokenOpt.toSeq)("git", "push", "origin", branch).call(
cwd = cloneUnder,
stdin = os.Inherit,
stdout = os.Inherit,
Expand All @@ -114,11 +126,11 @@ def updateGhPages(
ghToken: String,
repo: String,
dryRun: Boolean,
dest: os.Path,
branch: String = "gh-pages"
) = T.command {
): Unit = {
val remote = s"https://$ghToken@github.com/$repo.git"

val dest = T.dest / "gh-pages"
os.makeDir.all(dest)

os.proc("git", "clone", remote, "-q", "-b", branch, dest.toString).call(
Expand Down
2 changes: 1 addition & 1 deletion project/modules/doc0.sc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ trait Doc extends ScalaModule {
branch: String = "master",
docusaurusDir: os.Path = os.pwd / "doc" / "website"
) = T.command {
docs.copyDocusaurusVersionedData(repo, branch, docusaurusDir)
docs.copyDocusaurusVersionedData(repo, branch, docusaurusDir, T.dest / "repo")
}

def forkWorkingDir = T.dest
Expand Down

0 comments on commit f869d79

Please sign in to comment.