Commit 38a1378e authored by Tomasz Maczukin's avatar Tomasz Maczukin

Add incremental build trace update API

parent d7127890
......@@ -231,11 +231,23 @@ module Ci
end
def trace=(trace)
recreate_trace_dir
File.write(path_to_trace, trace)
end
def recreate_trace_dir
unless Dir.exists?(dir_to_trace)
FileUtils.mkdir_p(dir_to_trace)
end
end
private :recreate_trace_dir
File.write(path_to_trace, trace)
def append_trace(trace_part)
recreate_trace_dir
File.open(path_to_trace, 'a') do |f|
f.write(trace_part)
end
end
def dir_to_trace
......
......@@ -50,6 +50,15 @@ module Ci
end
end
patch ":id/trace.txt" do
authenticate_runner!
update_runner_last_contact
build = Ci::Build.where(runner_id: current_runner.id).running.find(params[:id])
forbidden!('Build has been erased!') if build.erased?
build.append_trace(params[:trace_part])
end
# Authorize artifacts uploading for build - Runners only
#
# Parameters:
......
......@@ -156,6 +156,28 @@ describe Ci::API::API do
end
end
describe 'PATCH /builds/:id/trace.txt' do
let(:build) { create(:ci_build, :trace, runner_id: runner.id) }
before do
build.run!
patch ci_api("/builds/#{build.id}/trace.txt"), trace_part: ' appended', token: runner.token
end
it 'should append trace part to the trace' do
expect(response.status).to eq 200
expect(build.reload.trace).to eq 'BUILD TRACE appended'
end
context 'when build has been erased' do
let(:build) { create(:ci_build, runner_id: runner.id, erased_at: Time.now) }
it 'should respond with forbidden' do
expect(response.status).to eq 403
end
end
end
context "Artifacts" do
let(:file_upload) { fixture_file_upload(Rails.root + 'spec/fixtures/banana_sample.gif', 'image/gif') }
let(:file_upload2) { fixture_file_upload(Rails.root + 'spec/fixtures/dk.png', 'image/gif') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment