From a660b1aab5cf4394ba953ef7144698dec84e881d Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 18:38:04 +0200 Subject: [PATCH 1/9] Regenerate Appraisals, drop Rails 7.0 --- .github/workflows/test.yml | 7 ++----- Appraisals | 8 ++++---- gemfiles/{rails_7_0.gemfile => rails_8_0.gemfile} | 2 +- gemfiles/rails_head.gemfile | 9 --------- 4 files changed, 7 insertions(+), 19 deletions(-) rename gemfiles/{rails_7_0.gemfile => rails_8_0.gemfile} (83%) delete mode 100644 gemfiles/rails_head.gemfile diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index d4373cc..791f72d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -13,11 +13,8 @@ jobs: strategy: fail-fast: false matrix: - ruby: ["3.0", "3.1", "3.2", "3.3"] - gemfile: ["rails_7_0", "rails_7_2"] - exclude: - - ruby: "3.0" - gemfile: "rails_7_2" + ruby: ["3.2.2"] + gemfile: ["rails_7_2", "rails_8_0"] experimental: [false] steps: diff --git a/Appraisals b/Appraisals index e392ade..544f98e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,7 @@ -appraise "rails-7-0" do - gem "rails", "~> 7.0.0" -end - appraise "rails-7-2" do gem "rails", "~> 7.2.0" end + +appraise "rails-8-0" do + gem "rails", "~> 8.0.2" +end \ No newline at end of file diff --git a/gemfiles/rails_7_0.gemfile b/gemfiles/rails_8_0.gemfile similarity index 83% rename from gemfiles/rails_7_0.gemfile rename to gemfiles/rails_8_0.gemfile index 186acc4..7d6e285 100644 --- a/gemfiles/rails_7_0.gemfile +++ b/gemfiles/rails_8_0.gemfile @@ -4,6 +4,6 @@ source "https://rubygems.org" gem "rake" gem "appraisal" -gem "rails", "~> 7.0.0" +gem "rails", "~> 8.0.2" gemspec path: "../" diff --git a/gemfiles/rails_head.gemfile b/gemfiles/rails_head.gemfile deleted file mode 100644 index 7903192..0000000 --- a/gemfiles/rails_head.gemfile +++ /dev/null @@ -1,9 +0,0 @@ -# This file was generated by Appraisal - -source "https://rubygems.org" - -gem "rake" -gem "appraisal" -gem "rails", github: "rails/rails", branch: "main" - -gemspec path: "../" From f0d607ac1275f66b4d03378f33507a79bf9617ab Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 18:55:35 +0200 Subject: [PATCH 2/9] Allow usage of google-protobuf 4.x so that binary gems can be easily installed for use with pbbuilder --- pbbuilder.gemspec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pbbuilder.gemspec b/pbbuilder.gemspec index 86ed91e..e834b42 100644 --- a/pbbuilder.gemspec +++ b/pbbuilder.gemspec @@ -14,7 +14,7 @@ Gem::Specification.new do |spec| spec.files = `git ls-files`.split("\n") spec.test_files = `git ls-files -- test/*`.split("\n") - spec.add_dependency "google-protobuf", "~> 3.25" + spec.add_dependency "google-protobuf", ">= 3.25", "< 5.0" spec.add_dependency "activesupport" spec.add_development_dependency 'm' spec.add_development_dependency "pry" From 4470c97dbed5c8d511b36e9cc3ae6e86affa552b Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 18:56:37 +0200 Subject: [PATCH 3/9] Use an actual .proto for testing The format of the descriptor output changes between google-protobuf 3.x and 4.x and defining it "neatly" inline is no longer possible, but that's not a big deal. --- test/test_helper.rb | 28 +++++++--------------------- test/test_proto.proto | 27 +++++++++++++++++++++++++++ test/test_proto_pb.rb | 18 ++++++++++++++++++ 3 files changed, 52 insertions(+), 21 deletions(-) create mode 100644 test/test_proto.proto create mode 100644 test/test_proto_pb.rb diff --git a/test/test_helper.rb b/test/test_helper.rb index 1de8539..f0cf6eb 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -21,28 +21,14 @@ ActiveSupport.test_order = :random -Google::Protobuf::DescriptorPool.generated_pool.build do - add_file("pbbuilder.proto", syntax: :proto3) do - add_message "pbbuildertest.Person" do - optional :name, :string, 1 - repeated :friends, :message, 2, "pbbuildertest.Person" - optional :best_friend, :message, 3, "pbbuildertest.Person" - repeated :nicknames, :string, 4 - optional :field_mask, :message, 5, "google.protobuf.FieldMask" - map :favourite_foods, :string, :string, 6 - repeated :tags, :string, 7 - optional :last_name, :string, 8 - optional :boolean_me, :bool, 9 - optional :logo, :message, 10, "pbbuildertest.Asset" - end - - add_message "pbbuildertest.Asset" do - optional :url, :string, 1 - optional :url_2x, :string, 2 - optional :url_3x, :string, 3 - end - end +# Regenerate Ruby descriptors from proto if needed, and require them. +# This does require protoc to be installed +proto_file = File.expand_path("test_proto.proto", __dir__) +ruby_out = File.expand_path("test_proto_pb.rb", __dir__) +if !File.exist?(ruby_out) || File.mtime(ruby_out) < File.mtime(proto_file) + system("protoc --proto_path=#{File.dirname(proto_file)} --ruby_out=#{File.dirname(ruby_out)} #{proto_file}") end +require_relative "test_proto_pb" module API Person = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("pbbuildertest.Person").msgclass diff --git a/test/test_proto.proto b/test/test_proto.proto new file mode 100644 index 0000000..b34478b --- /dev/null +++ b/test/test_proto.proto @@ -0,0 +1,27 @@ +// This is the source proto file from which Ruby proto descriptors are generated. +// See test/test_helper.rb for the generation process. + +syntax = "proto3"; + +package pbbuildertest; + +import "google/protobuf/field_mask.proto"; + +message Person { + string name = 1; + repeated Person friends = 2; + Person best_friend = 3; + repeated string nicknames = 4; + google.protobuf.FieldMask field_mask = 5; + map favourite_foods = 6; + repeated string tags = 7; + string last_name = 8; + bool boolean_me = 9; + Asset logo = 10; +} + +message Asset { + string url = 1; + string url_2x = 2; + string url_3x = 3; +} \ No newline at end of file diff --git a/test/test_proto_pb.rb b/test/test_proto_pb.rb new file mode 100644 index 0000000..79ffe37 --- /dev/null +++ b/test/test_proto_pb.rb @@ -0,0 +1,18 @@ +# frozen_string_literal: true +# Generated by the protocol buffer compiler. DO NOT EDIT! +# source: test_proto.proto + +require 'google/protobuf' + +require 'google/protobuf/field_mask_pb' + + +descriptor_data = "\n\x10test_proto.proto\x12\rpbbuildertest\x1a google/protobuf/field_mask.proto\"\x81\x03\n\x06Person\x12\x0c\n\x04name\x18\x01 \x01(\t\x12&\n\x07\x66riends\x18\x02 \x03(\x0b\x32\x15.pbbuildertest.Person\x12*\n\x0b\x62\x65st_friend\x18\x03 \x01(\x0b\x32\x15.pbbuildertest.Person\x12\x11\n\tnicknames\x18\x04 \x03(\t\x12.\n\nfield_mask\x18\x05 \x01(\x0b\x32\x1a.google.protobuf.FieldMask\x12\x42\n\x0f\x66\x61vourite_foods\x18\x06 \x03(\x0b\x32).pbbuildertest.Person.FavouriteFoodsEntry\x12\x0c\n\x04tags\x18\x07 \x03(\t\x12\x11\n\tlast_name\x18\x08 \x01(\t\x12\x12\n\nboolean_me\x18\t \x01(\x08\x12\"\n\x04logo\x18\n \x01(\x0b\x32\x14.pbbuildertest.Asset\x1a\x35\n\x13\x46\x61vouriteFoodsEntry\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\r\n\x05value\x18\x02 \x01(\t:\x02\x38\x01\"4\n\x05\x41sset\x12\x0b\n\x03url\x18\x01 \x01(\t\x12\x0e\n\x06url_2x\x18\x02 \x01(\t\x12\x0e\n\x06url_3x\x18\x03 \x01(\tb\x06proto3" + +pool = Google::Protobuf::DescriptorPool.generated_pool +pool.add_serialized_file(descriptor_data) + +module Pbbuildertest + Person = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("pbbuildertest.Person").msgclass + Asset = ::Google::Protobuf::DescriptorPool.generated_pool.lookup("pbbuildertest.Asset").msgclass +end From b13ad2ec99d1f0b4a885874d588ccf7a2f6d6797 Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:04:24 +0200 Subject: [PATCH 4/9] Test with both google-protobuf 3.25 and 4.x --- Appraisals | 2 ++ gemfiles/rails_7_2.gemfile | 1 + gemfiles/rails_8_0.gemfile | 1 + 3 files changed, 4 insertions(+) diff --git a/Appraisals b/Appraisals index 544f98e..777d68e 100644 --- a/Appraisals +++ b/Appraisals @@ -1,7 +1,9 @@ appraise "rails-7-2" do gem "rails", "~> 7.2.0" + gem "google-protobuf", "~> 3.25", "< 4.0" end appraise "rails-8-0" do gem "rails", "~> 8.0.2" + gem "google-protobuf", "~> 4.0", "< 5.0" end \ No newline at end of file diff --git a/gemfiles/rails_7_2.gemfile b/gemfiles/rails_7_2.gemfile index f7bac6c..ddee8df 100644 --- a/gemfiles/rails_7_2.gemfile +++ b/gemfiles/rails_7_2.gemfile @@ -5,5 +5,6 @@ source "https://rubygems.org" gem "rake" gem "appraisal" gem "rails", "~> 7.2.0" +gem "google-protobuf", "~> 3.25", "< 4.0" gemspec path: "../" diff --git a/gemfiles/rails_8_0.gemfile b/gemfiles/rails_8_0.gemfile index 7d6e285..8d70272 100644 --- a/gemfiles/rails_8_0.gemfile +++ b/gemfiles/rails_8_0.gemfile @@ -5,5 +5,6 @@ source "https://rubygems.org" gem "rake" gem "appraisal" gem "rails", "~> 8.0.2" +gem "google-protobuf", "~> 4.0", "< 5.0" gemspec path: "../" From 7db38cdef7c1cfb954e1126bcdb0d45c6631ca25 Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:05:19 +0200 Subject: [PATCH 5/9] Remove --verbose when running rake test because the only thing it prints are test names and timings - and not in a very compact form --- Rakefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Rakefile b/Rakefile index d57d9e0..0b93f98 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ else file_name = ARGV[1] test_name = ARGV[2]&.tr(" ", "_") - ENV["TESTOPTS"] = "--verbose" + ENV["TESTOPTS"] = "" t.test_files = if file_name if test_name From 3a6e401a44859347cbbf22082264990828e06ebb Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:10:10 +0200 Subject: [PATCH 6/9] Update and cleanup changelog --- CHANGELOG.md | 42 +++++++++++------------------------------- 1 file changed, 11 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b11503b..b6d551f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,72 +1,55 @@ -# Pbbuilder Changelog -All notable changes to this project will be documented in this file. - -This format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). - ## Unreleased -- Remove official support for Rails 6 versions. It still works, but we don't test against it anymore. + +- Remove official support for Rails 7.0 and Rails 6.x, add Appraisal config for Rails 8.x +- Bump actions/checkout from 3 to 4 (#40) +- Drop support for rails v6.* versions (#60) +- Regenerate Appraisals, drop Rails 7.0 +- Allow usage of google-protobuf 4.x +- Use an actual .proto for testing +- Test with both google-protobuf 3.25 and 4.x +- Remove --verbose when running rake test ## 0.19.0 -### Added -- Add support for rails 7.2, but leave out rails 7.1 support. This is because ActionView has a breaking bug in 7.1 that renders the template back as a string -instead of an object, like we need for Pbbuilder https://github.com/rails/rails/pull/51023 +- Add support for rails 7.2, but leave out rails 7.1 support. This is because ActionView has a breaking bug in 7.1 that renders the template back as a string instead of an object, like we need for Pbbuilder https://github.com/rails/rails/pull/51023 ## 0.18.0 -### Added - Allow literal assignment of protos to fields ## 0.17.0 -### Changed - Instead of appending to repeated enum message, we're replacing it to avoid issues in case output will be rendered twice - If one field was defined twice, only last definition will end up in output - -## Fixed - Fixed CI by locking 3 version or lower of google-protobuf dependency. ## 0.16.2 -### Added - Add support for partial as a first argument , e.g.`pb.friends "racers/racer", as: :racer, collection: @racers` - Add tests to verify that fragment caching is operational ## 0.16.1 -### Changed - Deal properly with recursive protobuf messages while using ActiveView::CollectionRenderer ## 0.16.0 -### Added - Added support for new collection rendering, that is backed by ActiveView::CollectionRenderer. - -### Changed - Refactoring and simplification of #merge! method without a change in functionality. ## 0.15.1 -### Fixed - #merge! method to handle repeated unintialized message object ## 0.15.0 -### Changed - #merge! method was refactored to accomodate caching for all data types (especially those that are :repeated) ## 0.14.0 -### Added - Adding `frozen_string_literal: true` to all files. ## 0.13.2 2023.02.3 -### Fixed - In case ActiveSupport::Cache::FileStore in Rails is used as a cache, File.atomic_write can have a race condition and fail to rename temporary file. We're attempting to recover from that, by catching this specific error and returning a value. ## 0.13.1 2023.01.24 -### Added - #merge! to support boolean values ## 0.13.0 2023.01.18 -### Added - #merge! method added for PbbuilderTemplate class - ActiveSupport added as a dependency for gem - Fragment Caching support added, with #cache! and #cache_if! methods in PbbuilderTemplate class. - - -### Changed - Appraisal is properly configured to run against all rubies and rails combinations. - Supported ruby version's are 2.7, 3.0, 3.1 - Superclass for pbbuilder is now active_support/proxy_object, with a fallback to active_support/basic_object. @@ -74,10 +57,7 @@ instead of an object, like we need for Pbbuilder https://github.com/rails/rails/ - `rails` from version 6.1.4.4 to 6.1.7, and from version 7.0.1 to 7.0.4 - `google-protobuf` is let loose - `bundler` from version 2.3.4 to 2.3.22 - -### Removed -- TestUnit dependency - +- TestUnit dependency removed ## 0.12.0 Prior to 2022-10-14 From c5ccaa9a54006cf6ca5862c52324cf1632a7d655 Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:11:14 +0200 Subject: [PATCH 7/9] Clean up the changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b6d551f..a4de34a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -40,13 +40,13 @@ ## 0.14.0 - Adding `frozen_string_literal: true` to all files. -## 0.13.2 2023.02.3 +## 0.13.2 - In case ActiveSupport::Cache::FileStore in Rails is used as a cache, File.atomic_write can have a race condition and fail to rename temporary file. We're attempting to recover from that, by catching this specific error and returning a value. -## 0.13.1 2023.01.24 +## 0.13.1 - #merge! to support boolean values -## 0.13.0 2023.01.18 +## 0.13.0 - #merge! method added for PbbuilderTemplate class - ActiveSupport added as a dependency for gem - Fragment Caching support added, with #cache! and #cache_if! methods in PbbuilderTemplate class. From 9329abaee48167a8ef7fcd316613c51299c0c9cd Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:15:33 +0200 Subject: [PATCH 8/9] Update gemspec and version --- pbbuilder.gemspec | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pbbuilder.gemspec b/pbbuilder.gemspec index e834b42..23aa028 100644 --- a/pbbuilder.gemspec +++ b/pbbuilder.gemspec @@ -2,20 +2,20 @@ Gem::Specification.new do |spec| spec.name = "pbbuilder" - spec.version = "0.19.0" - spec.authors = ["Bouke van der Bijl"] - spec.email = ["bouke@cheddar.me"] + spec.version = "0.20.0" + spec.authors = ["Bouke van der Bijl", "Julik Tarkhanov", "Stas Katkov", "Sebastian van Hesteren"] + spec.email = ["julik@cheddar.me"] spec.homepage = "https://github.com/cheddar-me/pbbuilder" - spec.summary = "Generate Protobuf Messages with a simple DSL similar to JBuilder" + spec.summary = "Generate Protobuf messages with a simple DSL similar to JBuilder" spec.license = "MIT" - spec.required_ruby_version = '>= 2.7' + spec.required_ruby_version = '>= 3.2' spec.files = `git ls-files`.split("\n") spec.test_files = `git ls-files -- test/*`.split("\n") spec.add_dependency "google-protobuf", ">= 3.25", "< 5.0" spec.add_dependency "activesupport" - spec.add_development_dependency 'm' + spec.add_development_dependency "m" spec.add_development_dependency "pry" end From 8f5267a3dd8c77c1a815cbb52ba21e92aeec351e Mon Sep 17 00:00:00 2001 From: Julik Tarkhanov Date: Wed, 18 Jun 2025 19:15:44 +0200 Subject: [PATCH 9/9] And update CHANGELOG once more --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a4de34a..8c469c7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,7 +10,7 @@ - Remove --verbose when running rake test ## 0.19.0 -- Add support for rails 7.2, but leave out rails 7.1 support. This is because ActionView has a breaking bug in 7.1 that renders the template back as a string instead of an object, like we need for Pbbuilder https://github.com/rails/rails/pull/51023 +- Add support for rails 7.2, but leave out rails 7.1 support. This is because ActionView has a breaking bug in 7.1 that renders the template back as a string instead of an object, like we need for Pbbuilder https://github.com/rails/rails/pull/51023 This also removes the uses of the Rails variant of BasicObject in favor of the Ruby built-in. ## 0.18.0 - Allow literal assignment of protos to fields