Skip to content

Commit

Permalink
Update to Swift 6 (#38)
Browse files Browse the repository at this point in the history
* Update code

* Select Xcode 16

* Fix swiftlint

* Improve test code and removed mocks

* Remove XCTest imports

* Update GitHub Actions workflows to use macos-15

* Update GitHub Actions to use macos-15 for build environment

* Replace XCTUnwrap with #require in BumpCommandIntegrationTests and add Foundation import in XcodeFinderProjTests

* Fix package

* Add Foundation import and update references in tests for consistency

* Remove redundant imports in test files for cleaner code

* Add missing imports and enable upcoming feature flags in package configuration

* Update Periphery installation command and clean up XcodeProjFinder struct

* Rename error message property for clarity in XcodeProjFinder

* Comment out Codecov upload step in build workflow due to compatibility issues with Swift Testing

* Add comment to ignore FindError property usage in Periphery analysis
  • Loading branch information
homerooliveira authored Feb 26, 2025
1 parent 0a16bd6 commit b58a058
Show file tree
Hide file tree
Showing 26 changed files with 393 additions and 354 deletions.
14 changes: 7 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ concurrency:

jobs:
build:
runs-on: macos-latest
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Select Xcode
Expand All @@ -38,12 +38,12 @@ jobs:
- name: Build
run: swift build --verbose
- name: Run tests
run: swift test --verbose --enable-code-coverage | xcbeautify --renderer github-actions --report junit
- name: Upload test results to Codecov
uses: codecov/test-results-action@v1
with:
files: build/reports/junit.xml
token: ${{ secrets.CODECOV_TOKEN }}
run: swift test --verbose --enable-swift-testing --enable-code-coverage | xcbeautify --renderer github-actions --report junit
# - name: Upload test results to Codecov // Not working yet with Swift Testing
# uses: codecov/test-results-action@v1
# with:
# files: build/reports/junit.xml
# token: ${{ secrets.CODECOV_TOKEN }}
- name: Generate coverage
run: ./.scripts/generate_coverage.sh
- name: Upload coverage to Codecov
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ jobs:
# - https://gh.io/supported-runners-and-hardware-resources
# - https://gh.io/using-larger-runners
# Consider using larger runners for possible analysis time improvements.
runs-on: ${{ (matrix.language == 'swift' && 'macos-latest') }}
runs-on: ${{ (matrix.language == 'swift' && 'macos-15') }}
timeout-minutes: ${{ (matrix.language == 'swift' && 120) || 360 }}
permissions:
# required for all workflows
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:

jobs:
lint:
runs-on: macos-latest
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Install SwiftLint
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:

jobs:
build:
runs-on: macos-latest
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Cache .build
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/unused_code_lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,19 +21,19 @@ concurrency:

jobs:
unused_code_lint:
runs-on: macos-latest
runs-on: macos-15
steps:
- uses: actions/checkout@v4
- name: Select Xcode
run: sudo xcode-select -s /Applications/Xcode_16.2.app
- name: Cache .build
- name: Cache .build
uses: actions/cache@v4.2.0
with:
path: .build
key: ${{ runner.os }}-spm-${{ hashFiles('**/Package.resolved') }}
restore-keys: |
${{ runner.os }}-spm-
- name: Installing Periphery
run: brew install peripheryapp/periphery/periphery
run: brew install periphery
- name: Run Periphery
run: periphery scan --format github-actions --relative-results --strict
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ build:
swift build --product bump -c release --disable-sandbox

test:
swift test | xcbeautify
swift test --enable-swift-testing

install_debug: build_debug
install ".build/debug/bump" "$(bindir)"
Expand Down
2 changes: 1 addition & 1 deletion Package.resolved
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"originHash" : "7d7225ef6b8ae5861ffb4833e7c7e3bee4cdce4d9b4ca43199179e5334f62c8a",
"originHash" : "8b8eb38aebce548948b84f9848520628d289abdd3b1f2a4075c8f6e4a34428e1",
"pins" : [
{
"identity" : "aexml",
Expand Down
9 changes: 6 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ let package = Package(
.macOS(.v13)
],
products: [
.executable(name: "bump", targets: ["BumpCommandLine"])
.executable(name: "bump", targets: ["bump"]),
],
dependencies: [
.package(
Expand All @@ -20,7 +20,8 @@ let package = Package(
.upToNextMajor(from: "1.3.0")),
],
targets: [
.executableTarget(
.executableTarget(name: String("bump"), dependencies: ["BumpCommandLine"]),
.target(
name: "BumpCommandLine",
dependencies: [
"BumpCore",
Expand Down Expand Up @@ -55,7 +56,8 @@ let package = Package(
.testTarget(
name: "BumpCommandLineIntegrationTests",
dependencies: ["BumpCommandLine", "Environment"],
resources: [.copy("Resources/")]),
resources: [.copy("Resources/")]
),
.testTarget(
name: "SwiftExtensionsTests",
dependencies: ["SwiftExtensions"]),
Expand All @@ -79,5 +81,6 @@ for target in package.targets {
.unsafeFlags(["-warnings-as-errors"]),
.enableUpcomingFeature("ExistentialAny"),
.enableUpcomingFeature("InternalImportsByDefault"),
// .enableUpcomingFeature("MemberImportVisibility"), Swift 6.1 only
]
}
4 changes: 2 additions & 2 deletions Sources/BumpCommandLine/BumpCommand.swift
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import ArgumentParser
import BumpCore
import Environment
import FileManagerWrapper
import Foundation

@main
struct BumpCommand: ParsableCommand {
package struct BumpCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "bump",
abstract: "Bump your projects."
Expand Down
2 changes: 1 addition & 1 deletion Sources/BumpCore/IncrementMode.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import Foundation

public enum IncrementMode: RawRepresentable, Equatable {
public enum IncrementMode: RawRepresentable, Equatable, Sendable {
case major
case minor
case patch
Expand Down
13 changes: 5 additions & 8 deletions Sources/FileManagerWrapper/XcodeProjFinder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@ public protocol XcodeProjFinderProtocol {
}

public struct XcodeProjFinder: XcodeProjFinderProtocol {
struct FindError: Error {
let message: String
public struct FindError: Error, Equatable {
// periphery:ignore - Because the periphery can't find the usage of this property.
let description: String

init(_ message: String) {
self.message = message
}

var description: String {
message
init(_ description: String) {
self.description = description
}
}

Expand Down
2 changes: 0 additions & 2 deletions Sources/XcodeProjWrapper/XcodeProjWrapperProtocol.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import Foundation

public protocol XcodeProjWrapperProtocol {
var targets: [Target] { get }

Expand Down
4 changes: 0 additions & 4 deletions Sources/XcodeProjWrapperMock/BuildConfigurationMock.swift

This file was deleted.

3 changes: 0 additions & 3 deletions Sources/XcodeProjWrapperMock/TargetMock.swift

This file was deleted.

9 changes: 9 additions & 0 deletions Sources/bump/Main.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import ArgumentParser
import BumpCommandLine

@main
enum Main {
static func main() {
BumpCommand.main()
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,29 @@
import ArgumentParser
import BumpCore
import Environment
import FileManagerWrapper
import XcodeProjWrapper
import Foundation
import XCTest

import XcodeProjWrapper
import Testing
@testable import BumpCommandLine

final class BumpCommandIntegrationTests: XCTestCase {
private var logs: [String] = []
private var command = BumpCommand()
final class Box<T>: Equatable where T: Equatable {
var value: T

init(_ value: T) {
self.value = value
}

override func setUpWithError() throws {
logs = []
command = BumpCommand(environment: makeEnvironment())
static func == (lhs: Box<T>, rhs: Box<T>) -> Bool {
lhs.value == rhs.value
}
}

struct BumpCommandIntegrationTests {

@Test func bumpWithDirectory() throws {
var (command, logs) = makeCommand()

func testBumpWithDirectory() throws {
let resourcesPath = try fixturesPath()

command.path = resourcesPath.path
Expand All @@ -28,12 +35,14 @@ final class BumpCommandIntegrationTests: XCTestCase {

try command.run()

logs.sort()
logs.value.sort()

XCTAssertEqual(logs, ["1.5.0.2", "1.5.0.2", "2.5.0.2"])
#expect(logs == Box(["1.5.0.2", "1.5.0.2", "2.5.0.2"]))
}

func testBumpWithXcodeproj() throws {
@Test func bumpWithXcodeproj() throws {
var (command, logs) = makeCommand()

let resourcesPath = try fixturesPath()
.appendingPathComponent("SampleProject.xcodeproj")

Expand All @@ -46,12 +55,14 @@ final class BumpCommandIntegrationTests: XCTestCase {

try command.run()

logs.sort()
logs.value.sort()

XCTAssertEqual(logs, ["1.5.0.2", "1.5.0.2", "2.5.0.2"])
#expect(logs == Box(["1.5.0.2", "1.5.0.2", "2.5.0.2"]))
}

func testBumpWithDirectoryWhenVerboseIsTrue() throws {
@Test func bumpWithDirectoryWhenVerboseIsTrue() throws {
var (command, logs) = makeCommand()

let resourcesPath = try fixturesPath()

command.path = resourcesPath.path
Expand All @@ -63,19 +74,20 @@ final class BumpCommandIntegrationTests: XCTestCase {

try command.run()

logs.sort()
logs.value.sort()

XCTAssertEqual(
logs,
[
#expect(
logs == Box([
"Test1 1.5.0.1 -> 1.5.0.2",
"Test2Intention 1.5.0.1 -> 1.5.0.2",
"TestIntetion 2.5.0.1 -> 2.5.0.2"
]
])
)
}

func testBumpWithXcodeprojWhenVerboseIsTrue() throws {
@Test func bumpWithXcodeprojWhenVerboseIsTrue() throws {
var (command, logs) = makeCommand()

let resourcesPath = try fixturesPath()
.appendingPathComponent("SampleProject.xcodeproj")

Expand All @@ -88,35 +100,37 @@ final class BumpCommandIntegrationTests: XCTestCase {

try command.run()

logs.sort()
logs.value.sort()

XCTAssertEqual(
logs,
[
#expect(
logs == Box([
"Test1 1.5.0.1 -> 1.5.0.2",
"Test2Intention 1.5.0.1 -> 1.5.0.2",
"TestIntetion 2.5.0.1 -> 2.5.0.2"
]
])
)

try command.run()
}

func testBumpWithXcodeprojWhenPathIsNil() throws {
@Test func bumpWithXcodeprojWhenPathIsNil() {
var (command, _) = makeCommand()

command.path = nil
command.bundleIdentifiers = ["com.test.Test1"]
command.mode = .build
command.useSameVersion = false
command.verbose = false
command.inPlace = false

// This will throw an error because the current directory does not have an xcodeproj file
XCTAssertThrowsError(try command.run())
#expect(throws: (any Error).self) {
try command.run()
}
}

func testBumpWithInPlaceTrue() throws {
@Test func bumpWithInPlaceTrue() throws {
var (command, logs) = makeCommand()

let resourcesPath = try fixturesPath()
.appending(component: "SampleProject.xcodeproj")
.appendingPathComponent("SampleProject.xcodeproj")

let temporaryFile = try copyFileToTemporaryPath(fileURL: resourcesPath)

Expand All @@ -129,9 +143,9 @@ final class BumpCommandIntegrationTests: XCTestCase {

try command.run()

logs.sort()
logs.value.sort()

XCTAssertEqual(logs, ["1.5.0.2", "1.5.0.2", "2.5.0.2"])
#expect(logs == Box(["1.5.0.2", "1.5.0.2", "2.5.0.2"]))

// Remove the temporary file
try FileManager.default.removeItem(at: temporaryFile)
Expand All @@ -148,14 +162,21 @@ final class BumpCommandIntegrationTests: XCTestCase {
}

private func fixturesPath() throws -> URL {
try XCTUnwrap(Bundle.module.resourceURL)
try #require(Bundle.module.resourceURL)
}

private func makeEnvironment() -> Environment {
Environment(
xcodeProjFinder: XcodeProjFinder(fileManagerWrapper: FileManager.default),
xcodeProjWrapper: { try XcodeProjWrapper(path: $0) },
logger: { self.logs.append($0) }
private func makeCommand() -> (BumpCommand, Box<[String]>) {
let logs: Box<[String]> = Box([])

return (
BumpCommand(
environment: Environment(
xcodeProjFinder: XcodeProjFinder(fileManagerWrapper: FileManager.default),
xcodeProjWrapper: { try XcodeProjWrapper(path: $0) },
logger: { logs.value.append($0) }
)
),
logs
)
}
}
Loading

0 comments on commit b58a058

Please sign in to comment.