|
| 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