Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion .github/workflows/swift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,34 @@ name: Swift

on:
push:
branches: [ "main" ]
tags:
- "**"
pull_request:
branches: [ "main" ]

permissions:
contents: write

jobs:
build:
test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: swift-actions/setup-swift@v3
with:
swift-version: "6.4.2"
- name: Run tests
run: swift test -v

release:
if: startsWith(github.ref, 'refs/tags/')
runs-on: macos-latest
steps:
- uses: actions/checkout@v4
- uses: swift-actions/setup-swift@v3
with:
swift-version: "6.4.2"
- name: Build
run: swift build -v --disable-sandbox -c release --arch arm64 --arch x86_64
- name: Release
Expand Down
15 changes: 8 additions & 7 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 20 additions & 4 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// swift-tools-version: 5.9.0
// swift-tools-version: 6.4
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
Expand All @@ -7,15 +7,31 @@ let package = Package(
name: "swift-changelog-parser",
platforms: [.macOS(.v13)],
dependencies: [
.package(url: "https://github.com/apple/swift-markdown.git", branch: "main"),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.4.0")),
.package(url: "https://github.com/apple/swift-markdown.git", .upToNextMajor(from: "0.9.0")),
.package(url: "https://github.com/apple/swift-argument-parser.git", .upToNextMajor(from: "1.8.2")),
],
targets: [
// Targets are the basic building blocks of a package, defining a module or a test suite.
// Targets can depend on other targets in this package and products from dependencies.
.executableTarget(
name: "swift-changelog-parser",
dependencies: [.product(name: "Markdown", package: "swift-markdown"),
.product(name: "ArgumentParser", package: "swift-argument-parser")]),
.product(name: "ArgumentParser", package: "swift-argument-parser")],
swiftSettings: swiftSettings),
.testTarget(
name: "swift-changelog-parserTests",
dependencies: ["swift-changelog-parser"],
swiftSettings: swiftSettings),
]
)

var swiftSettings: [SwiftSetting] {
[
.swiftLanguageMode(.v6),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
.enableUpcomingFeature("MemberImportVisibility"),
.enableUpcomingFeature("InferIsolatedConformances"),
.enableUpcomingFeature("ImmutableWeakCaptures"),
]
}
16 changes: 12 additions & 4 deletions Sources/Changelog.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ struct Changelog: ParsableCommand {

func run() throws {
let document = try Document(parsing: URL(filePath: path))
let section = try Changelog.section(of: document, for: release)

if section.isEmpty {
Logger.changelog.info("Changelog does not contain elements in the '\(release.description.localizedCapitalized, privacy: .public)' section")
}

print(section)
}

static func section(of document: Document, for release: Release) throws -> String {
let heading = document.children
.compactMap { $0 as? Heading }
.filter { $0.level == 2 }
Expand All @@ -82,11 +92,9 @@ struct Changelog: ParsableCommand {

let list = document.child(at: heading.indexInParent + 1)
guard let list, list is UnorderedList else {
Logger.changelog.info("Changelog does not contain elements in the '\(release.description.localizedCapitalized, privacy: .public)' section")
print("")
return
return ""
}

print(list.format().trimmingCharacters(in: .whitespacesAndNewlines))
return list.format().trimmingCharacters(in: .whitespacesAndNewlines)
}
}
57 changes: 57 additions & 0 deletions Tests/swift-changelog-parserTests/ChangelogTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import ArgumentParser
import Markdown
import Testing
@testable import swift_changelog_parser

let changelog = """
# Changelog

## Unreleased

- Added thing
- Fixed thing

## 1.1.0

- Second release

## 1.0.0

- First release
"""

@Suite struct ChangelogTests {

func section(_ release: Changelog.Release, markdown: String = changelog) throws -> String {
try Changelog.section(of: Document(parsing: markdown), for: release)
}

@Test func unreleased() throws {
#expect(try section(.unreleased) == "- Added thing\n- Fixed thing")
}

@Test func latest() throws {
#expect(try section(.latest) == "- Second release")
}

@Test func specificRelease() throws {
#expect(try section(.release("1.0.0")) == "- First release")
}

@Test func missingSectionThrows() {
#expect(throws: ValidationError.self) {
try section(.release("2.0.0"))
}
}

@Test func emptySectionReturnsEmptyString() throws {
let markdown = """
# Changelog

## Unreleased

Some prose, but no list.
"""
#expect(try section(.unreleased, markdown: markdown).isEmpty)
}
}
Loading