Skip to content

Commit 74be985

Browse files
authored
ci: Run the Flagsmith SDK behavioural spec (#110)
1 parent f92f66d commit 74be985

5 files changed

Lines changed: 77 additions & 1 deletion

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: SDK spec
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [main]
7+
8+
permissions:
9+
contents: read
10+
11+
jobs:
12+
sdk-spec:
13+
# Keep the ref in `uses:` and `spec-ref` in sync.
14+
uses: Flagsmith/sdk-spec/.github/workflows/run-spec.yml@v0.3.0
15+
with:
16+
spec-ref: v0.3.0
17+
language: ruby

‎flagsmith.gemspec‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
1212
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
1313
spec.files = Dir.chdir(__dir__) do
1414
`git ls-files -z`.split("\x0").reject do |f|
15-
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
15+
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|sdk-spec|features)/|\.(?:git|travis|circleci)|appveyor)})
1616
end
1717
end
1818

‎renovate.json‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,15 @@
44
"ignorePresets": [":semanticPrefixFixDepsChoreOthers"],
55
"semanticCommitType": "deps",
66
"git-submodules": { "enabled": true },
7+
"customManagers": [
8+
{
9+
"customType": "regex",
10+
"managerFilePatterns": ["/^\\.github/workflows/sdk-spec\\.yml$/"],
11+
"matchStrings": ["spec-ref: (?<currentValue>v[\\d.]+)"],
12+
"depNameTemplate": "Flagsmith/sdk-spec",
13+
"datasourceTemplate": "github-tags"
14+
}
15+
],
716
"packageRules": [
817
{
918
"matchUpdateTypes": [
@@ -23,6 +32,11 @@
2332
"matchManagers": ["git-submodules"],
2433
"versioning": "semver-coerced",
2534
"enabled": true
35+
},
36+
{
37+
"matchPackageNames": ["Flagsmith/sdk-spec"],
38+
"groupName": "SDK spec",
39+
"enabled": true
2640
}
2741
]
2842
}

‎sdk-spec/Dockerfile‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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/ruby .
3+
FROM docker.io/library/ruby:3.3-slim
4+
5+
# The gemspec lists its files with `git ls-files`.
6+
RUN apt-get update \
7+
&& apt-get install -y --no-install-recommends git \
8+
&& rm -rf /var/lib/apt/lists/*
9+
10+
WORKDIR /sdk
11+
COPY . .
12+
RUN gem build flagsmith.gemspec --output flagsmith.gem \
13+
&& gem install --no-document flagsmith.gem
14+
15+
COPY --from=harness harness.rb /harness/harness.rb
16+
17+
ENTRYPOINT ["ruby", "/harness/harness.rb", "sdk-spec/steps.rb"]

‎sdk-spec/steps.rb‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# frozen_string_literal: true
2+
3+
# Steps for the Flagsmith SDK behavioural spec: https://github.com/Flagsmith/sdk-spec
4+
#
5+
# Each method implements the Gherkin step in the comment above it.
6+
7+
require 'flagsmith'
8+
9+
def as_spec_flags(flags)
10+
flags.all_flags.map do |flag|
11+
{ feature: flag.feature_name, enabled: flag.enabled, value: flag.value }
12+
end
13+
end
14+
15+
# Create the SDK client
16+
def create_client(environment_key, api_url)
17+
Flagsmith::Client.new(environment_key: environment_key, api_url: api_url)
18+
end
19+
20+
# When the application gets the environment flags
21+
def get_environment_flags(flagsmith)
22+
as_spec_flags(flagsmith.get_environment_flags)
23+
end
24+
25+
# When the application gets the flags for identity "{identifier}" with traits:
26+
def get_identity_flags(flagsmith, identifier, traits)
27+
as_spec_flags(flagsmith.get_identity_flags(identifier, **traits))
28+
end

0 commit comments

Comments
 (0)