Skip to content

Commit 0e3b15b

Browse files
author
Marko Bogdanović
authored
Merge pull request #257 from bmarkons/manual-run-releases
Run releases through admin UI
2 parents 4f3ee20 + 9c12b1f commit 0e3b15b

27 files changed

Lines changed: 384 additions & 234 deletions
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
$(document).on('turbolinks:load', function() {
2-
$('#manual_run_form').submit(function(event) {
2+
$('#commits_run_form').submit(function(event) {
33
$('#notice').remove();
4-
$('#wait_alert').removeClass('hidden');
4+
$('#wait_commits_alert').removeClass('hidden');
5+
});
6+
7+
$('#releases_run_form').submit(function(event) {
8+
$('#notice').remove();
9+
$('#wait_releases_alert').removeClass('hidden');
510
});
611
});
712

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
class Admin::DashboardController < AdminController
2+
def dashboard
3+
end
4+
end

app/controllers/admin/groups_controller.rb

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,4 @@
1-
class Admin::GroupsController < ApplicationController
2-
http_basic_authenticate_with(
3-
name: 'admin',
4-
password: Rails.application.secrets.admin_password
5-
) unless Rails.env.test?
6-
7-
layout 'admin'
8-
9-
before_action :set_repos, :set_admin
1+
class Admin::GroupsController < AdminController
102
before_action :set_group, only: [:show, :edit, :update, :destroy]
113

124
def index
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
class Admin::ReposController < AdminController
2+
before_action :set_repo
3+
4+
def show
5+
end
6+
7+
def run_commits
8+
ManualRunner.new(@repo).run_last(
9+
commits_count,
10+
pattern: pattern
11+
)
12+
13+
redirect_to admin_repo_path(@repo.name), notice: "#{@repo.name.capitalize} suite is running for last #{params[:count].to_i} commits."
14+
end
15+
16+
def run_releases
17+
unless versions.empty?
18+
ManualRunner.new(@repo).run_releases(
19+
versions,
20+
pattern: pattern
21+
)
22+
redirect_to admin_repo_path(@repo.name), notice: "#{@repo.name.capitalize} suite is running for selected versions."
23+
else
24+
redirect_to admin_repo_path(@repo.name), notice: 'You need to select release versions you want to run.'
25+
end
26+
end
27+
28+
private
29+
30+
def set_repo
31+
@repo = Repo.find_by(name: params[:repo_name])
32+
end
33+
34+
def versions
35+
params[:versions].split(',')
36+
end
37+
38+
def pattern
39+
params[:pattern] == 'all' ? '' : params[:pattern]
40+
end
41+
42+
def commits_count
43+
params[:count].to_i
44+
end
45+
end

app/controllers/admin_controller.rb

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,34 +7,14 @@ class AdminController < ApplicationController
77
layout 'admin'
88

99
before_action :set_repos, :set_admin
10-
before_action :set_repo, only: [:repo, :run]
10+
11+
private
1112

1213
def set_admin
1314
session['admin'] = true unless session['admin'] || Rails.env.test?
1415
end
1516

16-
def home
17-
end
18-
19-
def repo
20-
end
21-
22-
def run
23-
ManualRunner.new(@repo).run_last(
24-
params[:count].to_i,
25-
pattern: params[:pattern] == 'all' ? '' : params[:pattern]
26-
)
27-
28-
redirect_to admin_repo_path(@repo.name), notice: "#{@repo.name.capitalize} suite is running for last #{params[:count].to_i} commits."
29-
end
30-
31-
private
32-
3317
def set_repos
3418
@repos = Repo.all
3519
end
36-
37-
def set_repo
38-
@repo = Repo.find_by(name: params[:repo_name])
39-
end
4020
end

app/jobs/remote_server_job.rb

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,18 @@ class RemoteServerJob < ActiveJob::Base
55

66
SCRIPTS_PATH = './ruby-bench-docker/scripts'
77

8-
RUBY_TRUNK = "#{SCRIPTS_PATH}/ruby/trunk.sh"
8+
RUBY_COMMIT = "#{SCRIPTS_PATH}/ruby/trunk.sh"
99
RUBY_RELEASE = "#{SCRIPTS_PATH}/ruby/releases.sh"
1010

11-
RAILS_MASTER = "#{SCRIPTS_PATH}/rails/master.sh"
11+
RAILS_COMMIT = "#{SCRIPTS_PATH}/rails/master.sh"
1212
RAILS_RELEASE = "#{SCRIPTS_PATH}/rails/releases.sh"
1313

14-
SEQUEL_MASTER = "#{SCRIPTS_PATH}/sequel/master.sh"
14+
SEQUEL_COMMIT = "#{SCRIPTS_PATH}/sequel/master.sh"
1515
SEQUEL_RELEASE = "#{SCRIPTS_PATH}/sequel/releases.sh"
1616

1717
BUNDLER_RELEASE = "#{SCRIPTS_PATH}/bundler/releases.sh"
1818

19-
PG_MASTER = "#{SCRIPTS_PATH}/pg/master.sh"
19+
PG_COMMIT = "#{SCRIPTS_PATH}/pg/master.sh"
2020

2121
# Use keyword arguments once Rails 4.2.1 has been released.
2222
def perform(initiator_key, benchmark_group, options = {})
@@ -32,7 +32,7 @@ def perform(initiator_key, benchmark_group, options = {})
3232

3333
private
3434

35-
def ruby_trunk(ssh, commit_hash, options)
35+
def ruby_commit(ssh, commit_hash, options)
3636
ruby = true
3737
memory = true
3838
optcarrot = true
@@ -41,11 +41,11 @@ def ruby_trunk(ssh, commit_hash, options)
4141

4242
ssh_exec!(
4343
ssh,
44-
"#{RUBY_TRUNK} #{ruby} #{memory} #{optcarrot} #{liquid} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}"
44+
"#{RUBY_COMMIT} #{ruby} #{memory} #{optcarrot} #{liquid} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}"
4545
)
4646
end
4747

48-
def ruby_releases(ssh, version, options)
48+
def ruby_release(ssh, version, options)
4949
ruby = true
5050
memory = true
5151
optcarrot = true
@@ -58,7 +58,7 @@ def ruby_releases(ssh, version, options)
5858
)
5959
end
6060

61-
def ruby_releases_discourse(ssh, ruby_version, options)
61+
def ruby_release_discourse(ssh, ruby_version, options)
6262
execute_ssh_commands(ssh,
6363
[
6464
'docker pull rubybench/ruby_releases_discourse',
@@ -77,7 +77,7 @@ def ruby_releases_discourse(ssh, ruby_version, options)
7777
)
7878
end
7979

80-
def ruby_trunk_discourse(ssh, commit_hash, options)
80+
def ruby_commit_discourse(ssh, commit_hash, options)
8181
execute_ssh_commands(ssh,
8282
[
8383
'docker pull rubybench/ruby_trunk_discourse',
@@ -94,41 +94,41 @@ def ruby_trunk_discourse(ssh, commit_hash, options)
9494
)
9595
end
9696

97-
def rails_releases(ssh, version, options)
97+
def rails_release(ssh, version, options)
9898
prepared_statements = if version >= '4.2.5' then 1 else 0 end
9999
patterns = options[:include_patterns]
100100

101101
ssh_exec!(ssh, "#{RAILS_RELEASE} #{version} #{secrets.api_name} #{secrets.api_password} #{prepared_statements} #{patterns}")
102102
end
103103

104-
def rails_trunk(ssh, commit_hash, options)
104+
def rails_commit(ssh, commit_hash, options)
105105
patterns = options[:include_patterns]
106106

107-
ssh_exec!(ssh, "#{RAILS_MASTER} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
107+
ssh_exec!(ssh, "#{RAILS_COMMIT} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
108108
end
109109

110-
def sequel_releases(ssh, version, options)
110+
def sequel_release(ssh, version, options)
111111
patterns = options[:include_patterns]
112112

113113
ssh_exec!(ssh, "#{SEQUEL_RELEASE} #{version} #{secrets.api_name} #{secrets.api_password} #{patterns}")
114114
end
115115

116-
def sequel_trunk(ssh, commit_hash, options)
116+
def sequel_commit(ssh, commit_hash, options)
117117
patterns = options[:include_patterns]
118118

119-
ssh_exec!(ssh, "#{SEQUEL_MASTER} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
119+
ssh_exec!(ssh, "#{SEQUEL_COMMIT} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
120120
end
121121

122-
def bundler_releases(ssh, version, options)
122+
def bundler_release(ssh, version, options)
123123
patterns = options[:include_patterns]
124124

125125
ssh_exec!(ssh, "#{BUNDLER_RELEASE} #{version} #{secrets.api_name} #{secrets.api_password} #{patterns}")
126126
end
127127

128-
def pg_master(ssh, commit_hash, options)
128+
def pg_commit(ssh, commit_hash, options)
129129
patterns = options[:include_patterns]
130130

131-
ssh_exec!(ssh, "#{PG_MASTER} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
131+
ssh_exec!(ssh, "#{PG_COMMIT} #{commit_hash} #{secrets.api_name} #{secrets.api_password} #{patterns}")
132132
end
133133

134134
def execute_ssh_commands(ssh, commands)

app/services/benchmark_pool.rb

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,14 @@
11
module BenchmarkPool
2-
def self.enqueue(repo_name, commit_sha, options = {})
2+
def self.enqueue(initiator_type, initiator, repo_name, options = {})
33
case repo_name
44
when 'ruby'
5-
RemoteServerJob.perform_later(commit_sha, 'ruby_trunk', options)
6-
# RemoteServerJob.perform_later(commit_sha, 'ruby_trunk_discourse')
5+
RemoteServerJob.perform_later(initiator, "ruby_#{initiator_type}", options)
76
when 'rails'
8-
RemoteServerJob.perform_later(commit_sha, 'rails_trunk', options)
7+
RemoteServerJob.perform_later(initiator, "rails_#{initiator_type}", options)
98
when 'sequel'
10-
RemoteServerJob.perform_later(commit_sha, 'sequel_trunk', options)
9+
RemoteServerJob.perform_later(initiator, "sequel_#{initiator_type}", options)
1110
when 'ruby-pg'
12-
RemoteServerJob.perform_later(commit_sha, 'pg_master', options)
11+
RemoteServerJob.perform_later(initiator, "pg_#{initiator_type}", options)
1312
else
1413
raise ArgumentError, "unknown repo: #{repo_name}"
1514
end

app/services/commits_runner.rb

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,45 @@
1-
class CommitsRunner
2-
def self.run(commits, pattern = '')
3-
commits.select { |commit| valid?(commit) }
4-
.each { |commit| create_and_run(commit, pattern) }
5-
.count
1+
module CommitsRunner
2+
def self.run(trigger_source, commits, repo, pattern = '')
3+
formatted_commits =
4+
if trigger_source == :webhook
5+
format_webhook(commits, repo)
6+
elsif trigger_source == :api
7+
format_api(commits, repo)
8+
end
9+
10+
formatted_commits.select { |commit| valid?(commit) }
11+
.each { |commit| create_and_run(commit, pattern) }
12+
.count
613
end
714

815
private
916

17+
def self.format_api(commits, repo)
18+
commits.map do |commit|
19+
{
20+
sha: commit['sha'],
21+
message: commit['commit']['message'],
22+
repo: repo,
23+
url: commit['html_url'],
24+
created_at: commit['commit']['author']['date'],
25+
author_name: commit['commit']['author']['name']
26+
}
27+
end
28+
end
29+
30+
def self.format_webhook(commits, repo)
31+
commits.map do |commit|
32+
{
33+
sha: commit['id'],
34+
message: commit['message'],
35+
repo: repo,
36+
url: commit['url'],
37+
created_at: commit['timestamp'],
38+
author_name: commit['author']['name']
39+
}
40+
end
41+
end
42+
1043
def self.valid?(commit)
1144
!Commit.merge_or_skip_ci?(commit[:message]) && Commit.valid_author?(commit[:author_name])
1245
end
@@ -20,8 +53,9 @@ def self.create_and_run(commit, pattern)
2053
end
2154

2255
BenchmarkPool.enqueue(
23-
commit[:repo].name,
56+
:commit,
2457
commit[:sha],
58+
commit[:repo].name,
2559
include_patterns: pattern
2660
)
2761
end

app/services/github_event_handler.rb

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,14 @@ def branch_from_payload
2525
@payload['ref'].split('/')[2]
2626
end
2727

28-
# Grabs the commits hash and starts job to run benchmarks on remote server.
2928
def process_push
30-
repo = first_or_create_repo(@payload['repository'])
29+
repo = find_or_create_repo(@payload['repository'])
3130
commits = @payload['commits'] || [@payload['head_commit']]
3231

33-
commits.each do |commit|
34-
if create_commit(commit, repo.id)
35-
BenchmarkPool.enqueue(repo.name, commit['id'])
36-
end
37-
end
32+
CommitsRunner.run(:webhook, commits, repo)
3833
end
3934

40-
def first_or_create_repo(repository)
35+
def find_or_create_repo(repository)
4136
organization_name, repo_name = parse_full_name(repository['full_name'])
4237
repository_url = repository['html_url']
4338

@@ -65,19 +60,4 @@ def parse_full_name(full_name)
6560
full_name =~ /\A(\w+)\/(\w+)/
6661
[$1, $2]
6762
end
68-
69-
def create_commit(commit, repo_id)
70-
if valid_commit?(commit)
71-
Commit.find_or_create_by(sha1: commit['id']) do |c|
72-
c.url = commit['url']
73-
c.message = commit['message']
74-
c.repo_id = repo_id
75-
c.created_at = commit['timestamp']
76-
end
77-
end
78-
end
79-
80-
def valid_commit?(commit)
81-
!Commit.merge_or_skip_ci?(commit['message']) && Commit.valid_author?(commit['author']['name'])
82-
end
8363
end

app/services/manual_runner.rb

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ def initialize(repo)
77
@octokit = Octokit::Client.new(access_token: Rails.application.secrets.github_api_token)
88
end
99

10+
def run_releases(versions, pattern: '')
11+
ReleasesRunner.run(versions, @repo, pattern)
12+
end
13+
1014
def run_last(commits_count, pattern: '')
1115
if commits_count < 100
1216
run_commits(per_page: commits_count, pattern: pattern)
@@ -25,21 +29,7 @@ def run_paginated(commits_count, page: 1, pattern: '')
2529
end
2630

2731
def run_commits(page: 1, per_page: 100, pattern: '')
28-
fetched_commits = @octokit.commits("#{@repo.organization.name}/#{@repo.name}", per_page: per_page, page: page)
29-
formatted_commits = format_commits(fetched_commits)
30-
CommitsRunner.run(formatted_commits, pattern)
31-
end
32-
33-
def format_commits(commits)
34-
commits.map do |commit|
35-
{
36-
sha: commit['sha'],
37-
message: commit['commit']['message'],
38-
repo: @repo,
39-
url: commit['html_url'],
40-
created_at: commit['commit']['author']['date'],
41-
author_name: commit['commit']['author']['name']
42-
}
43-
end
32+
commits = @octokit.commits("#{@repo.organization.name}/#{@repo.name}", per_page: per_page, page: page)
33+
CommitsRunner.run(:api, commits, @repo, pattern)
4434
end
4535
end

0 commit comments

Comments
 (0)