From 71aaf4b6e2f7e9ec0c9b2845d53f5c5ccf6501a4 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 14 May 2024 16:53:37 +0300 Subject: [PATCH 1/8] bump version --- CHANGELOG.md | 2 ++ PostHog.podspec | 2 +- PostHog/PostHogVersion.swift | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b6c81bcb..454331ca3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ ## Next +## 3.2.5 - 2024-05-14 + ## 3.2.4 - 2024-03-12 - `maxQueueSize` wasn't respected when capturing events [#116](https://github.com/PostHog/posthog-ios/pull/116) diff --git a/PostHog.podspec b/PostHog.podspec index a26f3b975..76c4ac5d0 100644 --- a/PostHog.podspec +++ b/PostHog.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "PostHog" - s.version = "3.2.4" + s.version = "3.2.5" s.summary = "The hassle-free way to add posthog to your iOS app." s.description = <<-DESC diff --git a/PostHog/PostHogVersion.swift b/PostHog/PostHogVersion.swift index 6e384a12a..f16c8f63b 100644 --- a/PostHog/PostHogVersion.swift +++ b/PostHog/PostHogVersion.swift @@ -9,7 +9,7 @@ import Foundation // if you change this, make sure to also change it in the podspec and check if the script scripts/bump-version.sh still works // This property is internal only -public var postHogVersion = "3.2.4" +public var postHogVersion = "3.2.5" // This property is internal only public var postHogSdkName = "posthog-ios" From a78bd5372342f68f214db14be1e4721def446dff Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 14 May 2024 17:22:47 +0300 Subject: [PATCH 2/8] fix --- PostHog/PostHogStorage.swift | 18 ++++++++++++++++-- PostHogExample/AppDelegate.swift | 1 + 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/PostHog/PostHogStorage.swift b/PostHog/PostHogStorage.swift index e80754448..c3af79408 100644 --- a/PostHog/PostHogStorage.swift +++ b/PostHog/PostHogStorage.swift @@ -20,6 +20,7 @@ func applicationSupportDirectoryURL() -> URL { } class PostHogStorage { + // when adding or removing items here, make sure to update the reset method enum StorageKey: String { case distinctId = "posthog.distinctId" case anonymousId = "posthog.anonymousId" @@ -125,8 +126,21 @@ class PostHogStorage { } public func reset() { - deleteSafely(appFolderUrl) - createDirectoryAtURLIfNeeded(url: appFolderUrl) + // sadly the StorageKey.allCases does not work here + deleteAndCreateDir(url(forKey: .distinctId)) + deleteAndCreateDir(url(forKey: .anonymousId)) + // .queue not needed since it'll be deleted by the queue.clear() + deleteAndCreateDir(url(forKey: .oldQeueue)) + deleteAndCreateDir(url(forKey: .enabledFeatureFlags)) + deleteAndCreateDir(url(forKey: .enabledFeatureFlagPayloads)) + deleteAndCreateDir(url(forKey: .groups)) + deleteAndCreateDir(url(forKey: .registerProperties)) + deleteAndCreateDir(url(forKey: .optOut)) + } + + private func deleteAndCreateDir(_ url: URL) { + deleteSafely(url) + createDirectoryAtURLIfNeeded(url: url) } public func remove(key: StorageKey) { diff --git a/PostHogExample/AppDelegate.swift b/PostHogExample/AppDelegate.swift index aa5a36e4c..e59851245 100644 --- a/PostHogExample/AppDelegate.swift +++ b/PostHogExample/AppDelegate.swift @@ -24,6 +24,7 @@ class AppDelegate: NSObject, UIApplicationDelegate { PostHogSDK.shared.setup(config) // PostHogSDK.shared.debug() // PostHogSDK.shared.capture("App started!") +// PostHogSDK.shared.reset() let defaultCenter = NotificationCenter.default From 2e09488bf72819cc28c4c1ddf0fa673dbe537533 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 14 May 2024 17:31:13 +0300 Subject: [PATCH 3/8] changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 454331ca3..613ec65dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 3.2.5 - 2024-05-14 +- fix: `reset` deletes only sdk files instead of the whole folder [#132](https://github.com/PostHog/posthog-ios/pull/132) + ## 3.2.4 - 2024-03-12 - `maxQueueSize` wasn't respected when capturing events [#116](https://github.com/PostHog/posthog-ios/pull/116) From 9528ae4f6233b16f79ed172b3249f1807746a7f6 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 14 May 2024 17:33:51 +0300 Subject: [PATCH 4/8] add branch to ci flow --- .github/workflows/build.yml | 1 + .github/workflows/lint.yml | 1 + .github/workflows/test.yml | 1 + 3 files changed, 3 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 165c2d94f..42c0635aa 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - 3.2.5_patch pull_request: paths-ignore: - "**/*.md" diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 0cd8b7397..a9e0a7f01 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - 3.2.5_patch pull_request: paths-ignore: - "**/*.md" diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 40469d772..35ae6045e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -3,6 +3,7 @@ on: push: branches: - main + - 3.2.5_patch pull_request: paths-ignore: - "**/*.md" From c43bec77b3d25c736e185fec78c2429a0a0710a7 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Tue, 14 May 2024 17:41:00 +0300 Subject: [PATCH 5/8] fix --- PostHog/PostHogStorage.swift | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/PostHog/PostHogStorage.swift b/PostHog/PostHogStorage.swift index c3af79408..f0f6ec3c8 100644 --- a/PostHog/PostHogStorage.swift +++ b/PostHog/PostHogStorage.swift @@ -127,20 +127,15 @@ class PostHogStorage { public func reset() { // sadly the StorageKey.allCases does not work here - deleteAndCreateDir(url(forKey: .distinctId)) - deleteAndCreateDir(url(forKey: .anonymousId)) + deleteSafely(url(forKey: .distinctId)) + deleteSafely(url(forKey: .anonymousId)) // .queue not needed since it'll be deleted by the queue.clear() - deleteAndCreateDir(url(forKey: .oldQeueue)) - deleteAndCreateDir(url(forKey: .enabledFeatureFlags)) - deleteAndCreateDir(url(forKey: .enabledFeatureFlagPayloads)) - deleteAndCreateDir(url(forKey: .groups)) - deleteAndCreateDir(url(forKey: .registerProperties)) - deleteAndCreateDir(url(forKey: .optOut)) - } - - private func deleteAndCreateDir(_ url: URL) { - deleteSafely(url) - createDirectoryAtURLIfNeeded(url: url) + deleteSafely(url(forKey: .oldQeueue)) + deleteSafely(url(forKey: .enabledFeatureFlags)) + deleteSafely(url(forKey: .enabledFeatureFlagPayloads)) + deleteSafely(url(forKey: .groups)) + deleteSafely(url(forKey: .registerProperties)) + deleteSafely(url(forKey: .optOut)) } public func remove(key: StorageKey) { From 8d16840982f3f0f95314d2b49f6879b5f816684a Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 15 May 2024 09:18:10 +0300 Subject: [PATCH 6/8] add test --- PostHogTests/PostHogSDKTest.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/PostHogTests/PostHogSDKTest.swift b/PostHogTests/PostHogSDKTest.swift index 9a89889ec..8a3b1643b 100644 --- a/PostHogTests/PostHogSDKTest.swift +++ b/PostHogTests/PostHogSDKTest.swift @@ -694,6 +694,18 @@ class PostHogSDKTest: QuickSpec { sut.reset() sut.close() } + + it("reset deletes posthog folder but not other folders") { + let appFolder = applicationSupportDirectoryURL() + expect(FileManager.default.fileExists(atPath: appFolder.path)) == false + + let sut = self.getSut() + + sut.reset() + sut.close() + + expect(FileManager.default.fileExists(atPath: appFolder.path)) == true + } } } From 92cdd5e5137528eb12284b7daa4d0af1ec76e1a9 Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 15 May 2024 09:19:26 +0300 Subject: [PATCH 7/8] rename test --- PostHogTests/PostHogSDKTest.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PostHogTests/PostHogSDKTest.swift b/PostHogTests/PostHogSDKTest.swift index 8a3b1643b..debdd4ad7 100644 --- a/PostHogTests/PostHogSDKTest.swift +++ b/PostHogTests/PostHogSDKTest.swift @@ -695,7 +695,7 @@ class PostHogSDKTest: QuickSpec { sut.close() } - it("reset deletes posthog folder but not other folders") { + it("reset deletes posthog files but not other folders") { let appFolder = applicationSupportDirectoryURL() expect(FileManager.default.fileExists(atPath: appFolder.path)) == false From 8b2508444962d67aa5f8770074f32d493383dafd Mon Sep 17 00:00:00 2001 From: Manoel Aranda Neto Date: Wed, 15 May 2024 09:23:08 +0300 Subject: [PATCH 8/8] fix lint --- .github/workflows/lint.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index a9e0a7f01..1d1798248 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,4 +14,6 @@ jobs: - uses: actions/checkout@v4 - name: Run lints - run: make lint + run: | + brew install swiftlint + make lint