Skip to content

Commit 45ebb03

Browse files
committed
ci: Implement the SDK spec as a steps file
1 parent a515240 commit 45ebb03

5 files changed

Lines changed: 77 additions & 177 deletions

File tree

‎.github/workflows/sdk-spec.yml‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ permissions:
1111
jobs:
1212
sdk-spec:
1313
# Keep the ref in `uses:` and `spec-ref` in sync.
14-
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.1.1
14+
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@feat/v0.2.0
1515
with:
16-
spec-ref: v0.1.1
16+
spec-ref: feat/v0.2.0
17+
language: java

‎sdk-spec/Dockerfile‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Runs this SDK, built from source, under the Flagsmith SDK behavioural spec.
2+
# docker build -f sdk-spec/Dockerfile --build-context harness=<sdk-spec>/harness/java .
3+
FROM docker.io/library/maven:3.9-eclipse-temurin-11 AS build
4+
5+
WORKDIR /sdk
6+
COPY pom.xml lombok.config ./
7+
COPY src/main ./src/main
8+
RUN mvn --batch-mode --no-transfer-progress \
9+
-Dmaven.test.skip=true -Dcheckstyle.skip=true -Djacoco.skip=true -Dmaven.source.skip=true \
10+
package dependency:copy-dependencies -DincludeScope=runtime -DoutputDirectory=target/lib \
11+
&& cp target/flagsmith-java-client-*.jar target/lib/
12+
13+
COPY --from=harness Harness.java /harness/Harness.java
14+
COPY sdk-spec/Steps.java ./sdk-spec/Steps.java
15+
RUN javac -cp "target/lib/*" -d target/classes-spec /harness/Harness.java sdk-spec/Steps.java
16+
17+
FROM docker.io/library/eclipse-temurin:11-jre
18+
19+
WORKDIR /sdk
20+
COPY --from=build /sdk/target/lib ./lib
21+
COPY --from=build /sdk/target/classes-spec ./classes
22+
COPY sdk-spec/Steps.java ./sdk-spec/Steps.java
23+
24+
ENTRYPOINT ["java", "-XX:TieredStopAtLevel=1", "-cp", "classes:lib/*", "Harness", "sdk-spec/Steps.java"]

‎sdk-spec/Steps.java‎

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
import com.flagsmith.FlagsmithClient;
2+
import com.flagsmith.exceptions.FlagsmithClientError;
3+
import com.flagsmith.models.BaseFlag;
4+
import com.flagsmith.models.Flags;
5+
import java.util.List;
6+
import java.util.Map;
7+
import java.util.stream.Collectors;
8+
9+
/**
10+
* Steps for the Flagsmith SDK behavioural spec: https://github.com/Flagsmith/sdk-spec
11+
*
12+
* <p>Each method implements the Gherkin step in the comment above it.
13+
*/
14+
public class Steps {
15+
16+
/** A flag in the shape the spec expects. */
17+
public static class SpecFlag {
18+
public final String feature;
19+
public final boolean enabled;
20+
public final Object value;
21+
22+
SpecFlag(BaseFlag flag) {
23+
feature = flag.getFeatureName();
24+
enabled = flag.getEnabled();
25+
value = flag.getValue();
26+
}
27+
}
28+
29+
static List<SpecFlag> asSpecFlags(Flags flags) {
30+
return flags.getAllFlags().stream().map(SpecFlag::new).collect(Collectors.toList());
31+
}
32+
33+
// Given an SDK client for the environment
34+
static FlagsmithClient createClient(String environmentKey, String apiUrl) {
35+
return FlagsmithClient.newBuilder().setApiKey(environmentKey).withApiUrl(apiUrl).build();
36+
}
37+
38+
// When the application gets the environment flags
39+
static List<SpecFlag> getEnvironmentFlags(FlagsmithClient flagsmith)
40+
throws FlagsmithClientError {
41+
return asSpecFlags(flagsmith.getEnvironmentFlags());
42+
}
43+
44+
// When the application gets the flags for identity "{identifier}" with traits:
45+
static List<SpecFlag> getIdentityFlags(
46+
FlagsmithClient flagsmith, String identifier, Map<String, Object> traits)
47+
throws FlagsmithClientError {
48+
return asSpecFlags(flagsmith.getIdentityFlags(identifier, traits));
49+
}
50+
}

‎spec-adapter/Adapter.java‎

Lines changed: 0 additions & 151 deletions
This file was deleted.

‎spec-adapter/Dockerfile‎

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)