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.3.0
with:
spec-ref: v0.3.0
language: ruby
2 changes: 1 addition & 1 deletion flagsmith.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Gem::Specification.new do |spec|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(__dir__) do
`git ls-files -z`.split("\x0").reject do |f|
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
(f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|sdk-spec|features)/|\.(?:git|travis|circleci)|appveyor)})
end
end

Expand Down
14 changes: 14 additions & 0 deletions renovate.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,15 @@
"ignorePresets": [":semanticPrefixFixDepsChoreOthers"],
"semanticCommitType": "deps",
"git-submodules": { "enabled": true },
"customManagers": [
{
"customType": "regex",
"managerFilePatterns": ["/^\\.github/workflows/sdk-spec\\.yml$/"],
"matchStrings": ["spec-ref: (?<currentValue>v[\\d.]+)"],
"depNameTemplate": "Flagsmith/sdk-spec",
"datasourceTemplate": "github-tags"
}
],
"packageRules": [
{
"matchUpdateTypes": [
Expand All @@ -23,6 +32,11 @@
"matchManagers": ["git-submodules"],
"versioning": "semver-coerced",
"enabled": true
},
{
"matchPackageNames": ["Flagsmith/sdk-spec"],
"groupName": "SDK spec",
"enabled": true
}
]
}
17 changes: 17 additions & 0 deletions sdk-spec/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Runs this SDK, built from source, under the Flagsmith SDK behavioural spec.
# docker build -f sdk-spec/Dockerfile --build-context harness=<sdk-spec>/harness/ruby .
FROM docker.io/library/ruby:3.3-slim

# The gemspec lists its files with `git ls-files`.
RUN apt-get update \
&& apt-get install -y --no-install-recommends git \
&& rm -rf /var/lib/apt/lists/*

WORKDIR /sdk
COPY . .
RUN gem build flagsmith.gemspec --output flagsmith.gem \
&& gem install --no-document flagsmith.gem

COPY --from=harness harness.rb /harness/harness.rb

ENTRYPOINT ["ruby", "/harness/harness.rb", "sdk-spec/steps.rb"]
28 changes: 28 additions & 0 deletions sdk-spec/steps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

# Steps for the Flagsmith SDK behavioural spec: https://github.com/Flagsmith/sdk-spec
#
# Each method implements the Gherkin step in the comment above it.

require 'flagsmith'

def as_spec_flags(flags)
flags.all_flags.map do |flag|
{ feature: flag.feature_name, enabled: flag.enabled, value: flag.value }
end
end

# Create the SDK client
def create_client(environment_key, api_url)
Flagsmith::Client.new(environment_key: environment_key, api_url: api_url)
end

# When the application gets the environment flags
def get_environment_flags(flagsmith)
as_spec_flags(flagsmith.get_environment_flags)
end

# When the application gets the flags for identity "{identifier}" with traits:
def get_identity_flags(flagsmith, identifier, traits)
as_spec_flags(flagsmith.get_identity_flags(identifier, **traits))
end
Loading