Skip to content

Commit d67c921

Browse files
committed
docs: Generate changelog before release
1 parent 7077b72 commit d67c921

File tree

2 files changed

+208
-64
lines changed

2 files changed

+208
-64
lines changed

.github/workflows/ci.yml

Lines changed: 78 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989

9090
publish:
9191
name: Publish Artifacts
92-
needs: [build]
92+
needs: [prepare-release]
9393
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
9494
strategy:
9595
matrix:
@@ -212,6 +212,83 @@ jobs:
212212

213213
- run: scala-steward validate-repo-config .scala-steward.conf
214214

215+
prepare-release:
216+
name: 👷 Prepare release
217+
needs: [build]
218+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
219+
strategy:
220+
matrix:
221+
os: [ubuntu-latest]
222+
scala: [2.13]
223+
java: [temurin@11]
224+
runs-on: ${{ matrix.os }}
225+
permissions:
226+
actions: write
227+
checks: write
228+
contents: write
229+
deployments: write
230+
id-token: none
231+
issues: write
232+
packages: write
233+
pages: write
234+
pull-requests: write
235+
repository-projects: write
236+
security-events: write
237+
statuses: write
238+
env:
239+
DTC_HEADLESS: true
240+
steps:
241+
- name: Checkout current branch (full)
242+
uses: actions/checkout@v4
243+
with:
244+
fetch-depth: 0
245+
246+
- name: Get previous tag
247+
id: previousTag
248+
run: |
249+
name=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | tail -2 | head -1)
250+
ref_name="${{ github.ref_name }}"
251+
prefix="prepare-"
252+
next_version=${ref_name/#$prefix}
253+
echo "previousTag=$name"
254+
echo "previousTag=$name" >> $GITHUB_ENV
255+
echo "nextTag=$next_version"
256+
echo "nextTag=$next_version" >> $GITHUB_ENV
257+
258+
- name: Update CHANGELOG
259+
id: changelog
260+
uses: requarks/changelog-action@v1
261+
with:
262+
token: ${{ github.token }}
263+
fromTag: ${{ github.ref_name }}
264+
toTag: ${{ env.previousTag }}
265+
writeToFile: true
266+
267+
- name: Commit CHANGELOG.md
268+
uses: stefanzweifel/git-auto-commit-action@v5
269+
with:
270+
commit_message: 'docs: update CHANGELOG.md for ${{ env.nextTag }} [skip ci]'
271+
branch: main
272+
file_pattern: CHANGELOG.md docToolchainConfig.groovy
273+
274+
- name: Create version tag
275+
uses: rickstaa/action-create-tag@v1
276+
with:
277+
tag: ${{ github.ref_name }}
278+
message: Release ${{ github.ref_name }}
279+
force_push_tag: true
280+
281+
- name: Create release
282+
uses: ncipollo/[email protected]
283+
with:
284+
body: ${{ steps.changelog.outputs.changes }}
285+
name: ${{ env.nextTag }}
286+
tag: ${{ env.nextTag }}
287+
draft: false
288+
makeLatest: true
289+
allowUpdates: true
290+
token: ${{ github.token }}
291+
215292
website:
216293
name: 🌐 Publish website
217294
needs: [publish]

build.sbt

Lines changed: 130 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ ThisBuild / tlCiMimaBinaryIssueCheck := true
3434
ThisBuild / tlCiDependencyGraphJob := true
3535
ThisBuild / autoAPIMappings := true
3636

37-
val sharedSettings = Seq(
37+
val sharedSettings = Seq(
3838
scalaVersion := "3.5.2",
3939
libraryDependencies ++= Seq(
4040
"org.scalameta" %% "munit" % "1.0.3" % Test
@@ -48,72 +48,139 @@ val sharedSettings = Seq(
4848
|""".stripMargin
4949
))
5050
)
51-
52-
githubWorkflowGeneratedCI ++= Seq(
53-
WorkflowJob(
54-
id = "website",
55-
name = "🌐 Publish website",
56-
oses = List("ubuntu-latest"),
57-
cond = Some("""github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))"""),
58-
needs = List("publish"),
59-
env = Map("DTC_HEADLESS" -> "true"),
60-
permissions = Some(Permissions.Specify.defaultPermissive),
61-
concurrency = Some(Concurrency(s"$${{ github.workflow }} @ $${{ github.ref }}", Some(true))),
62-
steps = List(
63-
WorkflowStep.Checkout,
64-
WorkflowStep.Run(
65-
name = Some("Setup"),
66-
commands = List("chmod +x dtcw")
51+
val releasePreparation = WorkflowJob(
52+
id = "prepare-release",
53+
name = "👷 Prepare release",
54+
oses = List("ubuntu-latest"),
55+
cond = Some("""github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))"""),
56+
needs = List("build"),
57+
env = Map("DTC_HEADLESS" -> "true"),
58+
permissions = Some(Permissions.Specify.defaultPermissive),
59+
steps = List(
60+
WorkflowStep.CheckoutFull,
61+
WorkflowStep.Run(
62+
name = Some("Get previous tag"),
63+
id = Some("previousTag"),
64+
commands = List(
65+
"""name=$(git --no-pager tag --sort=creatordate --merged ${{ github.ref_name }} | tail -2 | head -1)""",
66+
"""ref_name="${{ github.ref_name }}"""",
67+
"""prefix="prepare-"""",
68+
"""next_version=${ref_name/#$prefix}""",
69+
"""echo "previousTag=$name"""",
70+
"""echo "previousTag=$name" >> $GITHUB_ENV""",
71+
"""echo "nextTag=$next_version"""",
72+
"""echo "nextTag=$next_version" >> $GITHUB_ENV"""
73+
)
74+
),
75+
WorkflowStep.Use(
76+
name = Some("Update CHANGELOG"),
77+
id = Some("changelog"),
78+
ref = UseRef.Public("requarks", "changelog-action", "v1"),
79+
params = Map(
80+
"token" -> "${{ github.token }}",
81+
"fromTag" -> "${{ github.ref_name }}",
82+
"toTag" -> "${{ env.previousTag }}",
83+
"writeToFile" -> "true"
84+
)
85+
),
86+
WorkflowStep.Use(
87+
name = Some("Commit CHANGELOG.md"),
88+
ref = UseRef.Public("stefanzweifel", "git-auto-commit-action", "v5"),
89+
params = Map(
90+
"commit_message" -> "docs: update CHANGELOG.md for ${{ env.nextTag }} [skip ci]",
91+
"branch" -> "main",
92+
"file_pattern" -> "CHANGELOG.md docToolchainConfig.groovy"
93+
)
94+
),
95+
WorkflowStep.Use(
96+
name = Some("Create version tag"),
97+
ref = UseRef.Public("rickstaa", "action-create-tag", "v1"),
98+
params = Map(
99+
"tag" -> "${{ github.ref_name }}",
100+
"message" -> "Release ${{ github.ref_name }}",
101+
"force_push_tag" -> "true" // force push the tag to move it to HEAD
67102
)
68-
) ++
69-
WorkflowStep.SetupJava(List(JavaSpec.temurin("17"))) ++
70-
List(
71-
WorkflowStep.Run(
72-
name = Some("Install docToolchain"),
73-
commands = List("./dtcw local install doctoolchain")
74-
),
75-
WorkflowStep.Use(
76-
name = Some("Cache sbt"),
77-
ref = UseRef.Public("actions", "cache", "v4"),
78-
params = Map(
79-
"path" ->
80-
""".ivy2
81-
|.sbt""".stripMargin,
82-
"key" -> s"sbt-$${{ hashFiles('build.sbt', 'plugins.sbt') }}",
83-
"restore-keys" -> s"pillars-cache-$${{ hashFiles('build.sbt', 'plugins.sbt') }}"
84-
)
85-
),
86-
WorkflowStep.Run(
87-
name = Some("Get latest version"),
88-
id = Some("version"),
89-
commands = List(
90-
"""PILLARS_VERSION="$(git ls-remote --tags $REPO | awk -F"/" '{print $3}' | grep '^v[0-9]*\\.[0-9]*\\.[0-9]*' | grep -v {} | sort --version-sort | tail -n1)""",
91-
"""echo "latest version is [$PILLARS_VERSION]"""",
92-
"""echo "version=${PILLARS_VERSION#v}" >> "$GITHUB_OUTPUT""""
93-
)
94-
),
95-
WorkflowStep.Run(
96-
name = Some("Generate site"),
97-
commands = List("""./dtcw local generateSite && sbt unidoc"""),
98-
env = Map("PILLARS_VERSION" -> "${{ steps.version.outputs.version }}", "DTC_HEADLESS" -> "true")
99-
),
100-
WorkflowStep.Run(
101-
name = Some("Copy to public"),
102-
commands = List("cp -r target/microsite/output ./public")
103-
),
104-
WorkflowStep.Use(
105-
name = Some("Deply to GitHub Pages"),
106-
ref = UseRef.Public("peaceiris", "actions-gh-pages", "v4"),
107-
params = Map(
108-
"github_token" -> s"$${{ secrets.GITHUB_TOKEN }}",
109-
"publish_dir" -> "./public",
110-
"cname" -> "pillars.dev",
111-
"enable_jekyll" -> "false"
112-
)
103+
),
104+
WorkflowStep.Use(
105+
name = Some("Create release"),
106+
ref = UseRef.Public("ncipollo", "release-action", "v1.14.0"),
107+
params = Map(
108+
"allowUpdates" -> "true",
109+
"draft" -> "false",
110+
"makeLatest" -> "true",
111+
"name" -> "${{ env.nextTag }}",
112+
"tag" -> "${{ env.nextTag }}",
113+
"body" -> "${{ steps.changelog.outputs.changes }}",
114+
"token" -> "${{ github.token }}"
115+
)
116+
)
117+
)
118+
)
119+
val websitePublication = WorkflowJob(
120+
id = "website",
121+
name = "🌐 Publish website",
122+
oses = List("ubuntu-latest"),
123+
cond = Some("""github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))"""),
124+
needs = List("publish"),
125+
env = Map("DTC_HEADLESS" -> "true"),
126+
permissions = Some(Permissions.Specify.defaultPermissive),
127+
concurrency = Some(Concurrency(s"$${{ github.workflow }} @ $${{ github.ref }}", Some(true))),
128+
steps = List(
129+
WorkflowStep.Checkout,
130+
WorkflowStep.Run(
131+
name = Some("Setup"),
132+
commands = List("chmod +x dtcw")
133+
)
134+
) ++
135+
WorkflowStep.SetupJava(List(JavaSpec.temurin("17"))) ++
136+
List(
137+
WorkflowStep.Run(
138+
name = Some("Install docToolchain"),
139+
commands = List("./dtcw local install doctoolchain")
140+
),
141+
WorkflowStep.Use(
142+
name = Some("Cache sbt"),
143+
ref = UseRef.Public("actions", "cache", "v4"),
144+
params = Map(
145+
"path" ->
146+
""".ivy2
147+
|.sbt""".stripMargin,
148+
"key" -> s"sbt-$${{ hashFiles('build.sbt', 'plugins.sbt') }}",
149+
"restore-keys" -> s"pillars-cache-$${{ hashFiles('build.sbt', 'plugins.sbt') }}"
150+
)
151+
),
152+
WorkflowStep.Run(
153+
name = Some("Get latest version"),
154+
id = Some("version"),
155+
commands = List(
156+
"""PILLARS_VERSION="$(git ls-remote --tags $REPO | awk -F"/" '{print $3}' | grep '^v[0-9]*\\.[0-9]*\\.[0-9]*' | grep -v {} | sort --version-sort | tail -n1)""",
157+
"""echo "latest version is [$PILLARS_VERSION]"""",
158+
"""echo "version=${PILLARS_VERSION#v}" >> "$GITHUB_OUTPUT""""
159+
)
160+
),
161+
WorkflowStep.Run(
162+
name = Some("Generate site"),
163+
commands = List("""./dtcw local generateSite && sbt unidoc"""),
164+
env = Map("PILLARS_VERSION" -> "${{ steps.version.outputs.version }}", "DTC_HEADLESS" -> "true")
165+
),
166+
WorkflowStep.Run(
167+
name = Some("Copy to public"),
168+
commands = List("cp -r target/microsite/output ./public")
169+
),
170+
WorkflowStep.Use(
171+
name = Some("Deply to GitHub Pages"),
172+
ref = UseRef.Public("peaceiris", "actions-gh-pages", "v4"),
173+
params = Map(
174+
"github_token" -> s"$${{ secrets.GITHUB_TOKEN }}",
175+
"publish_dir" -> "./public",
176+
"cname" -> "pillars.dev",
177+
"enable_jekyll" -> "false"
113178
)
114179
)
115-
)
180+
)
116181
)
182+
ThisBuild / githubWorkflowGeneratedCI ++= List(releasePreparation, websitePublication)
183+
ThisBuild / githubWorkflowPublishNeeds := List("prepare-release")
117184

118185
enablePlugins(ScalaUnidocPlugin)
119186

0 commit comments

Comments
 (0)