Increase release tag implementation

This commit is contained in:
Wedge 2016-03-08 05:40:23 +03:00
parent 0dae93bbe5
commit d34308d749
7 changed files with 52 additions and 24 deletions

View File

@ -100,6 +100,7 @@ source 'http://rails-assets.org' do
end end
gem 'rack-utf8_sanitizer' gem 'rack-utf8_sanitizer'
gem 'redis-semaphore'
#github api #github api
gem 'github_api' gem 'github_api'

View File

@ -452,6 +452,8 @@ GEM
redis-actionpack (~> 4) redis-actionpack (~> 4)
redis-activesupport (~> 4) redis-activesupport (~> 4)
redis-store (~> 1.1.0) redis-store (~> 1.1.0)
redis-semaphore (0.3.0)
redis
redis-store (1.1.4) redis-store (1.1.4)
redis (>= 2.2) redis (>= 2.2)
ref (1.0.5) ref (1.0.5)
@ -741,6 +743,7 @@ DEPENDENCIES
rdiscount rdiscount
redcarpet (~> 3.3) redcarpet (~> 3.3)
redis-rails redis-rails
redis-semaphore
resque resque
resque-scheduler (~> 2.5.4) resque-scheduler (~> 2.5.4)
resque-status resque-status
@ -777,4 +780,4 @@ DEPENDENCIES
zeroclipboard-rails zeroclipboard-rails
BUNDLED WITH BUNDLED WITH
1.10.6 1.11.2

View File

@ -62,7 +62,7 @@ class Api::V1::JobsController < Api::V1::BaseController
name = params[:name] name = params[:name]
if name =~ /abfworker::rpm-worker/ if name =~ /abfworker::rpm-worker/
if current_user.system? || current_user.id == BuildList.where(id: name.gsub(/[^\d]/, '')).first.try(:builder_id) if current_user.system? || current_user.id == BuildList.where(id: name.gsub(/[^\d]/, '')).first.try(:builder_id)
res = BuildList.log_server.setex name, 15, params[:logs] BuildList.log_server.setex name, 15, params[:logs]
end end
end end
render nothing: true render nothing: true

View File

@ -57,7 +57,6 @@ class Platforms::ProductBuildListsController < Platforms::BaseController
flash[:notice] = t('flash.product.build_started') flash[:notice] = t('flash.product.build_started')
redirect_to [@platform, @product] redirect_to [@platform, @product]
else else
puts pbl.errors.messages
flash[:error] = t('flash.product.build_error') flash[:error] = t('flash.product.build_error')
@product_build_list = pbl @product_build_list = pbl
render action: :new render action: :new

View File

@ -86,6 +86,19 @@ class MassBuild < ActiveRecord::Base
return unless start return unless start
# later with resque # later with resque
arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all arches_list = arch_names ? Arch.where(name: arch_names.split(', ')) : Arch.all
project_version =
if save_to_platform.name != build_for_platform.name
save_to_platform.default_branch
else
build_for_platform.default_branch
end
increase_rt = increase_release_tag?
if increase_rt
inc_rt_sem = Redis::Semaphore.new(:increase_release_tag_lock)
inc_rt_sem.lock
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
end
projects_list.lines.each do |name| projects_list.lines.each do |name|
next if name.blank? next if name.blank?
@ -96,13 +109,25 @@ class MassBuild < ActiveRecord::Base
return if self.reload.stop_build return if self.reload.stop_build
# Ensures that user has rights to create a build_list # Ensures that user has rights to create a build_list
next unless ProjectPolicy.new(user, project).write? next unless ProjectPolicy.new(user, project).write?
increase_rt = increase_release_tag?
arches_list.each do |arch| arches_list.each do |arch|
rep_id = (project.repository_ids & save_to_platform.repository_ids).first rep_id = (project.repository_ids & save_to_platform.repository_ids).first
project.build_for(self, rep_id, arch, 0, increase_rt) if increase_rt
increase_rt = false if ratelimit_remaining <= 1
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
#if that's still less that or equal 1
if ratelimit_remaining <= 1
#just to make sure it really resets wait additional 5 seconds
ratelimit_reset_wait = Github_blobs_api.ratelimit_reset - Time.now.to_i + 5
sleep ratelimit_reset_wait
ratelimit_remaining = Github_blobs_api.ratelimit_remaining
end
end
count = project.increase_release_tag(project_version, "MassBuild##{id}: Increase release tag")
ratelimit_remaining -= count
end
project.build_for(self, rep_id, project_version, arch, 0)
end end
rescue RuntimeError, Exception rescue RuntimeError, Exception => e
end end
else else
MassBuild.increment_counter :missed_projects_count, id MassBuild.increment_counter :missed_projects_count, id
@ -111,6 +136,9 @@ class MassBuild < ActiveRecord::Base
end end
end end
done done
if increase_rt
inc_rt_sem.unlock
end
end end
later :build_all, queue: :low later :build_all, queue: :low

View File

@ -1,3 +1,5 @@
require 'base64'
class Project < ActiveRecord::Base class Project < ActiveRecord::Base
has_ancestry orphan_strategy: :adopt # we replace a 'path' method in the Git module has_ancestry orphan_strategy: :adopt # we replace a 'path' method in the Git module
@ -122,7 +124,7 @@ class Project < ActiveRecord::Base
"git://github.com/" + github_get_organization + "/" + name + ".git" "git://github.com/" + github_get_organization + "/" + name + ".git"
end end
def build_for(mass_build, repository_id, arch = Arch.find_by(name: 'i586'), priority = 0, increase_rt = false) def build_for(mass_build, repository_id, project_version, arch = Arch.find_by(name: 'i586'), priority = 0)
build_for_platform = mass_build.build_for_platform build_for_platform = mass_build.build_for_platform
save_to_platform = mass_build.save_to_platform save_to_platform = mass_build.save_to_platform
user = mass_build.user user = mass_build.user
@ -132,10 +134,6 @@ class Project < ActiveRecord::Base
main_rep_id = build_for_platform.repositories.main.first.try(:id) main_rep_id = build_for_platform.repositories.main.first.try(:id)
include_repos = ([main_rep_id] << (save_to_platform.main? ? repository_id : nil)).compact.uniq include_repos = ([main_rep_id] << (save_to_platform.main? ? repository_id : nil)).compact.uniq
project_version = project_version_for save_to_platform, build_for_platform
increase_release_tag(project_version, user, "MassBuild##{mass_build.id}: Increase release tag") if increase_rt
build_list = build_lists.build do |bl| build_list = build_lists.build do |bl|
bl.save_to_platform = save_to_platform bl.save_to_platform = save_to_platform
bl.build_for_platform = build_for_platform bl.build_for_platform = build_for_platform
@ -233,18 +231,14 @@ class Project < ActiveRecord::Base
end end
end end
def increase_release_tag(project_version, user, message) def increase_release_tag(project_version, message)
blob, raw = find_blob_and_raw_of_spec_file(project_version) file = Github_blobs_api.get github_get_organization, name, '/' + name + '.spec', ref: project_version rescue return 1
return unless blob decoded_content = Base64.decode64(file.content)
new_content = Project.replace_release_tag decoded_content
content = self.class.replace_release_tag raw.content return 1 if new_content == decoded_content
return if content == raw.content Github_blobs_api.update github_get_organization, name, '/' + name + '.spec', path: '/' + name + '.spec',\
message: message, content: new_content, sha: file.sha rescue return 2
update_file(blob.name, content.gsub("\r", ''), return 2
message: message,
actor: user,
head: project_version
)
end end
protected protected

View File

@ -7,3 +7,6 @@ Github.configure do |c|
builder.use Faraday::HttpCache, store: Rails.cache builder.use Faraday::HttpCache, store: Rails.cache
end end
end end
#for updating repo contents
Github_blobs_api = Github::Client::Repos::Contents.new basic_auth: ENV['GITHUB_REPO_BOT_LOGIN'] + ":" + ENV['GITHUB_REPO_BOT_PASSWORD']