зеркало из
1
0
Форкнуть 0
azure-sdk-for-ruby/Rakefile

503 строки
26 KiB
Ruby
Исходник Обычный вид История

2012-08-29 05:43:31 +04:00
#-------------------------------------------------------------------------
2013-11-26 04:38:44 +04:00
# # Copyright (c) Microsoft and contributors. All rights reserved.
2012-08-29 05:43:31 +04:00
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#--------------------------------------------------------------------------
#
# This rakefile consists of several tasks. This section will provide an overview of the
# tasks and their dependencies.
#
# -------------------------------------------------------------------------------------------------------------------------------------------
# | No | Task | Description |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 1 | regen | Regenerates all the SDK versions for all the services and all the profiles for all the services. |
# | | | This task has regen_sdk_versions and regen_all_profiles as prereqs. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 2 | regen_sdk_versions | Regenerates all the SDK versions for all the services. At the end, this task calls |
# | | | regen_individual_require_files as an enhancement. This task has clean_generated as prereq. This |
# |. |. | task is focused on code generation using autorest and will generate api versions as indicated in |
# | | |.in the config.json file. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 3 | regen_all_profiles | Regenerates all the profiles for all the services. This task has regen_rollup_profile and |
# | | | regen_individual_profiles as prereqs. This task uses the profile_generator to generate the |
# | | | with inputs from profiles.json and dir_metadata.json. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 4 | clean_generated | Cleans all the generated folders in multiple SDK versions. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 5 | regen_rollup_profile | Regenerates all profiles within the rollup gem. At the end, this task calls |
# | | | regen_rollup_require_files as an enhancement. This task has clean_rollup_profiles as prereq. This|
#.|. | | task requires correct definition of rollup profiles in profiles.json file. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 6 | regen_individual_profiles | Regenerates all profiles with all the services. At the end, this task calls |
# | | | regen_individual_require_files as an enhancement. This task calls clean_individual_profiles |
# | | | as prereq. This task requires correct definition of individual profiles in profiles.json file. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 7 | clean_all_profiles | Cleans all profiles inside the rollup gem and individual gems.This task has clean_rollup_profiles|
# | | | and clean_individual_profiles as prereqs. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 8 | clean_rollup_profiles | Cleans all profiles inside the rollup gem. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 9 | clean_individual_profiles | Cleans all profiles inside individual gems. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 10 | regen_all_require_files | Regenerates the require files for the rollup gem and individual gems. This task has |
# | | | regen_rollup_require_files and regen_individual_require_files as prereqs. A require file is the |
# | | | base file for a gem which includes other file. A sample could be found here: |
# |. | | https://github.com/Azure/azure-sdk-for-ruby/blob/master/azure_sdk/lib/azure_sdk.rb |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 11 | regen_rollup_require_files | Regenerates the require files for the rollup gem |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 12 | regen_individual_require_files | Regenerates the require files for the individual gems |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 13 | release | Release gems. This task has build as a prereq. The gems to be released must be indicated in the |
# |. | | GEMS_TO_RELEASE file. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 14 | build | Builds all gems. This task has clean as a prereq. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 15 | clean | Cleans the pks folder inside all the gems. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 16 | bundle:update | Performs bundle update for all gems. |
# |----|---------------------------------|--------------------------------------------------------------------------------------------------|
# | 17 | spec | Executes tests for all gems. |
# -------------------------------------------------------------------------------------------------------------------------------------------
#
# regen
# |
# -----------------------------------------------------------------------------------------------------
# | |
# regen_sdk_versions -->enhancement--> regen_individual_require_files |
# | regen_all_profiles
# | |
# clean_generated ------------------------------------------------------------------------------------------------------------------------------
# | |
# | |
# | |
# | |
# | regen_all_require_files |
# | | |
# | ----------------------------------------- |
# | | | |
# | | | |
# | | | |
# regen_rollup_profile -->enhancement--> regen_rollup_require_files | |
# | | |
# | | |
# | | |
# | | |
# | | |
# | | |
# | regen_individual_require_files<--enhancement<--regen_individual_profiles
# | |
# | clean_all_profiles |
# | | |
# | --------------------------------------------------------------------------------------------------------------- |
# | | | |
# | | | |
# clean_rollup_profiles clean_individual_profiles
#
# release
# |
# build
# |
# clean
#
# bundle:update
#
# spec
#
require 'dotenv/tasks'
require 'rspec/core/rake_task'
require 'open3'
require 'os'
2017-08-31 02:37:29 +03:00
require 'json'
require 'fileutils'
2012-06-15 01:45:06 +04:00
def get_config_files_folder
"#{__dir__}/config"
end
gem_versions = JSON.parse(File.read(File.expand_path("#{get_config_files_folder}/GEM_VERSIONS", __FILE__)).strip)
gems_to_release = JSON.parse(File.read(File.expand_path("#{get_config_files_folder}/GEMS_TO_RELEASE", __FILE__)).strip)
Update master to latest (#1529) * Update Cognitive Services Computer Vision * Update Cognitive Services Computer Vision Profiles to 2.0 * Update Cognitive Services Content Moderator Config * Updated Cognitive Services Custom Search Config * Update Cognitive Services Entity Search Config * Update Cognitive Services Face Config * Update Cognitive Services Image Search Config * Update Cognitive Services News Search Config * Update Cognitive Services Spell Check Config * Update Cognitive services Text Analytics Config * Update Cognitive Services Video Search Config * Update Cognitive Services Web Search Config * Update Data Plane Event Grid Config * Update Data Plane Key Vault Config and Profile config * Updated Management Plane Analysis Services Config File * Update Management Plane API Management SDK Config and Profiles * Update Management Plane Authorization Config * Update Management plane Automation config * Update Management Plane Batch Config * Update Management plane Billing config and profile files * Update Management plane cdn config file * Update Management Plane Cognitive Services config file * Update Management Plane Commerce Config file * Update Management Consumption SDK Config & Profiles files * Updated Management plane container instance sdk config and profile files * Update Management Container Registry Config file * Update Management Plane container service SDK config & profiles * Update Management plane Customer Insights config file * Update Management Datalake Analytics SDK config file * Updated Management Datalake store config file * Update Management Dev Spaces Config file * Update Management DevTestLabs Config file * Update Management DNS Config file * Update Management Event Grid Config file * Update Management Event Hub Config & Profiles file * Update Management IOT Central config and profiles file * Update Management IOT Hub Config & Profiles file * Update Management Key Vault Profile & Config files * Update Management Machine Learning SDK Config file * Update Management Marketplace ordering Config file * Update Management Media Services config & profiles files * Update Rakefile and Rakegeneration process to exclude mobile engagement * Update Management Monitor SDK config file * Update Management msi config json * Update Management Notification hubs config file * Update Management Operational Insights COnfig file * Update Management Policy Insights Config file * Update Management Powerbi embedded Config file * Update Management Recoverservices config file * Update Management Recovery Services Backup Config file * Update Management Recovery Services Site Recovery Config and Profiles file * Update Management Redis config & profiles file * Update Management Relay config file * Update Management Scheduler config file * Update Management Search Config file * Update Management Security config file * Update Management Service Bus config file * Update Management Service Fabric Config & Profiles * Update Management SignalR COnfig file * Update Management Stor Simple 8000 Series config file * Update Management Storage Config file * Update Management Stream Analytics Config file * Update Data Plane Graph RBAC Config file * Update Management Traffic Manager Config and Profiles file * Update Management Features config file * Update Management Links Config file * Update Management Locks SDK Config file * Update Management Logic SDK Config file * Update Management Management Applications SDK Config & Profiles files * Update Management Policy Config & Profiles files * Update Management Resources SDK config & profiles files * Update Management Resources Management Config & Profiles files * Update Management Subscriptions SDK Config file * Update Management Web Profiles & Config files * Update Management Network profile and config files * Update Management SQL Config & Profiles files * Update Management Compute Config and profiles files * Remove references to mobile engagement & server management gems * Deleting azure_mgmt_graph folder * Removing Mobile Engagement folder * Remove server management folder * Regen all SDKs and profiles * Fix spec for azure_sdk
2018-07-28 00:54:37 +03:00
GEMS_TO_IGNORE = %w{azure_mgmt_graph, azure_mgmt_mobile_engagement, azure_mgmt_server_management}
REGEN_EXCLUDES = ['azure_sdk']
2012-06-15 01:45:06 +04:00
desc 'Azure Resource Manager related tasks which often traverse each of the arm gems'
namespace :arm do
desc 'Delete ./pkg for each of the Azure Resource Manager projects'
task :clean, [:gem_name] do |_, args|
each_gem do |dir|
if !should_i_continue(args[:gem_name], dir)
next
end
FileUtils.rm_rf('pkg')
end
2012-07-07 02:59:00 +04:00
end
desc 'Delete multiple version folders for each sdk'
task :clean_generated, [:gem_name] do |_, args|
clean_generated('management', args[:gem_name])
clean_generated('data', args[:gem_name])
Dir.chdir(File.expand_path('..', __FILE__))
2012-06-15 01:45:06 +04:00
end
2013-10-11 14:09:19 +04:00
desc 'Build gems for each of the Azure Resource Manager projects'
task :build, [:gem_name] => :clean do |_, args|
each_gem do |dir|
if !should_i_continue(args[:gem_name], dir)
next
end
execute_and_stream('rake build')
end
end
2012-06-15 01:45:06 +04:00
desc 'Push gem for each of the Azure projects'
task :release, [:key] => :build do |_, args|
gems_to_release.each do |key, gems|
gems.each do |gem|
if(key == 'rollup')
Dir.chdir("#{__dir__}/azure_sdk")
version = gem_versions['rollup'][gem]
elsif(key == 'management')
Dir.chdir("#{__dir__}/management/#{gem}")
version = gem_versions['management'][gem]
elsif(key == 'data')
Dir.chdir("#{__dir__}/data/#{gem}")
version = gem_versions['data'][gem]
end
# Delay for 10 seconds before publishing gem
puts "Going to sleep for 10 seconds before publishing #{gem} ..."
sleep(10)
execute("gem push ./pkg/#{gem}-#{version}.gem" + (args[:key].nil? ? '' : " -k #{args[:key]}"))
end
2015-06-09 09:26:01 +03:00
end
2012-06-15 01:45:06 +04:00
end
2017-08-31 02:37:29 +03:00
desc 'Regen code for each sdk with all its api versions'
2019-04-14 08:47:58 +03:00
task :regen_sdk_versions, [:gem_name] => [:regen_folder_structure_if_required, :clean_generated] do |_, args|
2017-08-31 02:37:29 +03:00
json = get_config_file
each_gem do |dir| # dir corresponds to each azure_* folder
if REGEN_EXCLUDES.include?(dir.to_s)
update_gem_version('lib/azure_sdk/version.rb', gem_versions['rollup'][dir])
next
end
if !should_i_continue(args[:gem_name], dir)
next
end
mode = get_mode(dir)
puts "\nGenerating #{dir}\n"
ar_base_command = "#{ENV.fetch('AUTOREST_LOC', 'autorest')}"
ar_base_command = "#{ar_base_command} --use=#{ENV.fetch('AUTOREST_RUBY_LOC')}" unless ENV.fetch('AUTOREST_RUBY_LOC', nil).nil?
puts "ar_base_command #{ar_base_command}"
md = json[dir] # there should be an entry in the metadata for each of the api versions to generate
package_name = dir
md.each do |api_version_pkg, api_version_value|
ar_arguments = ''
output_folder = ''
api_version_value.each do |argument_name, argument_value|
if argument_name.casecmp("output-folder") == 0
output_folder = argument_value
else
if argument_name.casecmp("package-name") == 0
package_name = argument_value
else
if argument_name.casecmp("markdown") == 0
ar_arguments = ar_arguments + " #{argument_value}"
else
if argument_name.casecmp("input-file") == 0
input_files = argument_value.map {|file| "--input-file=#{file}"}
ar_arguments = ar_arguments + input_files.join(" ")
else
ar_arguments = ar_arguments + " --#{argument_name}=#{argument_value}"
end
end
end
end
2017-08-31 02:37:29 +03:00
end
command = "#{ar_base_command} --package-name=#{package_name} #{ar_arguments} --package-version=#{gem_versions[mode][dir]} --output-folder=#{File.join(Dir.pwd, 'lib', output_folder)} --ruby --azure-arm --version=V2"
execute_and_stream(command)
2016-09-12 21:02:17 +03:00
end
update_gem_version('lib/version.rb', gem_versions[mode][dir])
2012-06-15 01:45:06 +04:00
end
end
2012-06-15 01:45:06 +04:00
desc 'Bundler related helper'
namespace :bundle do
desc 'bundle update for each of the Azure Resource Manager projects'
task :update, [:gem_name] do |_, args|
each_gem do
if !should_i_continue(args[:gem_name], dir)
next
end
execute_and_stream('bundle update')
end
end
2012-06-15 01:45:06 +04:00
end
desc 'run specs for each of the Azure Resource Manager projects'
task :spec, [:gem_name] => :dotenv do |_, args|
each_gem do |gem_dir|
if !should_i_continue(args[:gem_name], gem_dir)
next
end
puts "Executing spec on #{gem_dir}"
execute_and_stream('bundle install')
execute_and_stream('bundle exec rspec')
end
end
desc 'Clean Rollup Profiles'
task :clean_rollup_profiles do
Dir.chdir(File.expand_path('../azure_sdk/lib', __FILE__))
subdir_list = Dir['*'].reject{|o| not File.directory?(o)}
subdir_list.each do |subdir|
if subdir != 'azure_sdk'
folder_to_be_cleaned = File.expand_path("../azure_sdk/lib/#{subdir}", __FILE__)
puts "Cleaning folder - #{folder_to_be_cleaned}"
FileUtils.rm_rf(folder_to_be_cleaned)
end
end
end
desc 'Clean Individual Profiles'
task :clean_individual_profiles, [:gem_name] do |_, args|
each_gem_dir do |gem|
if !should_i_continue(args[:gem_name], gem)
next
end
if REGEN_EXCLUDES.include?gem
next
end
mode = get_mode(gem)
Dir.chdir("#{__dir__}/#{mode}/#{gem}/lib/profiles")
subdir_list = Dir['*'].reject{|o| not File.directory?(o)}
subdir_list.each do |subdir|
folder_to_be_cleaned = "#{__dir__}/#{mode}/#{gem}/lib/profiles/#{subdir}"
puts "Cleaning folder - #{folder_to_be_cleaned}"
FileUtils.rm_rf(folder_to_be_cleaned)
end
end
end
desc 'Clean All profiles'
task :clean_all_profiles, [:gem_name] => [:clean_rollup_profiles, :clean_individual_profiles] do
puts 'Cleaned all profiles'
end
desc 'Regen rollup profiles'
task :regen_rollup_profile => :clean_rollup_profiles do
Dir.chdir(__dir__)
# Sample Command
# bundle exec ruby profile_generator_client.rb --dir_metadata=dir_metadata.json --profile=profiles.json --mode=rollup --key=azure_sdk
command = "#{get_base_profile_generation_cmd} --dir_metadata=#{get_config_files_folder}/dir_metadata.json --profile=#{get_config_files_folder}/profiles.json --mode=rollup --key=azure_sdk --sdk_path=#{__dir__}"
execute_and_stream(command)
end
desc 'Regen individual profiles'
task :regen_individual_profiles, [:gem_name] => :clean_individual_profiles do |_, args|
each_gem_dir do |gem|
if !should_i_continue(args[:gem_name], gem)
next
end
if REGEN_EXCLUDES.include?gem
next
end
mode = get_mode(gem)
# Sample Command
# bundle exec ruby profile_generator_client.rb --dir_metadata=dir_metadata.json --profile=authorization_profiles.json --mode=management --key=azure_mgmt_authorization
command = "#{get_base_profile_generation_cmd} --dir_metadata=#{get_config_files_folder}/dir_metadata.json --profile=#{get_config_files_folder}/profiles.json --mode=#{mode} --key=#{gem} --sdk_path=#{__dir__}"
execute_and_stream(command)
end
end
desc 'Generate individual require files'
task :regen_individual_require_files, [:gem_name] do |_, args|
key = args[:gem_name].nil? ? '*' : args[:gem_name]
command = "bundle exec ruby #{__dir__}/generators/requirefilegen/src/require_file_generator.rb --mode=individual --sdk_path=#{__dir__} --gem_name=#{key}"
execute_and_stream(command)
end
desc 'Generate rollup require files'
task :regen_rollup_require_files do
command = "bundle exec ruby #{__dir__}/generators/requirefilegen/src/require_file_generator.rb --mode=rollup --sdk_path=#{__dir__} --gem_name=azure_sdk"
execute_and_stream(command)
end
task :regen_folder_structure_if_required, [:gem_name] do |_, args|
2019-04-14 08:47:58 +03:00
if args[:gem_name] && !REGEN_EXCLUDES.include?(args[:gem_name])
plane = 'data'
if(args[:gem_name].include?'_mgmt_')
plane = 'management'
end
2019-04-30 23:56:38 +03:00
command = "ruby #{__dir__}/generators/metadatagen/src/metadatagen.rb --plane=#{plane} --gem_name=#{args[:gem_name]} --sdk_path=#{__dir__}"
2019-04-14 08:47:58 +03:00
execute_and_stream(command)
end
end
desc 'Generate all require files'
task :regen_all_require_files, [:gem_name] => [:regen_individual_require_files, :regen_rollup_require_files] do
puts 'Generated all require files'
end
desc 'Regen all profiles'
task :regen_all_profiles, [:gem_name] => [:regen_rollup_profile, :regen_individual_profiles] do
puts 'Regenerated all profiles'
end
desc 'Regen all versions of sdk and profiles'
task :regen, [:gem_name] => [:regen_sdk_versions, :regen_all_profiles] do
puts 'Regenerated all versions of sdk and profiles'
end
end
Rake::Task['arm:regen_rollup_profile'].enhance do
Rake::Task['arm:regen_rollup_require_files'].invoke
Rake::Task['arm:regen_rollup_require_files'].reenable
end
Rake::Task['arm:regen_individual_profiles'].enhance do |_, args|
Rake::Task['arm:regen_individual_require_files'].invoke(args[:gem_name])
Rake::Task['arm:regen_individual_require_files'].reenable
end
Rake::Task['arm:regen_sdk_versions'].enhance do |_, args|
Rake::Task['arm:regen_individual_require_files'].invoke(args[:gem_name])
Rake::Task['arm:regen_individual_require_files'].reenable
end
task :default => :spec
def should_i_continue(key, dir)
return (key.nil? || key == dir)
end
def get_mode(dir)
mode = ''
if (dir.include? '_mgmt_')
mode = 'management'
else
mode = 'data'
end
mode
end
def clean_generated(parent_dir, key)
Dir.chdir(File.expand_path("../#{parent_dir}", __FILE__))
gem_folders = Dir['*'].reject{|o| not File.directory?(o)}
gem_folders.each do |gem|
if !should_i_continue(key, gem)
next
end
if GEMS_TO_IGNORE.include?gem
next
end
Dir.chdir(File.expand_path("../#{parent_dir}/#{gem}/lib", __FILE__))
subdir_list = Dir['*'].reject{|o| not File.directory?(o)}
subdir_list.each do |subdir|
if subdir.to_s == 'profiles'
next
end
folder_to_be_cleaned = File.expand_path("../#{parent_dir}/#{gem}/lib/#{subdir}", __FILE__)
puts "Cleaning folder - #{folder_to_be_cleaned}"
FileUtils.rm_rf(folder_to_be_cleaned)
end
end
end
def get_base_profile_generation_cmd
"bundle exec ruby #{__dir__}/generators/profilegen/src/profile_generator_client.rb"
end
def execute_and_stream(cmd)
puts "running: #{cmd}"
execute(cmd)
end
def execute(cmd)
Open3.popen2e(cmd) do |_, stdout_err, wait_thr|
while line = stdout_err.gets
puts line
end
exit_status = wait_thr.value
unless exit_status.success?
abort "FAILED !!!"
end
end
end
2017-08-31 02:37:29 +03:00
def get_config_file
config_file = File.read(File.expand_path("#{get_config_files_folder}/config.json", __FILE__))
JSON.parse(config_file)
2017-08-31 02:37:29 +03:00
end
def each_child
each_child_mode_specific('management') {|dir| yield dir }
each_child_mode_specific('data') {|dir| yield dir }
Dir.chdir(File.expand_path('../azure_sdk', __FILE__))
yield('azure_sdk')
end
def each_child_mode_specific(parent_dir, change_dir = true)
Dir.chdir(File.expand_path("../#{parent_dir}", __FILE__))
sub_dirs = Dir['*'].reject{|o| not File.directory?(o)}
sub_dirs.each do |dir|
if GEMS_TO_IGNORE.include?dir
next
end
if (change_dir)
Dir.chdir(dir) do
yield(dir)
end
else
yield dir
2012-06-15 01:45:06 +04:00
end
end
end
def each_gem
each_child do |dir|
2017-08-31 02:37:29 +03:00
gem_dir = dir.split('/').last
yield gem_dir
end
end
2012-06-15 01:45:06 +04:00
def each_gem_dir
each_child_mode_specific('management', false) {|dir| yield dir }
each_child_mode_specific('data', false) {|dir| yield dir }
end
def update_gem_version(version_file, new_version)
existing_contents = File.read(version_file)
content_to_replace = existing_contents.gsub(/VERSION = '.*'/, "VERSION = '#{new_version}'")
File.open(version_file, 'w') { |file| file.puts content_to_replace }
end