Skip to content

Commit

Permalink
trigger github checks via github api instead of commits
Browse files Browse the repository at this point in the history
  • Loading branch information
manuelmeurer committed Sep 16, 2024
1 parent b765851 commit e97542b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 104 deletions.
67 changes: 0 additions & 67 deletions app/services/check_out_worker_repo.rb

This file was deleted.

54 changes: 17 additions & 37 deletions app/services/compats/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,44 +161,24 @@ def check_with_bundler_locally
def check_with_bundler_github
return unless @compat.pending? && Rails.env.production?

branch = @compat.id.to_s

# Delete branch if it exists
External::Github.delete_branch(branch)

CheckOutWorkerRepo.call do |git|
git.branch(branch).checkout

action_file = File.join(git.dir.path, ".github", "workflows", "check.yml")
action_content = File.read(action_file)
.gsub("RUBY_VERSION", @compat.rails_release.compatible_ruby_version.to_s)
.gsub("BUNDLER_VERSION", @compat.rails_release.compatible_bundler_version.to_s)
File.write action_file, action_content

dependencies = @compat.dependencies.dup
dependencies.transform_values! do |contraints|
contraints.split(/\s*,\s*/)
end
dependencies["rails"] ||= []
dependencies["rails"] << "#{@compat.rails_release.version.approximate_recommendation}.0"
dependencies = @compat
.dependencies
.dup
.transform_values {
_1.split(/\s*,\s*/)
}.then {
_1["rails"] ||= []
_1["rails"] << "#{@compat.rails_release.version.approximate_recommendation}.0"
}

gemfile = File.join(git.dir.path, "Gemfile")
gemfile_content = dependencies
.map do |gem, constraints_group|
"gem '#{gem}', #{constraints_group.map { "'#{_1}'" }.join(", ")}"
end
.unshift("source 'https://rubygems.org'")
.join("\n")
File.write gemfile, gemfile_content

git.add [action_file, gemfile]
git.commit @compat.to_s
Octopoller.poll retries: 5 do
git.push "origin", branch
rescue Git::GitExecuteError
:re_poll
end
end
External::Github.dispatch_workflow \
"railsbump/checker",
"check.yml",
:main,
compat_id: @compat.id.to_s,
ruby_version: @compat.rails_release.compatible_ruby_version.to_s,
bundler_version: @compat.rails_release.compatible_bundler_version.to_s,
dependencies: dependencies.to_json
end
end
end
6 changes: 6 additions & 0 deletions app/services/external/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ class Github < Baseline::ExternalService
false
end

add_method :dispatch_workflow do |repo, id, ref, **inputs|
client.workflow_dispatch \
repo, id, ref,
inputs: inputs
end

private

def client
Expand Down

0 comments on commit e97542b

Please sign in to comment.