-
Notifications
You must be signed in to change notification settings - Fork 50
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] Run tests for individual gems in GitHub Actions #569
Conversation
6d2872e
to
93be509
Compare
OK, I finally got this all working, but this situation is a little ridiculous for a single PR: There are a few main things that this PR does, and I'm going to try to split it into smaller PRs as best I can.
|
In the course of [trying to be able to run all of the tests for individual gems in CI](#569) I've discovered that we don't specify all of our dependencies fully. In the starter repo the problems don't appear because all of the things that we need end up being dependencies of something or other, but when we try to run tests for individual gems we'll get errors about unsatisfied dependencies. There are only a few gems where we needed to declare a missing dependency in the `.gemspec`. And those are the only thing in this PR that could have the chance to impact downsteam apps. All of the changes to `Gemfile` and `Gemfile.lock` in each gem won't impact gem consumers at all. They just come into play in local development and CI. The changes in each `Gemfile` ensure that when developing or testing these gems that they'll use their peer gems from inside the `core` repo insted of using whatever version happens to be latest.
In the course of [trying to be able to run all of the tests for individual gems in CI](#569) I've discovered that we don't specify all of our dependencies fully. In the starter repo the problems don't appear because all of the things that we need end up being dependencies of something or other, but when we try to run tests for individual gems we'll get errors about unsatisfied dependencies. There are only a few gems where we needed to declare a missing dependency in the `.gemspec`. And those are the only thing in this PR that could have the chance to impact downsteam apps. All of the changes to `Gemfile` and `Gemfile.lock` in each gem won't impact gem consumers at all. They just come into play in local development and CI. The changes in each `Gemfile` ensure that when developing or testing these gems that they'll use their peer gems from inside the `core` repo insted of using whatever version happens to be latest.
dc3ea6f
to
7c94fc5
Compare
7c94fc5
to
fbb3451
Compare
eb9ae05
to
926524d
Compare
@@ -0,0 +1,3 @@ | |||
class Api::V1::ApplicationController < ActionController::API | |||
include Api::Controllers::Base | |||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the next couple of files are just providing a default implementation of files that we ship in the starter repo. We can think of the files that we ship in the starter repo as being "ejected" versions of these files. I added these in the gem itself so that we don't have to supply these files in test/dummy
of every singe gem that ends up needing them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember this being really annoying because the tests complained about the files not being there. This seems like a good option!
I think it would be helpful to provide a comment in these files briefly explaining the situation so in the future someone on the Bullet Train team doesn't come across it and mistake it for a "duplicated" file in the starter repository.
7eb90ed
to
8eead89
Compare
@@ -1,6 +1,6 @@ | |||
class Webhooks::Incoming::BulletTrainWebhooksController < Webhooks::Incoming::WebhooksController | |||
def create | |||
Webhooks::Incoming::BulletTrainWebhook.create(data: JSON.parse(request.body.read)).process_async | |||
Webhooks::Incoming::BulletTrainWebhook.create(data: JSON.parse(request.raw_post)).process_async |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason request.body.read
is returning an empty string ''
which then causes JSON.parse
to throw an error. Using raw_post
seems to work. At least for tests...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a "default implementation" of something we ship with the starter repo. Putting it in this specific spot feels kinda wrong, but that's what I had to do to get tests to pass.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the next few files are just setting up the database for the test env of bullet_train-incoming_webhooks
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another "default implementation" that feels like it's not in quite the right place, but it had to be here for tests to work.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the next few files are just setting up the database for the test env of bullet_train-outgoing_webhooks
.
@@ -3,6 +3,9 @@ | |||
class Api::V1::Webhooks::Outgoing::EndpointsControllerTest < ActionDispatch::IntegrationTest | |||
setup do | |||
@controller = Api::V1::Webhooks::Outgoing::EndpointsController | |||
|
|||
@team = Team.first | |||
@endpoint = @team.webhooks_outgoing_endpoints.first |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Grabbing a couple of objects for reference later in the tests. Doing this since we can't (and shouldn't try to) rely on hard coded ids.
t.references :team | ||
t.string :url, null: false | ||
t.string :name, null: false | ||
t.integer :event_type_ids, array: true, default: [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sqlite3
doesn't seem to support array: true
in CI, so I just changed this gem to test against postgres which is what we target for deployment anyway.
|
||
5.times do |n| | ||
Webhooks::Outgoing::Endpoint.create! team_id: Team.first.id, name: "Generic name #{n}", url: "http://example.com/webhook-#{n}" | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moved these into the setup
method so that they're created within the transaction for running tests. When they were outside of the setup
method in the setup/active_record.rb
file the records created would stay in the DB between test runs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a missing binstub.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed this so that we use the default implementation from the core
gems.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added a default implementation of this file so that it doesn't need to be in test/dummy
for each gem. The next few files are also default implementations.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed a bunch of */test/dummy/app/controllers/application_controller.rb
*/test/dummy/app/models/application_record.rb
files so that gems will use the default implementation that we ship.
@@ -2,6 +2,7 @@ module Users::Base | |||
extend ActiveSupport::Concern | |||
|
|||
included do | |||
extend Devise::Models |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Explicitly including this so that things will work in tests when the rail ties don't do the thing.
@@ -24,7 +24,7 @@ def enable_bulk_invitations | |||
end | |||
|
|||
def incoming_webhooks_parent_class_name | |||
@@config&.incoming_webhooks_parent_class_name | |||
@@config&.incoming_webhooks_parent_class_name || "ApplicationRecord" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Need to supply a default value here or we get a failure like this:
Error:
Webhooks::Incoming::BulletTrainWebhooksControllerTest#test_should_get_incoming_webhook:
NoMethodError: undefined method `constantize' for nil:NilClass
/Users/jgreen/projects/bullet-train-co/bullet_train-core/bullet_train-incoming_webhooks/app/models/webhooks/incoming/bullet_train_webhook.rb:1:in `<top (required)>'
<internal:/Users/jgreen/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
<internal:/Users/jgreen/.asdf/installs/ruby/3.2.2/lib/ruby/3.2.0/rubygems/core_ext/kernel_require.rb>:37:in `require'
/Users/jgreen/.asdf/installs/ruby/3.2.2/lib/ruby/gems/3.2.0/gems/zeitwerk-2.6.12/lib/zeitwerk/kernel.rb:30:in `require'
/Users/jgreen/projects/bullet-train-co/bullet_train-core/bullet_train-incoming_webhooks/app/controllers/webhooks/incoming/bullet_train_webhooks_controller.rb:3:in `create'
This reverts commit 82123cb.
5dfbe87
to
672fa00
Compare
In #550 I realized that I was making the same changes over and over to each individual gem and that instead we should probably ship some base controller/models in the main
bullet_train
gem. So this is an attempt at doing that.