Skip to content

Commit 7e17ad5

Browse files
committed
[CI] Adds release task and integrates with make.sh script
1 parent 12a106b commit 7e17ad5

File tree

5 files changed

+86
-49
lines changed

5 files changed

+86
-49
lines changed

.ci/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ARG RUBY_TEST_VERSION=2.6
1+
ARG RUBY_TEST_VERSION=2.7
22
FROM ruby:${RUBY_TEST_VERSION}
33

44
ENV GEM_HOME="/usr/local/bundle"

.ci/make.sh

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# common build entry script for all elasticsearch clients
55

66
# ./.ci/make.sh bump VERSION
7-
# ./.ci/make.sh release TARGET_DIR
7+
# ./.ci/make.sh build[TARGET_DIR]
88
script_path=$(dirname "$(realpath -s "$0")")
99
repo=$(realpath "$script_path/../")
1010

@@ -13,9 +13,11 @@ CMD=$1
1313
VERSION=$2
1414
set -euo pipefail
1515

16-
TARGET_DIR=".ci/output"
16+
TARGET_DIR=${TARGET_DIR-.ci/output}
1717
OUTPUT_DIR="$repo/${TARGET_DIR}"
1818
RUBY_TEST_VERSION=${RUBY_TEST_VERSION-2.7}
19+
GITHUB_TOKEN=${GITHUB_TOKEN-}
20+
RUBYGEMS_API=${RUBYGEMS_API-}
1921

2022
case $CMD in
2123
bump)
@@ -24,8 +26,11 @@ case $CMD in
2426
build)
2527
TASK=build["$TARGET_DIR"]
2628
;;
29+
publish)
30+
TASK=publish
31+
;;
2732
*)
28-
echo -e "\nUsage:\n\t $0 {bump[VERSION]|build[VERSION,TARGET_DIR]}\n"
33+
echo -e "\nUsage:\n\t $0 {bump [VERSION] | build [TARGET_DIR]}\n"
2934
exit 1
3035
esac
3136

@@ -41,9 +46,11 @@ echo -e "\033[1m>>>>> Run [elastic/elasticsearch-ruby container] >>>>>>>>>>>>>>>
4146
mkdir -p "$OUTPUT_DIR"
4247

4348
docker run \
44-
--env "RUBY_TEST_VERSION" \
45-
--name test-runner \
46-
--volume "${OUTPUT_DIR}:/${TARGET_DIR}" \
47-
--rm \
48-
elastic/elasticsearch-ruby \
49-
bundle exec rake "$TASK"
49+
--env "RUBY_TEST_VERSION=${RUBY_TEST_VERSION}" \
50+
--env "GITHUB_TOKEN" \
51+
--env "RUBYGEMS_API_KEY" \
52+
--name test-runner \
53+
--volume "${OUTPUT_DIR}:/${TARGET_DIR}" \
54+
--rm \
55+
elastic/elasticsearch-ruby \
56+
bundle exec rake unified_release:"$TASK"

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ RELEASE_TOGETHER = [ 'elasticsearch',
3737
CERT_DIR = ENV['CERT_DIR'] || '.ci/certs'
3838

3939
# Import build task after setting constants:
40-
import 'rake_tasks/build_tasks.rake'
40+
import 'rake_tasks/unified_release_tasks.rake'
4141

4242
def admin_client
4343
$admin_client ||= begin

rake_tasks/build_tasks.rake

Lines changed: 0 additions & 38 deletions
This file was deleted.

rake_tasks/unified_release_tasks.rake

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
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_relative '../elasticsearch/lib/elasticsearch/version'
19+
CURRENT_VERSION = Elasticsearch::VERSION
20+
21+
namespace :unified_release do
22+
desc 'Bump versions'
23+
task :bump, [:version] do |_, args|
24+
raise ArgumentError, 'You must specify a version: rake bump[8.0.0]' unless args[:version]
25+
26+
Rake::Task['update_version'].invoke(CURRENT_VERSION, args[:version])
27+
end
28+
29+
desc 'Build release gem files'
30+
task :build, [:output_dir] do |_, args|
31+
raise ArgumentError, 'You must specify an output dir: rake build[output_dir]' unless args[:output_dir]
32+
33+
RELEASE_TOGETHER.each do |gem|
34+
puts '-' * 80
35+
puts "Building #{gem} v#{CURRENT_VERSION} to #{args[:output_dir]}"
36+
sh "cd #{CURRENT_PATH.join(gem)} && gem build --silent && mv *.gem #{CURRENT_PATH.join(args[:output_dir])}"
37+
end
38+
puts '-' * 80
39+
end
40+
41+
desc 'Publish gems to Rubygems'
42+
task :publish do
43+
setup_credentials
44+
45+
RELEASE_TOGETHER.each do |gem|
46+
puts '-' * 80
47+
puts "Releasing #{gem} v#{CURRENT_VERSION}"
48+
sh "cd #{CURRENT_PATH.join(gem)} && bundle exec rake release"
49+
end
50+
end
51+
52+
def setup_credentials
53+
raise ArgumentError, 'You need to set the env value for GITHUB_TOKEN' unless ENV['GITHUB_TOKEN']
54+
raise ArgumentError, 'You need to set the env value for RUBYGEMS_API_KEY' unless ENV['RUBYGEMS_API_KEY']
55+
56+
file_name = File.expand_path('~/.gem/credentials')
57+
text = <<~CREDENTIALS
58+
---
59+
:github: Bearer #{ENV['GITHUB_TOKEN']}
60+
:rubygems_api_key: #{ENV['RUBYGEMS_API_KEY']}
61+
CREDENTIALS
62+
File.open(file_name, 'w') do |file|
63+
file.write(text)
64+
end
65+
66+
FileUtils.chmod 0o600, file_name
67+
end
68+
end

0 commit comments

Comments
 (0)