@@ -10,8 +10,6 @@ require 'yard'
1010require 'rubocop/rake_task'
1111require 'tmpdir'
1212
13- SPEC_VERSION = '1.10.0'
14-
1513RuboCop ::RakeTask . new
1614
1715Rake ::TestTask . new :test do |t |
3129 task default : %i[ generate test rubocop yard ]
3230end
3331
34- task :generate do
35- cwd = Dir . pwd
32+ SPEC_VERSION = '1.20.0'
33+ PREV_SPEC_VERSION = Dir . children ( './lib/opentelemetry/semantic_conventions/' )
34+ . select { |dir | dir != SPEC_VERSION && File . directory? ( "./lib/opentelemetry/semantic_conventions/#{ dir } " ) }
35+ . map { |dir | Gem ::Version . new ( dir ) }
36+ . max
37+
38+ GENERATOR_VERSION = '0.22.0'
39+ semconvrepodir = './tmpsemconvrepo'
40+ gen_output_dir = "./lib/opentelemetry/semantic_conventions/#{ SPEC_VERSION } "
3641
37- Dir . mktmpdir ( 'opentelemetry-specification' , Dir . pwd ) do |tmpdir |
38- `git clone https://github.com/open-telemetry/opentelemetry-specification.git #{ tmpdir } `
39- Dir . chdir ( tmpdir ) do
40- `git fetch`
41- `git checkout "v#{ SPEC_VERSION } "`
42- end
43-
44- %w[ trace resource ] . each do |kind |
45- cmd = %W[
46- docker run --rm
47- -v "#{ tmpdir } /semantic_conventions/#{ kind } ":/source
48- -v "#{ cwd } /templates":/templates
49- -v "#{ cwd } /lib":/output
50- otel/semconvgen:0.11.1
51- -f /source code
52- --template /templates/semantic_conventions.j2
53- --output /output/opentelemetry/semantic_conventions/#{ kind } .rb
54- -Dmodule=#{ kind [ 0 ] . upcase } #{ kind [ 1 ..] }
55- ]
56-
57- puts "Running: #{ cmd . join ( ' ' ) } "
58- `#{ cmd . join ( ' ' ) } `
59- end
42+ task generate : [ :update_gem_version , :update_includes , "#{ gen_output_dir } /trace.rb" , "#{ gen_output_dir } /resource.rb" ]
43+
44+ directory semconvrepodir do
45+ `git clone --depth=1 --branch v#{ SPEC_VERSION } https://github.com/open-telemetry/opentelemetry-specification.git #{ semconvrepodir } `
46+ end
47+
48+ task check_out_semconv_version : [ semconvrepodir ] do
49+ Dir . chdir ( semconvrepodir ) do
50+ `git fetch`
51+ `git checkout "v#{ SPEC_VERSION } "`
6052 end
53+ end
54+
55+ directory gen_output_dir
56+
57+ file "#{ gen_output_dir } /trace.rb" => [ :check_out_semconv_version , gen_output_dir ] do
58+ semconvgen ( semconvrepodir , kind : 'trace' , only : 'span,event,attribute_group,scope' )
59+ end
60+
61+ file "#{ gen_output_dir } /resource.rb" => [ :check_out_semconv_version , gen_output_dir ] do
62+ semconvgen ( semconvrepodir , kind : 'resource' , only : 'resource' )
63+ end
64+
65+ def semconvgen ( semconvrepo , kind :, only :)
66+ cwd = Dir . pwd
67+ cmd = %W[
68+ docker run --rm
69+ -v "#{ semconvrepo } /semantic_conventions/":/source
70+ -v "#{ cwd } /templates":/templates
71+ -v "#{ cwd } /lib":/output
72+ otel/semconvgen:#{ GENERATOR_VERSION }
73+ --only #{ only }
74+ --yaml-root /source code
75+ --template /templates/semantic_conventions.j2
76+ --output /output/opentelemetry/semantic_conventions/#{ SPEC_VERSION } /#{ kind } .rb
77+ -Dkind=#{ kind }
78+ -Dmodule=#{ kind [ 0 ] . upcase } #{ kind [ 1 ..] }
79+ -Dspec_version=#{ SPEC_VERSION }
80+ -Dprev_spec_version=#{ PREV_SPEC_VERSION }
81+ ]
82+
83+ puts "Running: #{ cmd . join ( ' ' ) } "
84+ `#{ cmd . join ( ' ' ) } `
85+ end
86+
87+ task :update_includes do
88+ `sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{ SPEC_VERSION . tr ( "." , "_" ) } ::/g" lib/opentelemetry/semantic_conventions/trace.rb`
89+ `sed -i.bak "s/::SemanticConventions_.*::/::SemanticConventions_#{ SPEC_VERSION . tr ( "." , "_" ) } ::/g" lib/opentelemetry/semantic_conventions/resource.rb`
90+ `sed -i.bak "s/#{ PREV_SPEC_VERSION . to_s . gsub ( /\. / , "\\ ." ) } /#{ SPEC_VERSION } /" lib/opentelemetry/semantic_conventions.rb`
91+ `rm lib/opentelemetry/semantic_conventions/trace.rb.bak`
92+ `rm lib/opentelemetry/semantic_conventions/resource.rb.bak`
93+ `rm lib/opentelemetry/semantic_conventions.rb.bak`
94+ end
6195
96+ task :update_gem_version do
6297 `sed -i.bak "s/VERSION = '.*'/VERSION = '#{ SPEC_VERSION } '/g" lib/opentelemetry/semantic_conventions/version.rb`
6398 `rm lib/opentelemetry/semantic_conventions/version.rb.bak`
6499end
0 commit comments