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 authored and etagwerker committed Sep 27, 2024
1 parent 0e0a8c0 commit 0d26c53
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 105 deletions.
67 changes: 0 additions & 67 deletions app/services/check_out_worker_repo.rb

This file was deleted.

56 changes: 18 additions & 38 deletions app/services/compats/check.rb
Original file line number Diff line number Diff line change
Expand Up @@ -171,44 +171,24 @@ def check_dependency_supersets
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"

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
dependencies = @compat
.dependencies
.dup
.transform_values {
_1.split(/\s*,\s*/)
}.then {
_1["rails"] ||= []
_1["rails"] << "#{@compat.rails_release.version.approximate_recommendation}.0"
}

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 @@ def delete_branch(name)
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 0d26c53

Please sign in to comment.