Skip to content

Commit

Permalink
project(release): generate release notes in release flow
Browse files Browse the repository at this point in the history
  • Loading branch information
kattouf committed Oct 24, 2024
1 parent 8b5a8d3 commit 041db03
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 4 deletions.
12 changes: 12 additions & 0 deletions SakeApp/BrewCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,16 @@ struct BrewCommands {
}
)
}

static var ensureGitCliffInstalled: Command {
Command(
description: "Ensure git-cliff is installed",
skipIf: { _ in
run("which", "git-cliff").succeeded
},
run: { _ in
try runAndPrint("brew", "install", "git-cliff")
}
)
}
}
50 changes: 47 additions & 3 deletions SakeApp/ReleaseCommands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,14 @@ struct ReleaseCommands {
public static var release: Command {
Command(
description: "Release",
dependencies: [bumpVersion, buildReleaseArtifacts, calculateBuildArtifactsSha256, createAndPushTag, draftReleaseWithArtifacts]
dependencies: [
bumpVersion,
buildReleaseArtifacts,
calculateBuildArtifactsSha256,
createAndPushTag,
generateReleaseNotes,
draftReleaseWithArtifacts,
]
)
}

Expand Down Expand Up @@ -63,7 +70,7 @@ struct ReleaseCommands {
try versionFileContent.write(toFile: versionFilePath, atomically: true, encoding: .utf8)

try runAndPrint("git", "add", versionFilePath)
try runAndPrint("git", "commit", "-m", "Bump version to \(version)")
try runAndPrint("git", "commit", "-m", "chore(release): Bump version to \(version)")
print("Version bumped to \(version)")
}
)
Expand Down Expand Up @@ -202,6 +209,35 @@ struct ReleaseCommands {
)
}

static var generateReleaseNotes: Command {
Command(
description: "Generate release notes",
dependencies: [BrewCommands.ensureGitCliffInstalled],
skipIf: { context in
let arguments = try ReleaseArguments.parse(context.arguments)
try arguments.validate()

let version = arguments.version
let releaseNotesPath = releaseNotesPath(version: version)
if FileManager.default.fileExists(atPath: releaseNotesPath) {
print("Release notes for \(version) already exist at \(releaseNotesPath). Skipping...")
return true
} else {
return false
}
},
run: { context in
let arguments = try ReleaseArguments.parse(context.arguments)
try arguments.validate()

let version = arguments.version
let releaseNotesPath = releaseNotesPath(version: version)
try runAndPrint("git", "cliff", "--unreleased", "--strip=all", "--tag", version, "--output", releaseNotesPath)
print("Release notes generated at \(releaseNotesPath)")
}
)
}

static var draftReleaseWithArtifacts: Command {
Command(
description: "Draft a release on GitHub",
Expand All @@ -227,9 +263,17 @@ struct ReleaseCommands {
let tagName = arguments.version
let releaseTitle = arguments.version
let draftReleaseCommand =
"gh release create \(tagName) \(Constants.buildArtifactsDirectory)/*.zip --title '\(releaseTitle)' --draft --verify-tag --generate-notes"
"gh release create \(tagName) \(Constants.buildArtifactsDirectory)/*.zip --title '\(releaseTitle)' --draft --verify-tag --notes-file \(releaseNotesPath(version: tagName))"
try runAndPrint(bash: draftReleaseCommand)
}
)
}
}

// MARK: - Helpers

extension ReleaseCommands {
private static func releaseNotesPath(version: String) -> String {
".build/artifacts/release-notes-\(version).md"
}
}
2 changes: 1 addition & 1 deletion cliff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ commit_preprocessors = [
]
# regex for parsing and grouping commits
commit_parsers = [
{ message = '^chore\(release\): bump version', skip = true },
{ message = '^chore\(release\): Bump version to', skip = true },
{ message = '^(chore|fix)\(deps\):', group = "<!-- 99 -->:package: Dependency Updates", scope = "" },
{ message = '^feat', group = "<!-- 00 -->:rocket: Features" },
{ message = '^fix', group = "<!-- 01 -->:bug: Bug Fixes" },
Expand Down

0 comments on commit 041db03

Please sign in to comment.