Skip to content

Commit 85cfe97

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`. - Updates action to peter-eveans/create-pull-request (backport from main) - Sets report action to manual and branch, automation should be triggered in main
1 parent 26258cb commit 85cfe97

File tree

3 files changed

+65
-23
lines changed

3 files changed

+65
-23
lines changed

.github/workflows/report.yml

+18-10
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
name: report
22
on:
33
workflow_dispatch:
4-
schedule:
5-
- cron: "0 6 * * 1"
64
push:
75
branches:
8-
- main
6+
- 8.x
97
jobs:
108
generate_report:
119
runs-on: ubuntu-latest
10+
env:
11+
STACK_VERSION: 8.18.0-SNAPSHOT
12+
BRANCH: '8.x' # Branch for downloading the specs
1213
steps:
1314
- uses: actions/checkout@v4
1415
with:
1516
persist-credentials: false
1617
- uses: ruby/setup-ruby@v1
1718
with:
1819
ruby-version: 3.3
19-
env:
20-
STACK_VERSION: 8.18.0-SNAPSHOT
2120
- name: Build
2221
run: |
2322
cd report && bundle install
@@ -26,10 +25,19 @@ jobs:
2625
run: cd report && bundle exec rake download_all
2726
- name: Generate report
2827
run: cd report && bundle exec rake report
29-
- uses: gr2m/create-or-update-pull-request-action@v1
30-
env:
31-
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
28+
- name: Create Pull Request
29+
uses: peter-evans/create-pull-request@v6
30+
id: cpr
3231
with:
33-
commit-message: Updates API report ${{env.REPORT_DATE}}
34-
title: Updates API report
32+
token: ${{ secrets.GITHUB_TOKEN }}
33+
commit-message: Updates API report ${{env.REPORT_DATE}} ${{ env.BRANCH }}
34+
branch: update_report_${{ env.BRANCH }}
35+
title: Updates API report ${{ env.BRANCH }}
36+
body: 'As titled'
37+
base: ${{ env.BRANCH }}
38+
committer: 'Elastic Machine <elasticmachine@users.noreply.github.com>'
3539
author: 'Elastic Machine <elasticmachine@users.noreply.github.com>'
40+
- name: Pull Request Summary
41+
if: ${{ steps.cpr.outputs.pull-request-url }}
42+
run: |
43+
echo "${{ env.BRANCH }} - ${{ steps.cpr.outputs.pull-request-url }}" >> $GITHUB_STEP_SUMMARY

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)