Skip to content

Commit 6247ec7

Browse files
authored
Merge pull request #2449 from typelevel/jatcwang/publish_docs_on_release
Publish docs on release, fix manual publish job
2 parents 9d5582d + 0379f32 commit 6247ec7

3 files changed

Lines changed: 69 additions & 3 deletions

File tree

.github/workflows/ci.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,20 @@ on:
1414
branches: ['**', '!update/**', '!pr/**']
1515
tags: [v*]
1616

17+
permissions:
18+
actions: none
19+
checks: none
20+
contents: write
21+
deployments: none
22+
id-token: none
23+
issues: none
24+
packages: read
25+
pages: none
26+
pull-requests: none
27+
repository-projects: none
28+
security-events: none
29+
statuses: none
30+
1731
env:
1832
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1933

@@ -164,6 +178,22 @@ jobs:
164178
SONATYPE_CREDENTIAL_HOST: ${{ secrets.SONATYPE_CREDENTIAL_HOST }}
165179
run: sbt tlCiRelease
166180

181+
- name: Start up Postgres for docs publish
182+
if: startsWith(github.ref, 'refs/tags/v')
183+
run: docker compose up -d
184+
185+
- name: Configure git for docs publish
186+
if: startsWith(github.ref, 'refs/tags/v')
187+
run: |
188+
git config --global user.name "github-actions[bot]"
189+
git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com"
190+
191+
- name: Publish Doc Site
192+
if: startsWith(github.ref, 'refs/tags/v')
193+
env:
194+
SBT_GHPAGES_COMMIT_MESSAGE: Update docs for ${{ github.ref_name }}
195+
run: sbt docs/makeSite docs/ghpagesPushSite
196+
167197
dependency-submission:
168198
name: Submit Dependencies
169199
if: github.event.repository.fork == false && github.event_name != 'pull_request'

.github/workflows/publish-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ jobs:
5555
run: |
5656
git config user.name "github-actions[bot]"
5757
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
58-
git fetch origin gh-pages:gh-pages
59-
git worktree add doc_worktree gh-pages
58+
git fetch origin gh-pages:refs/remotes/origin/gh-pages
59+
git worktree add --track -B gh-pages doc_worktree origin/gh-pages
6060
6161
- name: Publish docs
6262
env:

build.sbt

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import FreeGen2._
22
import scala.sys.process._
3+
import org.typelevel.sbt.gha.{PermissionValue, Permissions}
34
import org.typelevel.sbt.tpolecat.{DevMode, CiMode}
45

56
// Library versions all in one place, for convenience and sanity.
@@ -28,6 +29,18 @@ lazy val scala212Version = "2.12.21"
2829
lazy val scala213Version = "2.13.18"
2930
lazy val scala3Version = "3.3.8"
3031
lazy val allScalaVersions = List(scala212Version, scala213Version, scala3Version)
32+
lazy val doobieGitRemote =
33+
if (sys.env.get("GITHUB_ACTIONS").contains("true"))
34+
sys.env
35+
.get("GITHUB_TOKEN")
36+
.filter(_.nonEmpty)
37+
.map(token => s"https://x-access-token:$token@github.com/typelevel/doobie.git")
38+
.getOrElse("https://github.com/typelevel/doobie.git")
39+
else
40+
"git@github.com:typelevel/doobie.git"
41+
lazy val doobieGithubWorkflowPermissions =
42+
Permissions.Specify.defaultRestrictive
43+
.withContents(PermissionValue.Write)
3144
// scala-steward:off
3245
lazy val slf4jVersion = "1.7.36"
3346
// scala-steward:on
@@ -44,6 +57,8 @@ ThisBuild / developers += tlGitHubDev("tpolecat", "Rob Norris")
4457
ThisBuild / tpolecatDefaultOptionsMode :=
4558
(if (sys.env.contains("CI")) CiMode else DevMode)
4659
ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("11"))
60+
useReadableConsoleGit
61+
ThisBuild / githubWorkflowPermissions := Some(doobieGithubWorkflowPermissions)
4762
ThisBuild / githubWorkflowBuildPreamble ++= Seq(
4863
WorkflowStep.Run(
4964
commands = List("docker compose up -d"),
@@ -86,6 +101,27 @@ ThisBuild / githubWorkflowJobSetup ~= { steps =>
86101
case s => s
87102
}
88103
}
104+
ThisBuild / githubWorkflowPublishPostamble ++= Seq(
105+
WorkflowStep.Run(
106+
commands = List("docker compose up -d"),
107+
name = Some("Start up Postgres for docs publish"),
108+
cond = Some("startsWith(github.ref, 'refs/tags/v')")
109+
),
110+
WorkflowStep.Run(
111+
commands = List(
112+
"git config --global user.name \"github-actions[bot]\"",
113+
"git config --global user.email \"41898282+github-actions[bot]@users.noreply.github.com\""
114+
),
115+
name = Some("Configure git for docs publish"),
116+
cond = Some("startsWith(github.ref, 'refs/tags/v')")
117+
),
118+
WorkflowStep.Sbt(
119+
commands = List("docs/makeSite", "docs/ghpagesPushSite"),
120+
name = Some("Publish Doc Site"),
121+
cond = Some("startsWith(github.ref, 'refs/tags/v')"),
122+
env = Map("SBT_GHPAGES_COMMIT_MESSAGE" -> "Update docs for ${{ github.ref_name }}")
123+
)
124+
)
89125

90126
ThisBuild / mergifyPrRules += MergifyPrRule(
91127
name = "merge-when-ci-pass",
@@ -576,7 +612,7 @@ lazy val docs = projectMatrix
576612

577613
// postgis is `provided` dependency for users, and section from book of doobie needs it
578614
libraryDependencies += postgisDep,
579-
git.remoteRepo := "git@github.com:typelevel/doobie.git",
615+
git.remoteRepo := doobieGitRemote,
580616
ghpagesNoJekyll := true,
581617
publish / skip := true,
582618
paradoxTheme := Some(builtinParadoxTheme("generic")),

0 commit comments

Comments
 (0)