Skip to content

Commit

Permalink
chore(ci): Test against all supported dependency versions (#159)
Browse files Browse the repository at this point in the history
* Test against all supported dependency versions

* Add explicit dependency on `google-protobuf`

* Increase `google-protobuf` version requirement to 3.21.12+

  Earlier versions fail to load the `protovalidate` extension field descriptors with
  "field with proto3_optional was not in a oneof (buf.validate.priv.field)".

  protocolbuffers/upb#1034

Signed-off-by: Andrew Haines <haines@cerbos.dev>
  • Loading branch information
haines committed Jun 10, 2024
1 parent 0615db1 commit 1bfb7c7
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 11 deletions.
18 changes: 16 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,13 @@ jobs:
GITHUB_TOKEN: ${{ github.token }}

test:
name: Test (Cerbos ${{ matrix.cerbos }} | Ruby ${{ matrix.ruby }})
name: Test (${{ matrix.title }})
runs-on: ubuntu-latest
continue-on-error: ${{ github.event_name != 'schedule' && endsWith(matrix.cerbos, '-prerelease') }}
env:
CERBOS_VERSION: ${{ matrix.cerbos }}
TEST_MATRIX_DEPENDENCY_NAME: ${{ matrix.dependency_name }}
TEST_MATRIX_DEPENDENCY_VERSION: ${{ matrix.dependency_version }}
needs:
- test-matrix
strategy:
Expand All @@ -60,9 +62,21 @@ jobs:
- name: Set up Ruby
uses: ruby/setup-ruby@v1
with:
bundler-cache: true
ruby-version: ${{ matrix.ruby }}

- name: Update Gemfile.lock
if: ${{ matrix.dependency_name }}
run: bin/bundle lock --update ${{ matrix.dependency_name }}

- name: Install gems
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: List installed gems
run: bin/bundle list

- name: Start test servers
run: bin/rake test:servers:start

Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
This makes the API consistent with policy expressions.
`attributes` is still supported for backwards compatibility, but is now deprecated.

- Increased [`google-protobuf`] version requirement to 3.21.12+ to avoid [failure to load `protovalidate` extension field descriptors](https://github.com/protocolbuffers/upb/pull/1034) ([#159](https://github.com/cerbos/cerbos-sdk-ruby/pull/159))

### Removed

- Support for Ruby 3.0 ([#158](https://github.com/cerbos/cerbos-sdk-ruby/pull/158))
Expand Down Expand Up @@ -75,7 +77,7 @@

### Changed

- Increased `grpc` version requirement to 1.46+ to avoid [installing a native gem compiled for `x86_64-darwin` on `arm64-darwin`](https://github.com/grpc/grpc/issues/29100) ([#8](https://github.com/cerbos/cerbos-sdk-ruby/pull/8))
- Increased [`grpc`] version requirement to 1.46+ to avoid [installing a native gem compiled for `x86_64-darwin` on `arm64-darwin`](https://github.com/grpc/grpc/issues/29100) ([#8](https://github.com/cerbos/cerbos-sdk-ruby/pull/8))

## [0.1.0] - 2022-05-12

Expand All @@ -93,3 +95,5 @@
[0.3.0]: https://github.com/cerbos/cerbos-sdk-ruby/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/cerbos/cerbos-sdk-ruby/compare/v0.1.0...v0.2.0
[0.1.0]: https://github.com/cerbos/cerbos-sdk-ruby/compare/4481009e9dec2e1e6a2df8ea2f828690ceabbefc...v0.1.0
[`google-protobuf`]: https://rubygems.org/gems/google-protobuf
[`grpc`]: https://rubygems.org/gems/grpc
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require "json"

source "https://rubygems.org"

gemspec
Expand All @@ -15,3 +17,7 @@ gem "rubocop-rspec"
gem "standard"
gem "webrick"
gem "yard"

dependency_name = ENV.fetch("TEST_MATRIX_DEPENDENCY_NAME", "")
dependency_version = ENV.fetch("TEST_MATRIX_DEPENDENCY_VERSION", "")
gem dependency_name, "~> #{dependency_version}.0" unless dependency_name.empty? || dependency_version.empty?
1 change: 1 addition & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ PATH
remote: .
specs:
cerbos (0.8.0)
google-protobuf (>= 3.21.12, < 4.0)
grpc (~> 1.46)

GEM
Expand Down
51 changes: 43 additions & 8 deletions bin/test-matrix
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,34 @@
require "json"
require "net/http"

# We support non-end-of-life Ruby versions: https://www.ruby-lang.org/en/downloads/branches/
ruby_versions = ["3.1", "3.2", "3.3"]
class Versions
attr_reader :all, :oldest, :latest

def initialize(all)
@all = all
@oldest = all.first
@latest = all.last
end

latest_ruby_version = ruby_versions.last
def all_except_latest
all - [latest]
end
end

def resolve_dependency_versions(dependency)
tuples, _errors = Gem::SpecFetcher.fetcher.search_for_dependency(dependency)
Versions.new(tuples.map { |tuple, _source| tuple.version.segments.first(2).join(".") }.uniq)
end

def matrix_entries(vary, *latest, include_latest: false)
vary_versions = vary.all
vary_versions -= [vary.latest] unless include_latest

vary_versions.map { |version| {"title" => "#{vary.name} #{version}", vary.name.downcase => version}.merge(latest.map { |versions| [versions.name.downcase, versions.latest] }.to_h) }
end

# We support non-end-of-life Ruby versions: https://www.ruby-lang.org/en/downloads/branches/
ruby_versions = Versions.new(["3.1", "3.2", "3.3"])

minimum_cerbos_version = Gem::Version.new("0.16.0")
available_cerbos_versions = []
Expand All @@ -33,19 +57,30 @@ Net::HTTP.start "api.github.com", 443, use_ssl: true do |http|
end
end

*previous_cerbos_versions, latest_cerbos_version =
cerbos_versions = Versions.new(
available_cerbos_versions
.group_by { |version| version.segments[0..1] }
.map { |_, patch_versions| patch_versions.max }
.sort
)

cerbos_versions.all.push "#{cerbos_versions.latest.bump}.0-prerelease"

prerelease_cerbos_version = "#{latest_cerbos_version.bump}.0-prerelease"
dependencies_versions = Gem::Specification.load("cerbos.gemspec").dependencies.map { |dependency| [dependency.name, resolve_dependency_versions(dependency)] }.to_h

matrix = {
include: [
*previous_cerbos_versions.map { |previous_cerbos_version| {ruby: latest_ruby_version, cerbos: previous_cerbos_version} },
*ruby_versions.map { |ruby_version| {ruby: ruby_version, cerbos: latest_cerbos_version} },
{ruby: latest_ruby_version, cerbos: prerelease_cerbos_version}
*cerbos_versions.all.map { |cerbos_version|
{title: "Cerbos #{cerbos_version}", cerbos: cerbos_version, ruby: ruby_versions.latest}
},
*ruby_versions.all_except_latest.map { |ruby_version|
{title: "Ruby #{ruby_version}", cerbos: cerbos_versions.latest, ruby: ruby_version}
},
*dependencies_versions.flat_map { |dependency_name, dependency_versions|
dependency_versions.all_except_latest.map { |dependency_version|
{title: "#{dependency_name} #{dependency_version}", cerbos: cerbos_versions.latest, ruby: ruby_versions.oldest, dependency_name: dependency_name, dependency_version: dependency_version}
}
}
]
}

Expand Down
1 change: 1 addition & 0 deletions cerbos.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@ Gem::Specification.new do |spec|

spec.required_ruby_version = ">= 3.1.0"
spec.add_dependency "grpc", "~> 1.46"
spec.add_dependency "google-protobuf", [">= 3.21.12", "< 4.0"]
end

0 comments on commit 1bfb7c7

Please sign in to comment.