From 5ee03aa0c34915aad23c850207577f76f910e8a4 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Fri, 5 Jan 2024 14:52:17 +0000 Subject: [PATCH 1/3] [CI] Adds branch option to docs report download --- rake_tasks/doc_generator.rake | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rake_tasks/doc_generator.rake b/rake_tasks/doc_generator.rake index 49a4e1937d..1c3850916c 100644 --- a/rake_tasks/doc_generator.rake +++ b/rake_tasks/doc_generator.rake @@ -46,7 +46,7 @@ namespace :docs do end desc 'Update report' - task :update do + task :update, [:branch] do |_, args| require 'elastic-transport' github_token = File.read(File.expand_path("~/.elastic/github.token")) transport_options = { @@ -60,9 +60,11 @@ namespace :docs do transport_options:transport_options ) path = '/repos/elastic/clients-flight-recorder/contents/recordings/docs/parsed-alternative-report.json' + path = "#{path}?ref=#{args[:branch]}" if args[:branch] params = {} response = client.perform_request('GET', path, params) File.write(File.expand_path('./docs/parsed_alternative_report.json', __dir__), response.body) + puts "Downloaded report for #{args[:branch] ? args[:branch] : 'main' } branch" end def json_data From 01730fb4791ddbb4e178eef59fd021cc71dff710 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Fri, 5 Jan 2024 16:04:21 +0000 Subject: [PATCH 2/3] [CI] Prepare log file for git comsumption --- rake_tasks/doc_generator.rake | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/rake_tasks/doc_generator.rake b/rake_tasks/doc_generator.rake index 1c3850916c..06aa1792e8 100644 --- a/rake_tasks/doc_generator.rake +++ b/rake_tasks/doc_generator.rake @@ -43,6 +43,7 @@ namespace :docs do generate_docs(entry) end puts "Finished generating #{entries.length} files in #{Time.now.to_i - start_time} seconds" + delete_first_log_line end desc 'Update report' @@ -123,7 +124,7 @@ namespace :docs do template.gsub(/\s+$/, '') end - def self.show_parameters(params) + def show_parameters(params) param_string = [] params.each do |k, v| value = (is_number?(v) || is_boolean?(v)) ? v : "'#{v}'" @@ -132,7 +133,7 @@ namespace :docs do param_string.join(",\n\s\s") end - def self.show_body(body) + def show_body(body) 'body: ' + JSON.pretty_generate(body) .gsub(/\"([a-z_]+)\":/,'\\1: ') # Use Ruby 2 hash syntax @@ -140,11 +141,11 @@ namespace :docs do .gsub('aggs', 'aggregations') # Replace 'aggs' with 'aggregations' for consistency end - def self.is_number?(value) + def is_number?(value) Float(value) || Integer(value) rescue false end - def self.is_boolean?(value) + def is_boolean?(value) (['false', 'true'].include? value) || value.is_a?(TrueClass) || value.is_a?(FalseClass) @@ -160,6 +161,13 @@ namespace :docs do SRC end end + + def delete_first_log_line + logfile = File.expand_path(__dir__ + '/../log/200-ok.log') + content = IO.readlines(logfile, chomp: true) + puts content.shift + File.write(logfile, content.first) + end end # From cc6b8dcc869e0bb2162fcf01e0cfe317fbbd37b8 Mon Sep 17 00:00:00 2001 From: Fernando Briano Date: Fri, 5 Jan 2024 16:07:12 +0000 Subject: [PATCH 3/3] [CI] Adds doc task to git add files from OK response --- rake_tasks/doc_generator.rake | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/rake_tasks/doc_generator.rake b/rake_tasks/doc_generator.rake index 06aa1792e8..5d26cdb8d1 100644 --- a/rake_tasks/doc_generator.rake +++ b/rake_tasks/doc_generator.rake @@ -68,6 +68,11 @@ namespace :docs do puts "Downloaded report for #{args[:branch] ? args[:branch] : 'main' } branch" end + desc 'Add files from 200-ok log' + task :add_files do + `cat log/200-ok.log | xargs git add` + end + def json_data JSON.parse(File.read(SRC_FILE)) end