Skip to content

Commit

Permalink
Add upload_results command to upload junit results to server
Browse files Browse the repository at this point in the history
  • Loading branch information
steve21168 committed Dec 20, 2023
1 parent f46d67e commit 5dd06f8
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 2 deletions.
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ PATH
specs:
gridlock_ci (0.1.0)
faraday (~> 2.7)
faraday-multipart (~> 1.0)
faraday-retry (~> 2.2)
rspec-core (~> 3.12)
rspec_junit_formatter (~> 0.6)
Expand All @@ -16,12 +17,15 @@ GEM
faraday (2.7.10)
faraday-net_http (>= 2.0, < 3.1)
ruby2_keywords (>= 0.0.4)
faraday-multipart (1.0.4)
multipart-post (~> 2)
faraday-net_http (3.0.2)
faraday-retry (2.2.0)
faraday (~> 2.0)
json (2.6.3)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
multipart-post (2.3.0)
nokogiri (1.15.3-x86_64-darwin)
racc (~> 1.4)
parallel (1.23.0)
Expand Down
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,11 @@ Example: `--rspec '--tag=foo --format progress'`
## Junit output

Junit output is supported via flag: `--junit-output FilePath`. Do not use the RSpec formatter for the reasons explained above.

## Upload results

Results can be uploaded to the server for analysis

```sh
bundle exec gridlock_ci run --run_id 1 --run_attempt 1 --file_path FilePath
```
28 changes: 27 additions & 1 deletion exe/gridlock_ci
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,32 @@ def enqueue_command
options
end

def upload_results_command
options = {}

OptionParser.new do |opts|
opts.banner = 'Usage: gridlock_ci upload_results [flags]'

opts.on('--run_id RUN_ID', 'Run ID to associate with [required]') do |o|
options[:run_id] = o
end

opts.on('--run_attempt RUN_ATTEMPT', 'Run attempt number [required]') do |o|
options[:run_attempt] = o
end

opts.on('--file_path FILE_PATH', 'Path to results file [required]') do |o|
options[:file_path] = o
end
end.parse!

options
end

global = OptionParser.new do |opts|
opts.banner = 'Usage: gridlock_ci [command] [options]'
opts.separator ''
opts.separator "Commands:\n run\n enqueue"
opts.separator "Commands:\n run\n enqueue\n upload_results"
end

global.order!
Expand All @@ -80,6 +102,10 @@ when 'enqueue'
end

GridlockCi::Client.new(opts[:run_id], opts[:run_attempt]).send_specs(specs)
when 'upload_results'
opts = upload_results_command

GridlockCi::Client.new(opts[:run_id], opts[:run_attempt]).upload_results(opts[:file_path])
else
puts 'Command not found'
exit 1
Expand Down
1 change: 1 addition & 0 deletions gridlock_ci.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |spec|

# Uncomment to register a new dependency of your gem
spec.add_dependency 'faraday', '~> 2.7'
spec.add_dependency 'faraday-multipart', '~> 1.0'
spec.add_dependency 'faraday-retry', '~> 2.2'
spec.add_dependency 'rspec-core', '~> 3.12'
spec.add_dependency 'rspec_junit_formatter', '~> 0.6'
Expand Down
1 change: 1 addition & 0 deletions lib/gridlock_ci.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
require 'json'
require 'faraday'
require 'faraday/retry'
require 'faraday/multipart'

require_relative 'gridlock_ci/version'
require_relative 'gridlock_ci/client'
Expand Down
17 changes: 16 additions & 1 deletion lib/gridlock_ci/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def previous_run_completed?
previous_run_key = "#{run_id}_#{run_attempt - 1}"
results = conn.get("/spec_list/#{previous_run_key}").body['specs']

return true if results.empty?
true if results.empty?
end

def next_spec
Expand All @@ -27,6 +27,13 @@ def send_specs(spec_list)
raise result['status'] if result['status'] != 'success'
end

def upload_results(file_path)
file = Faraday::Multipart::FilePart.new(file_path, 'text/xml')
payload = { file: file }

multipart_conn.post("/spec_results/#{run_key}", payload)
end

private

def run_key
Expand All @@ -49,6 +56,14 @@ def conn
end
end

def multipart_conn
Faraday.new(url: gridlock_ci_endpoint, request: { timeout: 15 }) do |f|
a.request :multipart
f.response :json
f.response :raise_error
end
end

def gridlock_ci_endpoint
ENV.fetch('GRIDLOCK_CI_SERVER_ENDPOINT', 'http://localhost:4568')
end
Expand Down

0 comments on commit 5dd06f8

Please sign in to comment.