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
17 changes: 17 additions & 0 deletions .github/workflows/sdk-spec.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: SDK spec

on:
pull_request:
push:
branches: [main]

permissions:
contents: read

jobs:
sdk-spec:
# Keep the ref in `uses:` and `spec-ref` in sync.
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.5.0
with:
spec-ref: v0.5.0
language: dart
23 changes: 23 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"$schema": "https://docs.renovatebot.com/renovate-schema.json",
"extends": ["config:recommended"],
"enabledManagers": ["custom.regex"],
"customManagers": [
{
"customType": "regex",
"managerFilePatterns": ["/^\\.github/workflows/sdk-spec\\.yml$/"],
"matchStrings": [
"uses: Flagsmith/sdk-spec/\\.github/workflows/run-spec\\.yml@(?<currentValue>v[\\d.]+)",
"spec-ref: (?<currentValue>v[\\d.]+)"
],
"depNameTemplate": "Flagsmith/sdk-spec",
"datasourceTemplate": "github-tags"
}
],
"packageRules": [
{
"matchPackageNames": ["Flagsmith/sdk-spec"],
"groupName": "SDK spec"
}
]
}
15 changes: 15 additions & 0 deletions sdk-spec/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Runs this SDK, built from source, under the Flagsmith SDK behavioural spec.
# docker build -f sdk-spec/Dockerfile --build-context harness=<sdk-spec>/harness/dart .
FROM ghcr.io/cirruslabs/flutter:3.44.0

WORKDIR /sdk
COPY . .
COPY --from=harness . /harness
RUN flutter pub get \
&& dart /harness/build.dart -o sdk-spec/harness_main.dart sdk-spec/steps.dart \
&& flutter build bundle --debug --target sdk-spec/harness_main.dart \
&& ln -s "$(find "$(dirname "$(readlink -f "$(command -v flutter)")")/cache/artifacts/engine" \
-path '*/linux-*/flutter_tester' -print -quit)" /usr/local/bin/flutter_tester

# The SDK needs Flutter, so run on the headless engine that `flutter test` uses.
ENTRYPOINT ["flutter_tester", "--non-interactive", "--disable-vm-service", "build/flutter_assets/kernel_blob.bin"]
34 changes: 34 additions & 0 deletions sdk-spec/steps.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// Steps for the Flagsmith SDK behavioural spec: https://github.com/Flagsmith/sdk-spec
import 'package:flagsmith/flagsmith.dart';

// Create the SDK client
Future<FlagsmithClient> createClient(String environmentKey, String apiUrl) =>
FlagsmithClient.init(
apiKey: environmentKey,
config: FlagsmithConfig(baseURI: apiUrl),
);

// When the application gets the environment flags
Future<List<Map<String, Object?>>> getEnvironmentFlags(
FlagsmithClient flagsmith) async =>
asSpecFlags(await flagsmith.getFeatureFlags());

// When the application gets the flags for identity "{identifier}" with traits:
Future<List<Map<String, Object?>>> getIdentityFlags(FlagsmithClient flagsmith,
String identifier, Map<String, Object?> traits) async =>
asSpecFlags(await flagsmith.getFeatureFlags(
user: Identity(identifier: identifier),
traits: [
for (final MapEntry(:key, :value) in traits.entries)
Trait(key: key, value: value),
],
));

List<Map<String, Object?>> asSpecFlags(List<Flag> flags) => [
for (final flag in flags)
{
Comment thread
Zaimwa9 marked this conversation as resolved.
'feature': flag.feature.name,
'enabled': flag.enabled,
'value': flag.value,
},
];
Loading