diff --git a/script/synth.rb b/script/synth.rb index f316d35c7..46b55792b 100755 --- a/script/synth.rb +++ b/script/synth.rb @@ -15,8 +15,16 @@ end # so any previously created files don't pollute this and subsequent synth runs. execute "git clean -df" -Dir.chdir "google-apis-generator" +# 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? diff --git a/synth.py b/synth.py index 67bb9953c..469360520 100644 --- a/synth.py +++ b/synth.py @@ -31,6 +31,7 @@ command = [ f"-v{os.getcwd()}:/workspace", "-v/var/run/docker.sock:/var/run/docker.sock", "-w", "/workspace", + "-e", f"USER_GROUP={os.getuid()}:{os.getgid()}", "--entrypoint", "script/synth.rb", "gcr.io/cloud-devrel-kokoro-resources/yoshi-ruby/autosynth"] if extra_args():