-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #84 from railsbump/trigger-github-checks-via-api
Trigger Github checks via Github API instead of commits + Refactor checks
- Loading branch information
Showing
10 changed files
with
267 additions
and
178 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,8 @@ | |
|
||
.rspec | ||
|
||
.vscode | ||
|
||
config/database.yml | ||
|
||
coverage | ||
|
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module Compats::Checks | ||
class Base | ||
def initialize(compat) | ||
@compat = compat | ||
end | ||
|
||
def call | ||
raise NotImplementedError | ||
end | ||
|
||
def check! | ||
raise NotImplementedError | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
module Compats::Checks | ||
|
||
# This method checks a compat by dispatching the check_bundler workflow. | ||
class BundlerGithubCheck < Base | ||
# Define the repository, workflow file, and branch | ||
GITHUB_REPO = 'railsbump/checker' | ||
GITHUB_WORKFLOW = 'check_bundler.yml' | ||
GITHUB_REF = 'main' | ||
|
||
def call | ||
return unless @compat.pending? && Rails.env.production? | ||
|
||
check! | ||
end | ||
|
||
def check! | ||
# Initialize the Octokit client with your GitHub token | ||
client = Octokit::Client.new(access_token: ENV['GITHUB_ACCESS_TOKEN']) | ||
|
||
# Trigger the workflow dispatch event | ||
client.workflow_dispatch(GITHUB_REPO, GITHUB_WORKFLOW, GITHUB_REF, inputs: inputs) | ||
end | ||
|
||
private | ||
|
||
# Define the inputs for the workflow | ||
def inputs | ||
{ | ||
rails_version: @compat.rails_release.version.to_s, | ||
ruby_version: @compat.rails_release.minimum_ruby_version.to_s, | ||
bundler_version: @compat.rails_release.minimum_bundler_version.to_s, | ||
dependencies: JSON::dump(@compat.dependencies), | ||
compat_id: @compat.id.to_s | ||
} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
module Compats::Checks | ||
|
||
# This method checks if any other compats exist, that are marked as incompatible | ||
# and have a subset of the compat's dependencies. | ||
# | ||
# If so, the compat must be incompatible and is marked as such. | ||
class DependencySubsetsCheck < Base | ||
def call | ||
return unless @compat.pending? && (2..10).cover?(@compat.dependencies.size) | ||
|
||
check! | ||
end | ||
|
||
def check! | ||
subsets = (1..@compat.dependencies.size - 1).flat_map do |count| | ||
@compat.dependencies.keys.combination(count).map { @compat.dependencies.slice *_1 } | ||
end | ||
|
||
subsets.in_groups_of(100, false).each do |group| | ||
if @compat.rails_release.compats.where("dependencies::jsonb = ?", group.to_json).incompatible.any? | ||
@compat.status = :incompatible | ||
@compat.status_determined_by = "dependency_subsets" | ||
@compat.checked! | ||
return | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Compats::Checks | ||
|
||
# This method checks for the simplest case: if the compat has no dependencies, | ||
# it's marked as compatible. | ||
class EmptyDependenciesCheck < Base | ||
def call | ||
return unless @compat.pending? | ||
|
||
check! | ||
end | ||
|
||
def check! | ||
if @compat.dependencies.blank? | ||
@compat.status = :compatible | ||
@compat.status_determined_by = "empty_dependencies" | ||
@compat.checked! | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
module Compats::Checks | ||
|
||
# This method checks if the dependencies include any Rail gems, and if so, | ||
# if any of them have a different version than the compat's Rails version. | ||
# | ||
# If that's the case, the compat is marked as incompatible. | ||
class RailsGemsCheck < Base | ||
RAILS_GEMS = %w( | ||
actioncable | ||
actionmailbox | ||
actionmailer | ||
actionpack | ||
actiontext | ||
actionview | ||
activejob | ||
activemodel | ||
activerecord | ||
activestorage | ||
activesupport | ||
rails | ||
railties | ||
) | ||
|
||
def call | ||
return unless @compat.pending? | ||
|
||
check! | ||
end | ||
|
||
def check! | ||
@compat.dependencies.each do |gem_name, requirement| | ||
next unless RAILS_GEMS.include?(gem_name) | ||
requirement_unmet = requirement.split(/\s*,\s*/).any? do |r| | ||
!Gem::Requirement.new(r).satisfied_by?(@compat.rails_release.version) | ||
end | ||
if requirement_unmet | ||
@compat.status = :incompatible | ||
@compat.status_determined_by = "rails_gems" | ||
@compat.checked! | ||
return | ||
end | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.