Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 63 additions & 6 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,82 @@ concurrency:
cancel-in-progress: true

jobs:
checks:
runs-on: macos-latest
swift:
runs-on: macos-15
timeout-minutes: 30
strategy:
fail-fast: false
matrix:
swift-version: ["6.0.3", "6.2.1"]

steps:
- name: Check out repository
uses: actions/checkout@v7
uses: actions/checkout@v6

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.2"

- name: Set up Swift
uses: swift-actions/setup-swift@v2.4.0
with:
swift-version: "6.2.1"
swift-version: ${{ matrix.swift-version }}

- name: Show toolchain versions
run: |
swift --version
xcodebuild -version
xcrun --sdk macosx --show-sdk-version

- name: Build core SDK
run: swift build --target Featurevisor

- name: Build
run: swift build
- name: Build OpenFeature provider
run: swift build --target FeaturevisorOpenFeature

- name: Test
run: swift test

- name: Test with Thread Sanitizer
if: matrix.swift-version == '6.2.1'
env:
MACOSX_DEPLOYMENT_TARGET: "13.0"
run: swift test --sanitize=thread

platforms-and-integration:
runs-on: macos-15
timeout-minutes: 30

steps:
- name: Check out repository
uses: actions/checkout@v6

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.2"

- name: Set up Swift
uses: swift-actions/setup-swift@v2.4.0
with:
swift-version: "6.2.1"

- name: Show toolchain versions
run: |
swift --version
xcodebuild -version
xcrun --sdk macosx --show-sdk-version

- name: Build core SDK for iOS
run: swift build --target Featurevisor --triple arm64-apple-ios14.0-simulator --sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" --scratch-path /tmp/featurevisor-ios-core

- name: Build OpenFeature provider for iOS
run: swift build --target FeaturevisorOpenFeature --triple arm64-apple-ios14.0-simulator --sdk "$(xcrun --sdk iphonesimulator --show-sdk-path)" --scratch-path /tmp/featurevisor-ios-openfeature

- name: Verify clean package consumers
run: ./scripts/verify-consumers.sh

- name: Set up Node.js
uses: actions/setup-node@v6
with:
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
name: Release validation

on:
push:
tags:
- "v*"

permissions:
contents: read

jobs:
validate:
runs-on: macos-15
timeout-minutes: 30

steps:
- name: Check out repository
uses: actions/checkout@v6

- name: Set up Xcode
uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: "16.2"

- name: Validate semantic version tag
shell: bash
run: |
if [[ ! "$GITHUB_REF_NAME" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$ ]]; then
echo "Expected a semantic version tag such as v1.1.0"
exit 1
fi
version="${GITHUB_REF_NAME#v}"
if ! grep -Fq "from: \"$version\"" README.md; then
echo "README installation version does not match $GITHUB_REF_NAME"
exit 1
fi

- name: Set up Swift
uses: swift-actions/setup-swift@v2.4.0
with:
swift-version: "6.2.1"

- name: Show toolchain versions
run: |
swift --version
xcodebuild -version
xcrun --sdk macosx --show-sdk-version

- name: Test
run: swift test

- name: Build public library targets
run: |
swift build --target Featurevisor
swift build --target FeaturevisorOpenFeature

- name: Verify clean package consumers
run: ./scripts/verify-consumers.sh
15 changes: 15 additions & 0 deletions Package.resolved

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

28 changes: 27 additions & 1 deletion Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,41 @@ import PackageDescription
let package = Package(
name: "featurevisor-swift2",
platforms: [
.macOS(.v13)
.iOS(.v14),
.macOS(.v11),
.tvOS(.v14),
.watchOS(.v7),
],
products: [
.library(
name: "Featurevisor",
targets: ["Featurevisor"]
),
.library(
name: "FeaturevisorOpenFeature",
targets: ["FeaturevisorOpenFeature"]
),
.executable(
name: "featurevisor",
targets: ["FeaturevisorCLI"]
),
],
dependencies: [
.package(url: "https://github.com/open-feature/swift-sdk.git", from: "0.5.0")
],
targets: [
.target(
name: "Featurevisor",
path: "Sources/Featurevisor"
),
.target(
name: "FeaturevisorOpenFeature",
dependencies: [
"Featurevisor",
.product(name: "OpenFeature", package: "swift-sdk")
],
path: "Sources/FeaturevisorOpenFeature"
),
.executableTarget(
name: "FeaturevisorCLI",
dependencies: ["Featurevisor"],
Expand All @@ -31,6 +49,14 @@ let package = Package(
dependencies: ["Featurevisor"],
path: "Tests/FeaturevisorTests"
),
.testTarget(
name: "FeaturevisorOpenFeatureTests",
dependencies: [
"FeaturevisorOpenFeature",
.product(name: "OpenFeature", package: "swift-sdk")
],
path: "Tests/FeaturevisorOpenFeatureTests"
),
.testTarget(
name: "FeaturevisorCLITests",
dependencies: ["FeaturevisorCLI", "Featurevisor"],
Expand Down
104 changes: 103 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ This SDK is compatible with [Featurevisor](https://featurevisor.com/) v3.0 proje
- [Registering modules](#registering-modules)
- [Child instance](#child-instance)
- [Close](#close)
- [OpenFeature](#openfeature)
- [CLI usage](#cli-usage)
- [Test](#test)
- [Benchmark](#benchmark)
Expand All @@ -58,7 +59,7 @@ This SDK is compatible with [Featurevisor](https://featurevisor.com/) v3.0 proje
In your Swift application, add this package using Swift Package Manager:

```swift
.package(url: "https://github.com/featurevisor/featurevisor-swift2.git", from: "0.1.0")
.package(url: "https://github.com/featurevisor/featurevisor-swift2.git", from: "1.1.0")
```

Then add the product dependency:
Expand All @@ -79,6 +80,8 @@ let f: Featurevisor = createFeaturevisor(

Most applications only need `createFeaturevisor`, `Featurevisor`, and `FeaturevisorOptions`. Public extension and observability types include `FeaturevisorModule`, `FeaturevisorDiagnostic`, and the datafile model types.

The SDK supports iOS 14, macOS 11, tvOS 14, and watchOS 7 or newer. Shared `Featurevisor`, child instance, and OpenFeature provider state is safe to use from concurrent callers. Module, diagnostic, event, and tracking callbacks are `@Sendable`; callback implementations must synchronize any mutable state they capture.

## Initialization

The SDK can be initialized by passing [datafile](https://featurevisor.com/docs/building-datafiles/) content directly:
Expand Down Expand Up @@ -586,6 +589,97 @@ swift run featurevisor assess-distribution \
--n=1000
```

## OpenFeature

The package exposes `FeaturevisorOpenFeature` as a separate library product. Targets using it should declare both package dependencies:

```swift
.package(url: "https://github.com/featurevisor/featurevisor-swift2.git", from: "1.1.0"),
.package(url: "https://github.com/open-feature/swift-sdk.git", from: "0.5.0")
```

Then add the products needed by that target:

```swift
.product(name: "Featurevisor", package: "featurevisor-swift2"),
.product(name: "FeaturevisorOpenFeature", package: "featurevisor-swift2"),
.product(name: "OpenFeature", package: "swift-sdk")
```

```swift
import Featurevisor
import FeaturevisorOpenFeature
import OpenFeature

let provider = FeaturevisorOpenFeatureProvider(
options: FeaturevisorOptions(datafile: datafile)
)

await OpenFeatureAPI.shared.setProviderAndWait(
provider: provider,
initialContext: ImmutableContext(targetingKey: "user-123")
)

let client = OpenFeatureAPI.shared.getClient()
let enabled = client.getBooleanValue(
key: "checkout",
defaultValue: false
)
```

Use `checkout` for a flag, `checkout:variation` for its variation, and `checkout:title` for its `title` variable. Boolean variables use the boolean resolver. Lists, structures, and JSON variables use the object resolver.

The provider maps Featurevisor values to OpenFeature resolvers as follows:

| Key | Resolver |
| --- | --- |
| `feature` | Boolean flag |
| `feature:variation` | String variation |
| `feature:variable` | Resolver matching the variable schema |

Integer variables can be resolved with either the integer or double resolver. Non-finite doubles are rejected with `TYPE_MISMATCH`. Invalid JSON variables also return `TYPE_MISMATCH` and the caller's default value.

OpenFeature's targeting key maps to `userId` by default. `targetingKeyField`, `keySeparator`, and `variationKey` can customize the mapping. Call `provider.close()` when the application owns the provider lifecycle and is finished with it.

You can initialize the provider from raw JSON when the application has not decoded a datafile yet:

```swift
let provider = FeaturevisorOpenFeatureProvider(
options: FeaturevisorOptions(logLevel: .warn),
datafileJSON: json
)
```

Malformed JSON returns the OpenFeature `PARSE_ERROR` code with `Could not parse datafile`. The provider keeps returning that error until a valid datafile is set through `provider.featurevisor.setDatafile(...)`. Successful replacement clears the parse error.

You can also reuse an existing Featurevisor instance:

```swift
let featurevisor = createFeaturevisor(FeaturevisorOptions(datafile: datafile))
let provider = FeaturevisorOpenFeatureProvider(featurevisor: featurevisor)
```

The caller owns an instance passed this way. Closing the provider does not close it. Call `featurevisor.close()` when every consumer is finished with it. When the provider creates the instance from `options`, the provider owns and closes it. If both are supplied, `featurevisor` takes precedence over `options`.

Featurevisor evaluation reasons map to OpenFeature reasons:

| Featurevisor reason | OpenFeature reason |
| --- | --- |
| `required`, `forced`, `sticky`, `rule`, variable overrides | `TARGETING_MATCH` |
| `allocated` | `SPLIT` |
| disabled flag, variation, or variable | `DISABLED` |
| no match, out of range, variable default | `DEFAULT` |
| missing feature, variable, or variations | `ERROR` with `FLAG_NOT_FOUND` |
| evaluation error | `ERROR` with `GENERAL` |

Resolution metadata includes `featureKey`, `featurevisorReason`, `schemaVersion`, and `revision`. It also includes `variableKey`, `ruleKey`, `bucketKey`, `bucketValue`, `forceIndex`, and `variableOverrideIndex` when those values are available. Variation resolutions populate OpenFeature's `variant` field.

The provider forwards OpenFeature tracking calls to `onTrack`. Closing a provider it owns closes Featurevisor modules and subscriptions. Closing a provider created with a caller-owned Featurevisor instance only removes provider subscriptions.

The base `Featurevisor` product does not compile or link OpenFeature provider code into an application target. Swift Package Manager still resolves the package-level `swift-sdk` dependency because both products share one package manifest. Projects that require dependency-download isolation would need the provider in a separate repository.

See the [OpenFeature provider guide](https://featurevisor.com/docs/sdks/openfeature/) for resolution reasons, errors, metadata, tracking, lifecycle, and providers for other languages.

<!-- FEATUREVISOR_DOCS_END -->

## Development of this package
Expand All @@ -602,6 +696,14 @@ To verify against the local Featurevisor example-1 project:
make test-example-1
```

To verify the public products from clean consumer packages:

```bash
./scripts/verify-consumers.sh
```

Release tags use semantic versions such as `v1.1.0`. The release validation workflow tests both public library targets and clean consumers for every release tag.

## License

MIT © [Fahad Heylaal](https://fahad19.com)
Loading
Loading