Skip to content

Commit 7e94020

Browse files
committed
Updates to report logic to download the right branch for report
- Adds branch to download for elasticsearch-specification. - Adds getting the version for artifacts from the snapshots url. - Fixes `8.x` branches reporting on `main`.
1 parent 2edb9c7 commit 7e94020

File tree

3 files changed

+50
-15
lines changed

3 files changed

+50
-15
lines changed

.github/workflows/report.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,13 @@ jobs:
1616
- uses: ruby/setup-ruby@v1
1717
with:
1818
ruby-version: 3.3
19-
env:
20-
STACK_VERSION: 8.18.0-SNAPSHOT
2119
- name: Build
2220
run: |
2321
cd report && bundle install
2422
echo "REPORT_DATE=`date "+%Y-%m-%d|%H:%M:%S"`" >> $GITHUB_ENV
23+
env:
24+
STACK_VERSION: 8.17.1-SNAPSHOT
25+
BRANCH: ${{ matrix.branch }} # Branch for downloading the specs
2526
- name: Download Artifacts
2627
run: cd report && bundle exec rake download_all
2728
- name: Generate report

report/Rakefile

+1-8
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,7 @@ end
2828

2929
desc 'Download Elasticsearch Stack artifacts'
3030
task :download_json do
31-
version = ENV['STACK_VERSION'] || read_version_from_github
32-
Elastic::download_json_spec(version)
33-
end
34-
35-
def read_version_from_github
36-
yml = File.read(File.expand_path('../.github/workflows/report.yml', __dir__))
37-
regexp = /[0-9.]+(-SNAPSHOT)?/
38-
yml.split("\n").select { |l| l.match?('STACK_VERSION') }.first.strip.match(regexp)[0]
31+
Elastic::download_json_spec
3932
end
4033

4134
desc 'Download Elasticsearch Serverless artifacts'

report/download_artifacts.rb

+46-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,40 @@
2222
module Elastic
2323
CURRENT_PATH = Pathname(File.expand_path(__dir__))
2424
class << self
25-
def download_json_spec(version)
25+
#
26+
# Defines the version to download. Useful for different branches. It uses the BRANCH env
27+
# variable, STACK_VERSION env variable or reads the version from the report GitHub Actions yaml
28+
# file in that order.
29+
# When using branch, it will get the latest version for that branch from snapshots.elastic.co.
30+
# This is useful for the Elasticsearch JSON artifacts. For the elasticsearch-specification, we
31+
# download the branch.
32+
#
33+
def version
34+
if ENV['BRANCH']
35+
require 'open-uri'
36+
require 'yaml'
37+
38+
versions = URI.open("https://snapshots.elastic.co/latest/#{ENV['BRANCH']}.json").read
39+
YAML.safe_load(versions)['version']
40+
else
41+
ENV['STACK_VERSION'] || read_version_from_github
42+
end
43+
end
44+
45+
#
46+
# If there's no STACK_VERSION or BRANCH specified, this function will read the version to
47+
# download from the GitHub Actions yaml file which specifies STACK_VERSION.
48+
#
49+
def read_version_from_github
50+
yml = File.read(File.expand_path('../.github/workflows/report.yml', __dir__))
51+
regexp = /[0-9.]+(-SNAPSHOT)?/
52+
yml.split("\n").select { |l| l.match?('STACK_VERSION') }.first.strip.match(regexp)[0]
53+
end
54+
55+
#
56+
# Downloads the JSON spec from Elasticsearch.
57+
#
58+
def download_json_spec
2659
json_filename = CURRENT_PATH.join('tmp/artifacts.json')
2760

2861
# Create ./tmp if it doesn't exist
@@ -31,7 +64,6 @@ def download_json_spec(version)
3164
# Download json file with package information for version:
3265
json_url = "https://artifacts-api.elastic.co/v1/versions/#{version}"
3366
download_file!(json_url, json_filename)
34-
3567
# Parse the downloaded JSON
3668
begin
3769
artifacts = JSON.parse(File.read(json_filename))
@@ -62,16 +94,25 @@ def download_json_spec(version)
6294
File.write(CURRENT_PATH.join('tmp/rest-api-spec/build_hash'), @build_hash)
6395
end
6496

65-
def download_es_specification(branch = 'main')
97+
#
98+
# Downloads the specification from github.com/elastic/elasticsearch-specification
99+
# If a branch is specified with an env variable, it uses that, downloads `main` otherwise.
100+
#
101+
def download_es_specification
102+
branch = ENV['BRANCH'] || 'main'
66103
filename = CURRENT_PATH.join('tmp/schema.json')
104+
67105
url = "https://github.com/elastic/elasticsearch-specification/raw/#{branch}/output/schema/schema.json"
68106
download_file!(url, filename)
69107
end
70108

109+
#
110+
# Helper function to download files
111+
#
71112
def download_file!(url, filename)
72113
puts "Downloading #{filename} from #{url}"
73-
File.open(filename, "w") do |downloaded_file|
74-
URI.open(url, "rb") do |artifact_file|
114+
File.open(filename, 'w') do |downloaded_file|
115+
URI.open(url, 'rb') do |artifact_file|
75116
downloaded_file.write(artifact_file.read)
76117
end
77118
end

0 commit comments

Comments
 (0)