Skip to content

Commit b59cd3d

Browse files
committed
[CI] Backports unified release scripts to 7.x
1 parent cad5744 commit b59cd3d

File tree

3 files changed

+185
-12
lines changed

3 files changed

+185
-12
lines changed

.ci/make.sh

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
#!/usr/bin/env bash
2+
# parameters are available to this script
3+
4+
# common build entry script for all elasticsearch clients
5+
6+
# ./.ci/make.sh bump VERSION
7+
# ./.ci/make.sh build[TARGET_DIR]
8+
script_path=$(dirname "$(realpath -s "$0")")
9+
repo=$(realpath "$script_path/../")
10+
11+
# shellcheck disable=SC1090
12+
CMD=$1
13+
VERSION=$2
14+
VERSION_QUALIFIER=${VERSION-''}
15+
set -euo pipefail
16+
17+
TARGET_DIR=${TARGET_DIR-.ci/output}
18+
OUTPUT_DIR="$repo/${TARGET_DIR}"
19+
RUBY_TEST_VERSION=${RUBY_TEST_VERSION-2.7}
20+
GITHUB_TOKEN=${GITHUB_TOKEN-nil}
21+
RUBYGEMS_API=${RUBYGEMS_API-nil}
22+
GIT_NAME=${GIT_NAME-elastic}
23+
GIT_EMAIL=${GIT_EMAIL-'[email protected]'}
24+
25+
case $CMD in
26+
assemble_snapshot)
27+
TASK=assemble_snapshot[$VERSION_QUALIFIER,$TARGET_DIR]
28+
;;
29+
assemble)
30+
TASK=assemble[$VERSION_QUALIFIER,$TARGET_DIR]
31+
;;
32+
*)
33+
echo -e "\nUsage:"
34+
echo -e "\t Build snapshot gems:"
35+
echo -e "\t $0 assemble_snapshot [version_qualifier]\n"
36+
echo -e "\t Build release gems:"
37+
echo -e "\t $0 assemble [version_qualifier]\n"
38+
exit 1
39+
esac
40+
41+
echo -e "\033[34;1mINFO:\033[0m OUTPUT_DIR ${OUTPUT_DIR}\033[0m"
42+
echo -e "\033[34;1mINFO:\033[0m RUBY_TEST_VERSION ${RUBY_TEST_VERSION}\033[0m"
43+
44+
echo -e "\033[1m>>>>> Build [elastic/elasticsearch-ruby container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
45+
46+
docker build --file .ci/Dockerfile --tag elastic/elasticsearch-ruby .
47+
48+
echo -e "\033[1m>>>>> Run [elastic/elasticsearch-ruby container] >>>>>>>>>>>>>>>>>>>>>>>>>>>>>\033[0m"
49+
50+
mkdir -p "$OUTPUT_DIR"
51+
52+
docker run \
53+
--env "RUBY_TEST_VERSION=${RUBY_TEST_VERSION}" \
54+
--env "GITHUB_TOKEN" \
55+
--env "RUBYGEMS_API_KEY" \
56+
--env "GIT_EMAIL" \
57+
--env "GIT_NAME" \
58+
--name test-runner \
59+
--volume $repo:/usr/src/app \
60+
--volume "${OUTPUT_DIR}:/${TARGET_DIR}" \
61+
--rm \
62+
elastic/elasticsearch-ruby \
63+
bundle exec rake unified_release:"$TASK"

Rakefile

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,21 +22,28 @@ import 'rake_tasks/update_version.rake'
2222
import 'profile/benchmarking/benchmarking_tasks.rake'
2323
require 'pathname'
2424

25-
CURRENT_PATH = Pathname( File.expand_path('..', __FILE__) )
26-
SUBPROJECTS = [ 'elasticsearch',
27-
'elasticsearch-transport',
28-
'elasticsearch-dsl',
29-
'elasticsearch-api',
30-
'elasticsearch-extensions',
31-
'elasticsearch-xpack' ].freeze
32-
33-
RELEASE_TOGETHER = [ 'elasticsearch',
34-
'elasticsearch-transport',
35-
'elasticsearch-api',
36-
'elasticsearch-xpack' ].freeze
25+
CURRENT_PATH = Pathname(File.expand_path(__dir__))
26+
SUBPROJECTS = [
27+
'elasticsearch',
28+
'elasticsearch-transport',
29+
'elasticsearch-dsl',
30+
'elasticsearch-api',
31+
'elasticsearch-extensions',
32+
'elasticsearch-xpack'
33+
].freeze
34+
35+
RELEASE_TOGETHER = [
36+
'elasticsearch',
37+
'elasticsearch-transport',
38+
'elasticsearch-api',
39+
'elasticsearch-xpack'
40+
].freeze
3741

3842
CERT_DIR = ENV['CERT_DIR'] || '.ci/certs'
3943

44+
# Import build task after setting constants:
45+
import 'rake_tasks/unified_release_tasks.rake'
46+
4047
def admin_client
4148
$admin_client ||= begin
4249
transport_options = {}

rake_tasks/unified_release_tasks.rake

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
# frozen_string_literal: true
2+
3+
# Licensed to Elasticsearch B.V. under one or more contributor
4+
# license agreements. See the NOTICE file distributed with
5+
# this work for additional information regarding copyright
6+
# ownership. Elasticsearch B.V. licenses this file to you under
7+
# the Apache License, Version 2.0 (the "License"); you may
8+
# not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing,
14+
# software distributed under the License is distributed on an
15+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
# KIND, either express or implied. See the License for the
17+
# specific language governing permissions and limitations
18+
require 'fileutils'
19+
require_relative '../elasticsearch/lib/elasticsearch/version'
20+
21+
namespace :unified_release do
22+
desc 'Build gem snapshot'
23+
task :assemble_snapshot, [:version_qualifier, :output_dir] do |_, args|
24+
qualifier = if args[:version_qualifier].nil? || args[:version_qualifier].empty?
25+
@zip_filename = "elasticsearch-ruby-#{Elasticsearch::VERSION}-SNAPSHOT"
26+
Time.now.strftime('%Y%m%d%H%M%S')
27+
else
28+
@zip_filename = "elasticsearch-ruby-#{Elasticsearch::VERSION}-#{args[:version_qualifier]}-SNAPSHOT"
29+
args[:version_qualifier]
30+
end
31+
@version = "#{Elasticsearch::VERSION}.#{qualifier}-SNAPSHOT"
32+
33+
Rake::Task['update_version'].invoke(Elasticsearch::VERSION, @version) unless @version == Elasticsearch::VERSION
34+
build_gems(args[:output_dir])
35+
zip_files(args[:output_dir])
36+
end
37+
38+
desc 'Build gem release'
39+
task :assemble, [:version_qualifier, :output_dir] do |_, args|
40+
version = [Elasticsearch::VERSION]
41+
version << args[:version_qualifier] unless args[:version_qualifier].nil? || args[:version_qualifier].empty?
42+
43+
@version = version.join('.')
44+
@zip_filename = "elasticsearch-ruby-#{version.join('-')}"
45+
Rake::Task['update_version'].invoke(Elasticsearch::VERSION, @version) unless @version == Elasticsearch::VERSION
46+
47+
build_gems(args[:output_dir])
48+
zip_files(args[:output_dir])
49+
end
50+
51+
def build_gems(output_dir)
52+
raise ArgumentError, 'You must specify an output dir' unless output_dir
53+
54+
# Create dir if it doesn't exist
55+
dir = CURRENT_PATH.join(output_dir).to_s
56+
FileUtils.mkdir_p(dir) unless File.exist?(dir)
57+
58+
RELEASE_TOGETHER.each do |gem|
59+
puts '-' * 80
60+
puts "Building #{gem} v#{@version} to #{output_dir}"
61+
sh "cd #{CURRENT_PATH.join(gem)} " \
62+
"&& gem build --silent -o #{gem}-#{@version}.gem && " \
63+
"mv *.gem #{CURRENT_PATH.join(output_dir)}"
64+
end
65+
puts '-' * 80
66+
end
67+
68+
def zip_files(output_dir)
69+
sh "cd #{CURRENT_PATH.join(output_dir)} && " \
70+
"zip -r #{@zip_filename}.zip * " \
71+
end
72+
73+
desc 'Publish gems to Rubygems'
74+
task :publish do
75+
setup_credentials
76+
77+
RELEASE_TOGETHER.each do |gem|
78+
puts '-' * 80
79+
puts "Releasing #{gem} v#{Elasticsearch::VERSION}"
80+
sh "cd #{CURRENT_PATH.join(gem)} && bundle exec rake release"
81+
end
82+
end
83+
84+
def setup_credentials
85+
raise ArgumentError, 'You need to set the env value for GITHUB_TOKEN' unless ENV['GITHUB_TOKEN']
86+
raise ArgumentError, 'You need to set the env value for RUBYGEMS_API_KEY' unless ENV['RUBYGEMS_API_KEY']
87+
88+
sh 'git config --global user.email ${GIT_EMAIL} && ' \
89+
'git config --global user.name ${GIT_NAME}'
90+
91+
file_name = File.expand_path('~/.gem/credentials')
92+
text = <<~CREDENTIALS
93+
---
94+
:github: Bearer #{ENV['GITHUB_TOKEN']}
95+
:rubygems_api_key: #{ENV['RUBYGEMS_API_KEY']}
96+
CREDENTIALS
97+
File.open(file_name, 'w') do |file|
98+
file.write(text)
99+
end
100+
101+
FileUtils.chmod 0o600, file_name
102+
end
103+
end

0 commit comments

Comments
 (0)