Commit 35dd2e12 authored by Kamil Trzcinski's avatar Kamil Trzcinski Committed by James Edwards-Jones

Fix tests

parent d28f1a7f
...@@ -14,23 +14,26 @@ class PagesWorker ...@@ -14,23 +14,26 @@ class PagesWorker
# Create status notifying the deployment of pages # Create status notifying the deployment of pages
@status = create_status @status = create_status
@status.run! @status.run!
raise 'pages are outdated' unless latest? raise 'pages are outdated' unless latest?
# Create temporary directory in which we will extract the artifacts # Create temporary directory in which we will extract the artifacts
FileUtils.mkdir_p(tmp_path)
Dir.mktmpdir(nil, tmp_path) do |archive_path| Dir.mktmpdir(nil, tmp_path) do |archive_path|
results = extract_archive(archive_path) extract_archive!(archive_path)
raise 'pages failed to extract' unless results.all?(&:success?)
# Check if we did extract public directory # Check if we did extract public directory
archive_public_path = File.join(archive_path, 'public') archive_public_path = File.join(archive_path, 'public')
raise 'pages miss the public folder' unless Dir.exists?(archive_public_path) raise 'pages miss the public folder' unless Dir.exists?(archive_public_path)
raise 'pages are outdated' unless latest? raise 'pages are outdated' unless latest?
deploy_page!(archive_public_path) deploy_page!(archive_public_path)
@status.success @status.success
end end
rescue => e rescue => e
fail(e.message, !latest?) fail(e.message, !latest?)
return false
end end
private private
...@@ -46,12 +49,12 @@ class PagesWorker ...@@ -46,12 +49,12 @@ class PagesWorker
) )
end end
def extract_archive(temp_path) def extract_archive!(temp_path)
results = Open3.pipeline(%W(gunzip -c #{artifacts}), results = Open3.pipeline(%W(gunzip -c #{artifacts}),
%W(dd bs=#{BLOCK_SIZE} count=#{blocks}), %W(dd bs=#{BLOCK_SIZE} count=#{blocks}),
%W(tar -x -C #{temp_path} public/), %W(tar -x -C #{temp_path} public/),
err: '/dev/null') err: '/dev/null')
results.compact raise 'pages failed to extract' unless results.compact.all?(&:success?)
end end
def deploy_page!(archive_public_path) def deploy_page!(archive_public_path)
...@@ -61,7 +64,10 @@ class PagesWorker ...@@ -61,7 +64,10 @@ class PagesWorker
# 2. We move temporary public to be deployed public # 2. We move temporary public to be deployed public
# 3. We remove previous public path # 3. We remove previous public path
FileUtils.mkdir_p(pages_path) FileUtils.mkdir_p(pages_path)
FileUtils.move(public_path, previous_public_path, force: true) begin
FileUtils.move(public_path, previous_public_path)
rescue
end
FileUtils.move(archive_public_path, public_path) FileUtils.move(archive_public_path, public_path)
ensure ensure
FileUtils.rm_r(previous_public_path, force: true) FileUtils.rm_r(previous_public_path, force: true)
......
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