forked from googleapis/google-api-ruby-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsynth.rb
executable file
·39 lines (32 loc) · 1.47 KB
/
synth.rb
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
#!/usr/bin/env ruby
require "fileutils"
DIR = File.dirname __dir__
def execute cmd
puts cmd
abort unless system cmd
end
# In an autosynth (multi-library) run, a previous library synth may have
# created a new library. If so, autosynth doesn't clean up those newly created
# files (i.e. it runs git reset --hard but not git clean). Do that ourselves,
# so any previously created files don't pollute this and subsequent synth runs.
execute "git clean -df"
# This script is generally run as a superuser in a container. As a result,
# newly generated files will have a superuser owner, and cannot easily be
# removed by the caller. Thus, we must ensure any files generated during this
# run are given a reasonable owner before the script exits.
at_exit do
user_group = ENV["USER_GROUP"]
execute "chown -R #{user_group} #{DIR}/generated" if user_group
end
Dir.chdir "google-apis-generator"
execute "bundle install"
if ARGV.empty?
execute "echo a | bundle exec bin/generate-api gen #{DIR}/generated --from-discovery --no-preferred-only --names=#{DIR}/api_names.yaml --names-out=#{DIR}/api_names_out.yaml --spot-check"
elsif ARGV == ["--clean"] || ARGV == ["clean"]
execute "bundle exec bin/generate-api gen #{DIR}/generated --clean"
elsif ARGV.size == 2
api, version = ARGV
execute "echo a | bundle exec bin/generate-api gen #{DIR}/generated --api=#{api}.#{version} --names=#{DIR}/api_names.yaml --names-out=#{DIR}/api_names_out.yaml --spot-check"
else
abort "Bad arguments: #{ARGV}"
end