Skip to content

Commit eb79209

Browse files
authored
chore: Support --pull-googleapis from owlbot script (#26561)
1 parent ccf0be9 commit eb79209

4 files changed

Lines changed: 39 additions & 12 deletions

File tree

.github/workflows/new-library.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,18 @@ jobs:
1313
runs-on: ubuntu-latest
1414
env:
1515
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
16-
GOOGLEAPIS_GEN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
1716
steps:
1817
- name: Checkout repo
1918
uses: actions/checkout@v4
2019
- name: Install Ruby 3.3
2120
uses: ruby/setup-ruby@v1
2221
with:
2322
ruby-version: "3.3"
23+
- name: Install Bazel
24+
uses: bazel-contrib/setup-bazel@0.8.5
2425
- name: Install tools
2526
run: |
2627
gem install --no-document toys
2728
- name: Create library
2829
run: |
29-
toys new-library -v --pull --test --fork --bootstrap-releases ${{ github.event.inputs.protoPath }}
30+
toys new-library -v --bazelisk --pull --pull-googleapis --test --fork --bootstrap-releases ${{ github.event.inputs.protoPath }}

.github/workflows/owlbot.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@ jobs:
1616
runs-on: ubuntu-latest
1717
env:
1818
GITHUB_TOKEN: ${{ secrets.YOSHI_CODE_BOT_TOKEN }}
19-
GOOGLEAPIS_GEN_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2019
steps:
2120
- name: Checkout repo
2221
uses: actions/checkout@v4
2322
- name: Install Ruby 3.3
2423
uses: ruby/setup-ruby@v1
2524
with:
2625
ruby-version: "3.3"
26+
- name: Install Bazel
27+
uses: bazel-contrib/setup-bazel@0.8.5
2728
- name: Install tools
2829
run: |
2930
gem install --no-document toys
3031
- name: OwlBot
3132
run: |
32-
toys owlbot -v --pull --fork ${{ github.event.inputs.flags }} ${{ github.event.inputs.gems }}
33+
toys owlbot -v --pull --fork --pull-googleapis --bazelisk ${{ github.event.inputs.flags }} ${{ github.event.inputs.gems }}

.toys/new-library.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@
2727
flag :source_path, "--source-path=PATH" do
2828
desc "Path to the googleapis-gen source repo"
2929
end
30+
flag :pull_googleapis, "--pull-googleapis[=COMMIT]" do
31+
desc "Generate by pulling googleapis/googleapis and running Bazel from the protos there"
32+
end
3033
flag :pull, "--[no-]pull" do
3134
desc "Pull the latest owlbot images before running"
3235
end
@@ -66,11 +69,6 @@
6669
include "yoshi-pr-generator"
6770

6871
def run
69-
# Temporary hack to allow minitest-rg 5.2.0 to work in minitest 5.19 or
70-
# later. This should be removed if we have a better solution or decide to
71-
# drop rg.
72-
ENV["MT_COMPAT"] = "true"
73-
7472
setup
7573
set :branch_name, "gen/#{gem_name}" unless branch_name
7674
commit_message = "feat: Initial generation of #{gem_name}"
@@ -130,6 +128,11 @@ def call_owlbot
130128
cmd << "--protos-path" << protos_path if protos_path
131129
cmd << "--source-path" << source_path if source_path
132130
cmd << "--piper-client" << piper_client if piper_client
131+
if pull_googleapis == true
132+
cmd << "--pull-googleapis"
133+
elsif pull_googleapis
134+
cmd << "--pull-googleapis=#{pull_googleapis}"
135+
end
133136
cmd << "--bazelisk" if enable_bazelisk
134137
cmd += verbosity_flags
135138
exec_tool cmd

.toys/owlbot.rb

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,9 @@
6060
default(ENV["GOOGLEAPIS_GEN_GITHUB_TOKEN"] || ENV["GITHUB_TOKEN"])
6161
desc "GitHub token for cloning the googleapis-gen repository."
6262
end
63+
flag :pull_googleapis, "--pull-googleapis[=COMMIT]" do
64+
desc "Generate by pulling googleapis/googleapis and running Bazel from the protos there"
65+
end
6366
flag :source_path, "--source-path=PATH" do
6467
desc "Path to the googleapis-gen source repo."
6568
end
@@ -99,9 +102,10 @@ def run
99102
gems = choose_gems
100103
cd context_directory
101104
setup_git
102-
gem_info = collect_gem_info gems
103-
104105
pull_images
106+
maybe_pull_googleapis
107+
108+
gem_info = collect_gem_info gems
105109
if piper_client || protos_path
106110
set :source_path, run_bazel(gem_info)
107111
else
@@ -163,6 +167,24 @@ def pull_images
163167
exec ["docker", "pull", "#{POSTPROCESSOR_IMAGE}:#{postprocessor_tag}"]
164168
end
165169

170+
def maybe_pull_googleapis
171+
return unless pull_googleapis
172+
commit = pull_googleapis
173+
commit = "HEAD" if commit == true
174+
googleapis_dir = File.join context_directory, "tmp", "googleapis"
175+
rm_rf googleapis_dir
176+
mkdir_p googleapis_dir
177+
at_exit { FileUtils.rm_rf googleapis_dir }
178+
cd googleapis_dir do
179+
exec ["git", "init"]
180+
exec ["git", "remote", "add", "origin", "https://github.com/googleapis/googleapis.git"]
181+
exec ["git", "fetch", "--depth=1", "origin", commit]
182+
exec ["git", "branch", "github-head", "FETCH_HEAD"]
183+
exec ["git", "switch", "github-head"]
184+
end
185+
set :protos_path, googleapis_dir
186+
end
187+
166188
def collect_gem_info gems
167189
gem_info = {}
168190
gems.each do |name|
@@ -205,7 +227,7 @@ def run_bazel gem_info
205227
bazel_alias = enable_bazelisk ? "bazelisk" : "bazel"
206228
gem_info.each_value do |info|
207229
info[:bazel_targets].each do |library_path, bazel_target|
208-
exec [bazel_alias, "build", "//#{library_path}:#{bazel_target}"], chdir: bazel_base_dir
230+
exec [bazel_alias, "build", "--verbose_failures", "//#{library_path}:#{bazel_target}"], chdir: bazel_base_dir
209231
end
210232
end
211233
source_dir = capture([bazel_alias, "info", "bazel-bin"], chdir: bazel_base_dir).chomp

0 commit comments

Comments
 (0)