-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRakefile
155 lines (124 loc) · 4.46 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
# frozen_string_literal: true
require 'git-version-bump'
def version_file
File.expand_path(File.join(File.dirname(__FILE__), 'lib', 'corgibytes', 'freshli', 'commons', 'version.rb'))
end
def version_file_contents
<<~VERSION_FILE
# frozen_string_literal: true
module Corgibytes
module Freshli
module Commons
VERSION = '#{GVB.version}'
end
end
end
VERSION_FILE
end
def write_version
File.write(version_file, version_file_contents)
load_version
end
def load_version
return if require_relative version_file
# forcefully reload version file if it was already loaded
Corgibytes::Freshli::Commons.send(:remove_const, :VERSION)
load(version_file)
end
write_version
require 'bundler/gem_tasks'
require 'rspec/core/rake_task'
require 'fileutils'
# TODO: Copy the `freshli_agent.proto` from the `corgibytes/freshli` repository
# instead of having it live in this repository. Similar to what's being done
# with the health status proto file below.
# based on https://stackoverflow.com/a/29743469/243215
def download(url, target_path)
# rubocop:disable Security/Open
require 'open-uri'
download = URI.open(url)
# rubocop:enable Security/Open
IO.copy_stream(download, target_path)
end
# Generate gRPC files from the freshli_agent.proto file
GENERATED_GRPC_FILES = [
'lib/corgibytes/freshli/commons/step_definitions/grpc/freshli_agent_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/freshli_agent_services_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/health_services_pb.rb',
'lib/corgibytes/freshli/commons/step_definitions/grpc/health_pb.rb'
].freeze
# rubocop:disable Metrics/BlockLength
namespace :grpc do
task :generate do
Rake::Task['grpc:generate:force'].invoke unless GENERATED_GRPC_FILES.all? { |file| File.exist?(file) }
end
namespace :generate do
desc 'Generate gRPC files even if they already exist'
task :force do
system(
'bundle exec grpc_tools_ruby_protoc -I ' \
'./protos/corgibytes/freshli/agent/grpc ' \
'--ruby_out=./lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'--grpc_out=./lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'./protos/corgibytes/freshli/agent/grpc/freshli_agent.proto'
)
FileUtils.mkdir_p('tmp')
download(
'https://raw.githubusercontent.com/grpc/grpc/e35cf362a49b4de753cbe69f3e836d2e40408ca2' \
'/src/proto/grpc/health/v1/health.proto',
File.expand_path(File.join(File.dirname(__FILE__), 'tmp', 'health.proto'))
)
system(
'bundle exec grpc_tools_ruby_protoc -I tmp ' \
'--ruby_out=lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'--grpc_out=lib/corgibytes/freshli/commons/step_definitions/grpc ' \
'tmp/health.proto'
)
end
end
end
# rubocop:enable Metrics/BlockLength
desc 'Generate gRPC files'
task grpc: %i[grpc:generate]
# Ensure that the grpc files are generated before the tests run
RSpec::Core::RakeTask.new(spec: 'grpc')
require 'rubocop/rake_task'
RuboCop::RakeTask.new
namespace :version do
desc "Persist the the current version number as #{GVB.version}"
task :persist do
write_version
end
task :show do
puts "Current version #{Corgibytes::Freshli::Commons::VERSION}"
end
end
# Ensure that the grpc files are generated before the build runs
Rake::Task['build'].enhance(['grpc', 'version:show'])
task default: %i[grpc spec rubocop]
# Copied from https://github.com/mpalmer/git-version-bump/blob/c1af65cd82c131cb541fa717b3d24a9247973049/lib/git-version-bump/rake-tasks.rb
# to avoid an issue that was causing the version number of the `git-version-bump` gem to be used instead
# of this gem's version. That's because of how the `GVB.version` method determines the calling file.
namespace :version do
namespace :bump do
desc 'bump major version (x.y.z -> x+1.0.0)'
task :major do
GVB.tag_version "#{GVB.major_version + 1}.0.0"
puts "Version is now #{GVB.version}"
end
desc 'bump minor version (x.y.z -> x.y+1.0)'
task :minor do
GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version + 1}.0"
puts "Version is now #{GVB.version}"
end
desc 'bump patch version (x.y.z -> x.y.z+1)'
task :patch do
GVB.tag_version "#{GVB.major_version}.#{GVB.minor_version}.#{GVB.patch_version + 1}"
puts "Version is now #{GVB.version}"
end
desc 'Print current version'
task :show do
puts GVB.version
end
end
end