From 44c76b808e7cdc7b710b1c80dc82088861fd9b2a Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 29 Mar 2022 23:11:57 -0300 Subject: [PATCH 1/4] Create a internal struct to deliver the package version This includes both current "1.0.1" and qualifiedVersion "Meilisearch Swift (v1.0.1)" --- .../MeiliSearch/Model/PackageVersion.swift | 15 ++++++++++++ .../PackageVersionTests.swift | 23 +++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 Sources/MeiliSearch/Model/PackageVersion.swift create mode 100644 Tests/MeiliSearchUnitTests/PackageVersionTests.swift diff --git a/Sources/MeiliSearch/Model/PackageVersion.swift b/Sources/MeiliSearch/Model/PackageVersion.swift new file mode 100644 index 00000000..202a7941 --- /dev/null +++ b/Sources/MeiliSearch/Model/PackageVersion.swift @@ -0,0 +1,15 @@ +import Foundation + +internal struct PackageVersion { + /// This is the current version of the meilisearch-swift package + private static let current = "0.13.0" + + /** + Retrieves the current version of the MeiliSearch Swift package and formats accordingly. + + - returns: String containing the qualified version of this package eg. `Meilisearch Swift (v1.0.0)` + */ + static func qualifiedVersion(_ rawVersion: String? = nil) -> String { + "Meilisearch Swift (v\(rawVersion ?? self.current))" + } +} diff --git a/Tests/MeiliSearchUnitTests/PackageVersionTests.swift b/Tests/MeiliSearchUnitTests/PackageVersionTests.swift new file mode 100644 index 00000000..08bb36a0 --- /dev/null +++ b/Tests/MeiliSearchUnitTests/PackageVersionTests.swift @@ -0,0 +1,23 @@ +@testable import MeiliSearch + +import Foundation +import XCTest + +class PackageVersionTests: XCTestCase { + func testAppendsContentsToPrefix() { + XCTAssert(PackageVersion.qualifiedVersion().contains("Meilisearch Swift")) + } + + func testGetsFullyQualifiedVersion() { + XCTAssertEqual(PackageVersion.qualifiedVersion("0.3.2"), "Meilisearch Swift (v0.3.2)") + } + + func testChecksForSemVerVersion() { + let version = PackageVersion.qualifiedVersion() + let regex = "[0-9]+.[0-9]+.[0-9]+" + + let hasSemVer = (version.range(of: regex, options: .regularExpression) ?? nil) != nil + + XCTAssert(hasSemVer, "The PackageVersion.current does not have a valid semver version.") + } +} From 6628f0cf088867348757cc82cce14083e0f4660a Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 29 Mar 2022 23:13:11 -0300 Subject: [PATCH 2/4] Make Pod::Spec load directly from PackageVersion.swift This way we can just change in one place besides the README stuff --- MeiliSearch.podspec | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/MeiliSearch.podspec b/MeiliSearch.podspec index 7a47bb03..6196d5a0 100644 --- a/MeiliSearch.podspec +++ b/MeiliSearch.podspec @@ -6,9 +6,18 @@ # To learn more about a Podspec see https://guides.cocoapods.org/syntax/podspec.html # +# Loads version from `PackageVersion.current` defined in the PackageVersion.swift file. +package_version = begin + File + .read("./Sources/MeiliSearch/Model/PackageVersion.swift") + .match(/"([0-9]+.[0-9]+.[0-9]+)"/i)[1] +rescue + raise "Cannot retrieve a valid semver.org version in the PackageVersion.swift file" +end + Pod::Spec.new do |s| s.name = 'MeiliSearch' - s.version = '0.13.0' + s.version = package_version s.summary = 'The Meilisearch API client written in Swift' # This description is used to generate tags and improve search results. @@ -33,10 +42,11 @@ Pod::Spec.new do |s| s.homepage = 'https://github.com/meilisearch/meilisearch-swift' s.license = { :type => 'MIT', :file => 'LICENSE' } s.author = { 'Meilisearch' => 'bonjour@meilisearch.com' } - s.source = { :git => 'https://github.com/meilisearch/meilisearch-swift.git', :tag => s.version.to_s } + s.source = { :git => 'https://github.com/meilisearch/meilisearch-swift.git', :tag => package_version } s.social_media_url = 'https://twitter.com/meilisearch' - s.source_files = 'Sources/**/*' + s.source_files = 'Sources/**/*.{h,m,swift}' + s.swift_versions = ['5.2'] s.ios.deployment_target = '10.0' s.osx.deployment_target = '10.10' From 40f495e18cd0725f8eb20f6f7c9bf6882c070584 Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 29 Mar 2022 23:14:36 -0300 Subject: [PATCH 3/4] Add a new step to lint podspec before the publish As recommended here https://guides.cocoapods.org/terminal/commands.html#pod_trunk_push --- .github/workflows/cocoapods.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/cocoapods.yml b/.github/workflows/cocoapods.yml index c6d9779e..c2f91a88 100644 --- a/.github/workflows/cocoapods.yml +++ b/.github/workflows/cocoapods.yml @@ -13,6 +13,8 @@ jobs: - uses: actions/checkout@v2 - name: Check release validity run: sh .github/scripts/check-release.sh + - name: Lint podspec before submitting + run: pod spec lint - name: Publish to CocoaPods register env: COCOAPODS_TRUNK_TOKEN: ${{ secrets.COCOAPODS_TRUNK_TOKEN }} From 70e5e29424d731a5f0645769d237958ee568064a Mon Sep 17 00:00:00 2001 From: Bruno Casali Date: Tue, 29 Mar 2022 23:19:18 -0300 Subject: [PATCH 4/4] Add a new check-release step to prevent issues with the new versioning --- .github/scripts/check-release.sh | 8 ++++++-- CONTRIBUTING.md | 6 +++--- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/.github/scripts/check-release.sh b/.github/scripts/check-release.sh index 6d52d865..dbae58e3 100644 --- a/.github/scripts/check-release.sh +++ b/.github/scripts/check-release.sh @@ -5,14 +5,18 @@ current_tag=$(echo $GITHUB_REF | tr -d 'refs/tags/') file1='MeiliSearch.podspec' file2='README.md' file3='.code-samples.meilisearch.yaml' +file4='Sources/MeiliSearch/Model/PackageVersion.swift' file_tag1=$(grep ' s.version' $file1 | cut -d '=' -f2 | tr -d "'" | tr -d ' ') file_tag2=$(grep '.package(url:' $file2 | cut -d ':' -f4 | tr -d '"' | tr -d ')' | tr -d ' ') file_tag3=$(grep '.package(url:' $file3 | cut -d ':' -f4 | tr -d '"' | tr -d ')' | tr -d ' ') -if [ "$current_tag" != "$file_tag1" ] || [ "$current_tag" != "$file_tag2" ] || [ "$current_tag" != "$file_tag3" ]; then +file_tag4=$(grep 'let current' -A 0 $file4 | cut -d '=' -f2 | tr -d '"' | tr -d ' ') + +if [ "$current_tag" != "$file_tag1" ] || [ "$current_tag" != "$file_tag2" ] || [ "$current_tag" != "$file_tag3" ] || [ "$current_tag" != "$file_tag4" ]; then echo "Error: the current tag does not match the version in package file(s)." echo "$file1: found $file_tag1 - expected $current_tag" echo "$file2: found $file_tag2 - expected $current_tag" - echo "$file2: found $file_tag3 - expected $current_tag" + echo "$file3: found $file_tag3 - expected $current_tag" + echo "$file4: found $file_tag4 - expected $current_tag" exit 1 fi diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 654ac4ac..c91e9839 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -120,9 +120,9 @@ _[Read more about this](https://github.com/meilisearch/integration-guides/blob/m ⚠️ Before doing anything, make sure you got through the guide about [Releasing an Integration](https://github.com/meilisearch/integration-guides/blob/main/resources/integration-release.md). Make a PR updating the different versions with the new one on these files: -- [`MeiliSearch.podspec`](/MeiliSearch.podspec): - ```ruby - s.version = 'X.X.X' +- [`Sources/MeiliSearch/Model/PackageVersion.swift`](/Sources/MeiliSearch/Model/PackageVersion.swift): + ```swift + private static let current = "X.X.X" ``` - [`.code-samples.meilisearch.yaml`](/.code-samples.meilisearch.yaml) on the line containing the following: ```ruby