Skip to content

Commit e04b085

Browse files
authored
Merge pull request #102 from Adyen/notify-on-empty-targets
Highlighting if empty targets are provided
2 parents c5246e7 + 4b3eced commit e04b085

File tree

5 files changed

+73
-7
lines changed

5 files changed

+73
-7
lines changed

.github/workflows/run-tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ jobs:
2121
- name: Select latest Xcode
2222
uses: maxim-lobanov/setup-xcode@v1
2323
with:
24-
xcode-version: '15.4'
24+
xcode-version: '16.1'
2525

2626
- name: 🛠️ Run All Tests
2727
run: |
28-
xcodebuild test -scheme public-api-diff -destination "platform=iOS,name=Any iOS Device" -skipPackagePluginValidation | xcpretty --utf --color && exit ${PIPESTATUS[0]}
28+
xcodebuild test -scheme public-api-diff-Package -destination "platform=macOS" -skipPackagePluginValidation | xcpretty --utf --color && exit ${PIPESTATUS[0]}

Sources/PublicModules/PADOutputGenerator/MarkdownOutputGenerator.swift

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
2525
let changes = Self.changeLines(changesPerModule: changesPerTarget)
2626

2727
var lines = [
28-
Self.title(changesPerTarget: changesPerTarget)
28+
Self.title(changesPerTarget: changesPerTarget, allTargets: allTargets)
2929
]
3030

3131
if let oldVersionName, let newVersionName {
@@ -46,7 +46,7 @@ public struct MarkdownOutputGenerator: OutputGenerating {
4646
lines += changes + [separator]
4747
}
4848

49-
if let allTargets {
49+
if let allTargets, !allTargets.isEmpty {
5050
lines += [
5151
Self.analyzedModulesInfo(allTargets: allTargets)
5252
]
@@ -60,7 +60,15 @@ public struct MarkdownOutputGenerator: OutputGenerating {
6060

6161
private extension MarkdownOutputGenerator {
6262

63-
static func title(changesPerTarget: [String: [Change]]) -> String {
63+
static func title(
64+
changesPerTarget: [String: [Change]],
65+
allTargets: [String]?
66+
) -> String {
67+
68+
if let allTargets, allTargets.isEmpty {
69+
// We got targets but the list is empty -> Show an error
70+
return "# ‼️ No analyzable targets detected"
71+
}
6472

6573
if changesPerTarget.keys.isEmpty {
6674
return "# ✅ No changes detected"

Sources/PublicModules/PADOutputGenerator/OutputGenerating.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public protocol OutputGenerating<OutputType> {
1515
/// Generates an output from input parameters
1616
/// - Parameters:
1717
/// - changesPerTarget: A list of changes per target/module
18-
/// - allTargets: A list of all targets/modules that were analysed in previous steps
18+
/// - allTargets: A list of all targets/modules that were analysed in previous steps - if targets are provided but the list is empty it is treated like a failure
1919
/// - oldVersionName: The name of the old/reference version
2020
/// - newVersionName: The name of the new/updated version
2121
/// - warnings: A list of warnings produced in previous steps

Tests/UnitTests/OutputGeneratorTests.swift

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class OutputGeneratorTests: XCTestCase {
2727
newVersionName: "new_source",
2828
warnings: []
2929
)
30+
3031
XCTAssertEqual(output, expectedOutput)
3132
}
3233

@@ -57,10 +58,11 @@ class OutputGeneratorTests: XCTestCase {
5758
newVersionName: "new_source",
5859
warnings: []
5960
)
61+
6062
XCTAssertEqual(output, expectedOutput)
6163
}
6264

63-
func test_multipleChanges_multipleModules() {
65+
func multipleChanges_multipleModules() {
6466

6567
let expectedOutput = """
6668
# ⚠️ 4 public changes detected ⚠️
@@ -109,6 +111,60 @@ class OutputGeneratorTests: XCTestCase {
109111
newVersionName: "new_source",
110112
warnings: []
111113
)
114+
115+
XCTAssertEqual(output, expectedOutput)
116+
}
117+
118+
struct AllTargetsExpectation {
119+
let allTargets: [String]?
120+
let expectedTitle: String
121+
let expectedTargetSection: String
122+
}
123+
124+
func test_allTargets_shouldChangeOutputAsExpected() {
125+
126+
let testExpectations: [AllTargetsExpectation] = [
127+
.init(
128+
allTargets: [],
129+
expectedTitle: "‼️ No analyzable targets detected",
130+
expectedTargetSection: ""
131+
),
132+
.init(
133+
allTargets: nil,
134+
expectedTitle: "✅ No changes detected",
135+
expectedTargetSection: ""
136+
),
137+
.init(
138+
allTargets: ["SomeTarget"],
139+
expectedTitle: "✅ No changes detected",
140+
expectedTargetSection: "\n**Analyzed targets:** SomeTarget"
141+
)
142+
]
143+
144+
testExpectations.forEach { argument in
145+
allTargets_shouldChangeOutputAsExpected(argument: argument)
146+
}
147+
}
148+
149+
private func allTargets_shouldChangeOutputAsExpected(argument: AllTargetsExpectation) {
150+
151+
let expectedOutput = """
152+
# \(argument.expectedTitle)
153+
_Comparing `new_source` to `old_repository @ old_branch`_
154+
155+
---\(argument.expectedTargetSection)
156+
"""
157+
158+
let outputGenerator = MarkdownOutputGenerator()
159+
160+
let output = outputGenerator.generate(
161+
from: [:],
162+
allTargets: argument.allTargets,
163+
oldVersionName: "old_repository @ old_branch",
164+
newVersionName: "new_source",
165+
warnings: []
166+
)
167+
112168
XCTAssertEqual(output, expectedOutput)
113169
}
114170
}

Tests/public-api-diff.xctestplan

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,15 @@
4545
},
4646
"testTargets" : [
4747
{
48+
"parallelizable" : true,
4849
"target" : {
4950
"containerPath" : "container:",
5051
"identifier" : "IntegrationTests",
5152
"name" : "IntegrationTests"
5253
}
5354
},
5455
{
56+
"parallelizable" : true,
5557
"target" : {
5658
"containerPath" : "container:",
5759
"identifier" : "UnitTests",

0 commit comments

Comments
 (0)