diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index bb07cf4..b04c956 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,7 +30,7 @@ jobs: id: version run: | # Read version from VERSION file - CURRENT=$(cat VERSION | tr -d '\n') + CURRENT=$(cat Sources/SwiftFindRefs/VERSION | tr -d '\n') echo "Current version: $CURRENT" # Parse version components @@ -54,13 +54,13 @@ jobs: - name: Update VERSION file run: | - echo "${{ steps.version.outputs.new }}" > VERSION + echo "${{ steps.version.outputs.new }}" > Sources/SwiftFindRefs/VERSION - name: Commit version bump run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com" - git add VERSION + git add Sources/SwiftFindRefs/VERSION git commit -m "bump up version" git push diff --git a/Package.swift b/Package.swift index ff22f70..97e309f 100644 --- a/Package.swift +++ b/Package.swift @@ -16,6 +16,9 @@ let package = Package( dependencies: [ .product(name: "ArgumentParser", package: "swift-argument-parser"), .product(name: "IndexStore", package: "swift-index-store"), + ], + resources: [ + .copy("VERSION") ] ), .testTarget( diff --git a/Sources/SwiftFindRefs/SwiftFindRefs.swift b/Sources/SwiftFindRefs/SwiftFindRefs.swift index 5c988d5..ffd790f 100644 --- a/Sources/SwiftFindRefs/SwiftFindRefs.swift +++ b/Sources/SwiftFindRefs/SwiftFindRefs.swift @@ -6,6 +6,7 @@ import Foundation struct SwiftFindRefs: AsyncParsableCommand { static let configuration = CommandConfiguration( abstract: "CLI that helps you interact with Xcode's IndexStoreDB.", + version: version, subcommands: [Search.self, Remove.self], defaultSubcommand: Search.self ) @@ -104,3 +105,13 @@ extension SwiftFindRefs { } } } + +extension SwiftFindRefs { + static let version: String = { + guard let url = Bundle.module.url(forResource: "VERSION", withExtension: nil), + let content = try? String(contentsOf: url, encoding: .utf8) else { + return "unknown" + } + return content.trimmingCharacters(in: .whitespacesAndNewlines) + }() +} diff --git a/VERSION b/Sources/SwiftFindRefs/VERSION similarity index 100% rename from VERSION rename to Sources/SwiftFindRefs/VERSION diff --git a/Tests/SwiftFindRefs/SwiftFindRefsTests.swift b/Tests/SwiftFindRefs/SwiftFindRefsTests.swift new file mode 100644 index 0000000..d2d16a9 --- /dev/null +++ b/Tests/SwiftFindRefs/SwiftFindRefsTests.swift @@ -0,0 +1,10 @@ +import Testing +@testable import SwiftFindRefs + +@Suite("SwiftFindRefs Configuration Tests") +struct SwiftFindRefsTests { + @Test + func `Verify CLI version uses VERSION file`() { + #expect(SwiftFindRefs.configuration.version == SwiftFindRefs.version) + } +} diff --git a/swiftfindrefs.rb b/swiftfindrefs.rb index 256d1a9..3a5a4d9 100644 --- a/swiftfindrefs.rb +++ b/swiftfindrefs.rb @@ -1,7 +1,7 @@ # Version is managed by the VERSION file - do not edit manually # Run the Release workflow to bump version automatically class Swiftfindrefs < Formula - APP_VERSION = File.read(File.join(__dir__, "VERSION")).strip.freeze + APP_VERSION = File.read(File.join(__dir__, "Sources/SwiftFindRefs/VERSION")).strip.freeze desc "SwiftFindRefs is a macOS Swift CLI that resolves a project's DerivedData, reads Xcode's IndexStore, and reports every file referencing a chosen symbol, with optional verbose tracing for diagnostics." homepage "https://github.com/michaelversus/SwiftFindRefs"