Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: setup initial release process #23

Merged
merged 9 commits into from
May 1, 2024
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
Binary file added .DS_Store
Binary file not shown.
27 changes: 25 additions & 2 deletions .github/workflows/pr-title-lint.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: "Lint PR"
name: 'Lint PR'

on:
pull_request_target:
Expand All @@ -12,6 +12,29 @@ jobs:
name: Validate PR title
runs-on: ubuntu-latest
steps:
- uses: amannn/action-semantic-pull-request@v5
- uses: amannn/action-semantic-pull-request@e9fabac35e210fea40ca5b14c0da95a099eff26f # v5
id: lint_pr_title
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2
# When the previous steps fails, the workflow would stop. By adding this
# condition you can continue the execution with the populated error message.
if: always() && (steps.lint_pr_title.outputs.error_message != null)
with:
header: pr-title-lint-error
message: |
Hey there and thank you for opening this pull request! 👋🏼

We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted.
Details:

```
${{ steps.lint_pr_title.outputs.error_message }}
```
# Delete a previous comment when the issue has been resolved
- if: ${{ steps.lint_pr_title.outputs.error_message == null }}
uses: marocchino/sticky-pull-request-comment@331f8f5b4215f0445d3c07b4967662a32a2d3e31 # v2
with:
header: pr-title-lint-error
delete: true
59 changes: 59 additions & 0 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Release Please

on:
push:
branches:
- main

jobs:
release-please:
name: Release Please
runs-on: ubuntu-latest
# Release-please creates a PR that tracks all changes
steps:
- uses: google-github-actions/release-please-action@v3
id: release
with:
release-type: ruby
command: manifest
token: ${{ secrets.RELEASE_PLEASE_ACTION_TOKEN }}
default-branch: main
signoff: "OpenFeature Bot <[email protected]>"

- name: Dump Release Please Output
env:
RELEASE_PLEASE_OUTPUT: ${{ toJson(steps.release.outputs) }}
run: |
echo "$RELEASE_PLEASE_OUTPUT"

outputs:
all: ${{ toJSON(steps.release.outputs) }}
paths_released: ${{ steps.release.outputs.paths_released }}

publish-gems:
name: Publish Ruby Gems
needs: release-please
runs-on: ubuntu-latest
if: ${{ fromJSON(needs.release-please.outputs.paths_released)[0] != null }}
strategy:
matrix:
path: ${{ fromJSON(needs.release-please.outputs.paths_released) }}
env:
TAG: ${{ fromJSON(needs.release-please.outputs.all)[format('{0}--tag_name', matrix.path)] }}
defaults:
run:
working-directory: ./${{ matrix.path }}
steps:
- name: Checkout
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # v4
with:
ref: ${{ env.TAG }}

- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
# TODO see if the ruby version matter for publishing
# ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically

## TODO add a step to publish the gem
4 changes: 2 additions & 2 deletions .github/workflows/ruby.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./providers/openfeature-sdk-meta_provider
working-directory: ./providers/openfeature-meta_provider
strategy:
matrix:
ruby-version:
Expand All @@ -61,6 +61,6 @@ jobs:
with:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
working-directory: ./providers/openfeature-sdk-meta_provider
working-directory: ./providers/openfeature-meta_provider
- name: Lint and test
run: bin/rake
4 changes: 4 additions & 0 deletions .release-please-manifest.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"providers/openfeature-flagd-provider": "0.0.1",
"providers/openfeature-meta_provider": "0.0.1"
}
Binary file added providers/.DS_Store
Binary file not shown.
2 changes: 1 addition & 1 deletion providers/openfeature-flagd-provider/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# OpenFeature FlagD Provider for Ruby

This is the Ruby [provider](https://openfeature.dev/docs/specification/sections/providers) implementation of the [FlagD](https://github.com/open-feature/flagd)

## Installation

Add this line to your application's Gemfile:
Expand Down Expand Up @@ -75,7 +76,6 @@ OpenFeature::SDK.configure do |config|
end
```


If no environment variables are set the [default configuration](./lib/openfeature/flagd/provider/configuration.rb) is set

## Contributing
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

require_relative "provider/configuration"
require_relative "provider/client"
require_relative "provider/version"

module OpenFeature
module FlagD
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

module OpenFeature
module FlagD
VERSION = "0.0.1"
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# frozen_string_literal: true

require_relative "lib/openfeature/flagd/provider/version"

Gem::Specification.new do |spec|
spec.name = "openfeature-flagd-provider"
spec.version = "0.0.1"
spec.version = OpenFeature::FlagD::VERSION
spec.authors = ["OpenFeature Authors"]
spec.email = ["[email protected]"]

Expand All @@ -14,7 +16,7 @@ Gem::Specification.new do |spec|

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-flagd-provider"
spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/CHANGELOG.md"
spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/providers/openfeature-flagd-provider/CHANGELOG.md"
spec.metadata["bug_tracker_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/issues"
spec.metadata["documentation_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/README.md"

Expand Down
6 changes: 6 additions & 0 deletions providers/openfeature-meta_provider/Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in openfeature-meta_provider.gemspec
gemspec
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
openfeature-sdk-meta_provider (0.1.0)
openfeature-meta_provider (0.0.1)
openfeature-sdk (~> 0.3.0)

GEM
Expand Down Expand Up @@ -86,7 +86,7 @@ PLATFORMS

DEPENDENCIES
debug (~> 1.9.2)
openfeature-sdk-meta_provider!
openfeature-meta_provider!
rake (~> 13.0)
rspec (~> 3.12)
standard (~> 1.34)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# frozen_string_literal: true

module OpenFeature
# Used to pull from multiple providers.
class MetaProvider
# @param providers [Array<Provider>]
# @param strategy [Symbol] When `:first_match`, returns first matched resolution. Providers will be searched
# in the order they were given. Defaults to `:first_match`.
def initialize(providers:, strategy: :first_match)
@providers = providers
@strategy = strategy
end

def metadata
SDK::Provider::ProviderMetadata.new(name: "MetaProvider: #{providers.map { |provider| provider.metadata.name }.join(", ")}")
end

def init
providers.each { |provider| provider.init }
end

def shutdown
providers.each(&:shutdown)
end

def fetch_boolean_value(flag_key:, default_value:, evaluation_context: nil)
fetch_from_sources(default_value:) do |provider|
provider.fetch_boolean_value(flag_key:, default_value:, evaluation_context:)
end
end

def fetch_number_value(flag_key:, default_value:, evaluation_context: nil)
fetch_from_sources(default_value:) do |provider|
provider.fetch_number_value(flag_key:, default_value:, evaluation_context:)
end
end

def fetch_object_value(flag_key:, default_value:, evaluation_context: nil)
fetch_from_sources(default_value:) do |provider|
provider.fetch_object_value(flag_key:, default_value:, evaluation_context:)
end
end

def fetch_string_value(flag_key:, default_value:, evaluation_context: nil)
fetch_from_sources(default_value:) do |provider|
provider.fetch_string_value(flag_key:, default_value:, evaluation_context:)
end
end

private

attr_reader :providers, :strategy

def fetch_from_sources(default_value:, &blk)
case strategy
when :first_match
successful_details = providers.each do |provider|
details = yield(provider)

break details if details.error_code.nil?
rescue
next
end

if successful_details.is_a?(SDK::Provider::ResolutionDetails)
successful_details
else
SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: SDK::Provider::Reason::ERROR)
end
else
SDK::Provider::ResolutionDetails.new(value: default_value, error_code: SDK::Provider::ErrorCode::GENERAL, reason: "Unknown strategy for MetaProvider")
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module OpenFeature
META_PROVIDER_VERSION = "0.0.1"
end
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
# frozen_string_literal: true

require_relative "lib/openfeature/meta_provider_version"

Gem::Specification.new do |spec|
spec.name = "openfeature-sdk-meta_provider"
spec.version = "0.1.0"
spec.name = "openfeature-meta_provider"
spec.version = OpenFeature::META_PROVIDER_VERSION
spec.authors = ["OpenFeature Authors"]
spec.email = ["[email protected]"]

spec.summary = "Meta provider for the OpenFeature Ruby SDK"
spec.description = "The MetaProvider wraps multiple other providers and uses a given strategy to resolve flags using all of them."
spec.homepage = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-sdk-meta_provider"
spec.homepage = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider"
spec.license = "Apache-2.0"
spec.required_ruby_version = ">= 3.1"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-sdk-meta_provider"
spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/CHANGELOG.md"
spec.metadata["source_code_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/providers/openfeature-meta_provider"
spec.metadata["changelog_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/blob/main/providers/openfeature-meta_provider/CHANGELOG.md"
spec.metadata["bug_tracker_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/issues"
spec.metadata["documentation_uri"] = "https://github.com/open-feature/ruby-sdk-contrib/README.md"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
end
end

RSpec.describe OpenFeature::SDK::Provider::MetaProvider do
RSpec.describe OpenFeature::MetaProvider do
subject(:meta_provider) { described_class.new(providers: [provider_one, provider_two]) }

let(:provider_one) do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

require "bundler/setup"
require "debug"
require "open_feature/sdk/provider/meta_provider"
require "openfeature/meta_provider"
require "open_feature/sdk"

RSpec.configure do |config|
Expand Down
6 changes: 0 additions & 6 deletions providers/openfeature-sdk-meta_provider/Gemfile

This file was deleted.

Loading