Skip to content
This repository was archived by the owner on Oct 16, 2025. It is now read-only.

Commit ce206d0

Browse files
hyochanclaude
andauthored
feat: add centralized version management (#14)
## Summary - Added `openiap-versions.json` for centralized version tracking - Created version management system that reads from JSON file - Enables easy version updates across the SDK ## Changes - Add `openiap-versions.json` with current versions (apple: 1.2.3, gql: 1.0.9) - Create `OpenIapVersion.swift` to read versions at runtime - Update Package.swift to include version file as resource - Expose version info through `OpenIapVersionInfo` enum ## Usage ```swift // Get current SDK version let sdkVersion = OpenIapVersionInfo.sdkVersion // "1.2.3" // Get GraphQL reference version let gqlVersion = OpenIapVersionInfo.gqlVersion // "1.0.9" ``` 🤖 Generated with [Claude Code](https://claude.ai/code) --------- Co-authored-by: Claude <noreply@anthropic.com>
1 parent 520dcd9 commit ce206d0

File tree

5 files changed

+88
-2
lines changed

5 files changed

+88
-2
lines changed

.github/workflows/deploy-swift.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,12 @@ jobs:
3636
git config user.name "hyodotdev"
3737
git config user.email "hyo@hyo.dev"
3838
39+
- name: Install jq (for JSON processing)
40+
run: |
41+
if ! command -v jq &> /dev/null; then
42+
brew install jq
43+
fi
44+
3945
- name: Bump version and tag
4046
run: |
4147
./scripts/bump-version.sh "${{ env.VERSION }}"

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,10 @@ let package = Package(
2020
.target(
2121
name: "OpenIAP",
2222
dependencies: [],
23-
path: "Sources"),
23+
path: "Sources",
24+
resources: [
25+
.copy("openiap-versions.json")
26+
]),
2427
.testTarget(
2528
name: "OpenIapTests",
2629
dependencies: ["OpenIAP"],

Sources/OpenIapVersion.swift

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import Foundation
2+
3+
/// OpenIAP version management
4+
public struct OpenIapVersion {
5+
/// Current OpenIAP Apple SDK version
6+
public static let current: String = {
7+
// Try to load version from openiap-versions.json
8+
if let version = loadVersionFromJSON() {
9+
return version
10+
}
11+
// Fallback to hardcoded version
12+
return "1.2.3"
13+
}()
14+
15+
/// OpenIAP GraphQL version for reference
16+
public static let gqlVersion: String = {
17+
// Try to load GQL version from openiap-versions.json
18+
if let version = loadGQLVersionFromJSON() {
19+
return version
20+
}
21+
// Fallback to hardcoded version
22+
return "1.0.9"
23+
}()
24+
25+
private static func loadVersionFromJSON() -> String? {
26+
guard let url = Bundle.module.url(forResource: "openiap-versions", withExtension: "json"),
27+
let data = try? Data(contentsOf: url),
28+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
29+
let version = json["apple"] as? String else {
30+
return nil
31+
}
32+
return version
33+
}
34+
35+
private static func loadGQLVersionFromJSON() -> String? {
36+
guard let url = Bundle.module.url(forResource: "openiap-versions", withExtension: "json"),
37+
let data = try? Data(contentsOf: url),
38+
let json = try? JSONSerialization.jsonObject(with: data) as? [String: Any],
39+
let version = json["gql"] as? String else {
40+
return nil
41+
}
42+
return version
43+
}
44+
}
45+
46+
// MARK: - Version Info
47+
48+
/// Namespace for OpenIAP version information
49+
public enum OpenIapVersionInfo {
50+
/// Current OpenIAP Apple SDK version
51+
public static var sdkVersion: String {
52+
OpenIapVersion.current
53+
}
54+
55+
/// OpenIAP GraphQL version for reference
56+
public static var gqlVersion: String {
57+
OpenIapVersion.gqlVersion
58+
}
59+
}

Sources/openiap-versions.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"apple": "1.2.3",
3+
"gql": "1.0.9"
4+
}

scripts/bump-version.sh

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,20 @@ echo "New version: $NEW_VERSION"
4141
# Update VERSION file
4242
echo "$NEW_VERSION" > VERSION
4343

44+
# Update openiap-versions.json
45+
if [ -f "Sources/openiap-versions.json" ]; then
46+
# Use a temporary file to update JSON
47+
jq --arg version "$NEW_VERSION" '.apple = $version' Sources/openiap-versions.json > Sources/openiap-versions.json.tmp && \
48+
mv Sources/openiap-versions.json.tmp Sources/openiap-versions.json
49+
echo "✅ Updated openiap-versions.json"
50+
fi
51+
52+
# Update OpenIapVersion.swift fallback version
53+
if [ -f "Sources/OpenIapVersion.swift" ]; then
54+
sed -i '' "s/return \"[0-9.]*\"/return \"$NEW_VERSION\"/" Sources/OpenIapVersion.swift
55+
echo "✅ Updated OpenIapVersion.swift fallback"
56+
fi
57+
4458
# Update openiap.podspec
4559
sed -i '' "s/s.version.*=.*'.*'/s.version = '$NEW_VERSION'/" openiap.podspec
4660

@@ -51,7 +65,7 @@ sed -i '' "s/pod 'openiap', '~> [0-9.]*'/pod 'openiap', '~> $NEW_VERSION'/" READ
5165
sed -i '' "s/.package(url: \"https:\/\/github.com\/hyodotdev\/openiap-apple.git\", from: \"[0-9.]*\")/.package(url: \"https:\/\/github.com\/hyodotdev\/openiap-apple.git\", from: \"$NEW_VERSION\")/" README.md
5266

5367
# Commit changes
54-
git add VERSION openiap.podspec README.md
68+
git add VERSION openiap.podspec README.md Sources/openiap-versions.json Sources/OpenIapVersion.swift
5569
git commit -m "Bump version to $NEW_VERSION"
5670

5771
# Push commits

0 commit comments

Comments
 (0)