Skip to content

Commit 2c24660

Browse files
authored
chore: Include release-please bootstrap in new-library script (googleapis#20998)
1 parent 65767fb commit 2c24660

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

.github/workflows/new-library.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ jobs:
1717
steps:
1818
- name: Checkout repo
1919
uses: actions/checkout@v3
20-
- name: Install Ruby 3.0
20+
- name: Install Ruby 3.1
2121
uses: ruby/setup-ruby@v1
2222
with:
23-
ruby-version: "3.0"
23+
ruby-version: "3.1"
2424
- name: Install tools
2525
run: |
2626
git config --global user.email "70984784+yoshi-code-bot@users.noreply.github.com"
2727
git config --global user.name "Yoshi Code Bot"
2828
gem install --no-document toys
2929
- name: Create library
3030
run: |
31-
toys new-library -v --pull --test --remote=origin ${{ github.event.inputs.protoPath }}
31+
toys new-library -v --pull --test --remote=origin --bootstrap-releases ${{ github.event.inputs.protoPath }}

.toys/new-library.rb

Lines changed: 43 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@
2727
flag :source_path, "--source-path=PATH" do
2828
desc "Path to the googleapis-gen source repo"
2929
end
30-
flag :pull do
30+
flag :pull, "--[no-]pull" do
3131
desc "Pull the latest owlbot images before running"
3232
end
33-
flag :interactive, "--interactive", "-i" do
33+
flag :interactive, "--[no-]interactive", "-i" do
3434
desc "Run in interactive mode, including editing of the .owlbot.rb file"
3535
end
3636
flag :editor do
@@ -43,9 +43,15 @@
4343
flag :git_remote, "--remote NAME" do
4444
desc "The name of the git remote to use as the pull request head. If omitted, does not open a pull request."
4545
end
46-
flag :enable_tests, "--test" do
46+
flag :enable_tests, "--[no-]test" do
4747
desc "Run CI on the newly-created library"
4848
end
49+
flag :bootstrap_releases, "--[no-]bootstrap-releases" do
50+
desc "Also add release-please configuration for the newly-created library"
51+
end
52+
53+
static :config_name, "release-please-config.json"
54+
static :manifest_name, ".release-please-manifest.json"
4955

5056
include :exec, e: true
5157
include :fileutils
@@ -64,6 +70,7 @@ def run
6470
write_owlbot_config
6571
write_owlbot_script
6672
call_owlbot
73+
create_release_please_configs if bootstrap_releases
6774
test_library if enable_tests
6875
end
6976
end
@@ -118,6 +125,39 @@ def call_owlbot
118125
exec_tool cmd
119126
end
120127

128+
def create_release_please_configs
129+
manifest = JSON.parse File.read manifest_name
130+
manifest[gem_name] = "0.0.1"
131+
manifest = add_fillers(manifest).sort.to_h
132+
File.write manifest_name, "#{JSON.pretty_generate manifest}\n"
133+
134+
config = JSON.parse File.read config_name
135+
config["packages"][gem_name] = {
136+
"component" => gem_name,
137+
"version_file" => gem_version_file
138+
}
139+
config["packages"] = config["packages"].sort.to_h
140+
File.write config_name, "#{JSON.pretty_generate config}\n"
141+
end
142+
143+
def gem_version_file
144+
@gem_version_file ||= begin
145+
version_path = gem_name.tr "-", "/"
146+
version_file = File.join "lib", version_path, "version.rb"
147+
version_file_full = File.join gem_name, version_file
148+
raise "Unable to find #{version_file_full}" unless File.file? version_file_full
149+
version_file
150+
end
151+
@gem_version_file
152+
end
153+
154+
def add_fillers manifest
155+
manifest.keys.each do |key|
156+
manifest["#{key}+FILLER"] = "0.0.0" unless key.end_with? "+FILLER"
157+
end
158+
manifest
159+
end
160+
121161
def test_library
122162
Dir.chdir gem_name do
123163
exec ["bundle", "install"]

.toys/release.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ def update_manifest_files
8989
}
9090
end
9191
end
92-
config["packages"] = sort_hash config_packages
93-
manifest = sort_hash add_fillers manifest
92+
config["packages"] = config_packages.sort.to_h
93+
manifest = add_fillers(manifest).sort.to_h
9494
puts "Added #{added_count} packages (#{already_present_count} already present)", :bold
9595

9696
File.open config_name, "w" do |file|
@@ -108,14 +108,6 @@ def add_fillers manifest
108108
manifest
109109
end
110110

111-
def sort_hash original
112-
result = {}
113-
original.keys.sort.each do |key|
114-
result[key] = original[key]
115-
end
116-
result
117-
end
118-
119111
def find_all_packages
120112
found = Dir.glob("*/*.gemspec").map { |path| File.dirname path }
121113
set :packages, found

0 commit comments

Comments
 (0)