|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Copyright 2021 Google LLC |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +desc "Runs release-please." |
| 18 | + |
| 19 | +flag :github_token, "--github-token=TOKEN", default: ENV["GITHUB_TOKEN"] |
| 20 | +flag :install |
| 21 | +remaining_args :gems, desc: "Release the specified gems. If no specific gem is provided, all gems are checked." |
| 22 | + |
| 23 | +include :exec, e: true |
| 24 | +include :terminal, styled: true |
| 25 | + |
| 26 | +def run |
| 27 | + Dir.chdir context_directory |
| 28 | + if install |
| 29 | + exec ["npm", "install", "release-please"] |
| 30 | + exit |
| 31 | + end |
| 32 | + if gems.empty? |
| 33 | + set :gems, Dir.glob("*/*.gemspec").map { |path| File.dirname path } |
| 34 | + end |
| 35 | + gems.each { |gem_name| release_please gem_name } |
| 36 | +end |
| 37 | + |
| 38 | +def release_please gem_name |
| 39 | + version = gem_version gem_name |
| 40 | + puts "Running release-please for #{gem_name} from version #{version}", :bold |
| 41 | + cmd = [ |
| 42 | + "npx", "release-please", "release-pr", |
| 43 | + "--package-name", gem_name, |
| 44 | + "--last-package-version", version, |
| 45 | + "--release-type", "ruby-yoshi", |
| 46 | + "--repo-url", "googleapis/google-cloud-ruby", |
| 47 | + "--bump-minor-pre-major" |
| 48 | + ] |
| 49 | + cmd += ["--token", github_token] if github_token |
| 50 | + log_cmd = cmd.inspect |
| 51 | + log_cmd.sub! github_token, "****" if github_token |
| 52 | + exec cmd, log_cmd: log_cmd |
| 53 | +end |
| 54 | + |
| 55 | +def gem_version gem_name |
| 56 | + func = proc do |
| 57 | + Dir.chdir gem_name do |
| 58 | + spec = Gem::Specification.load "#{gem_name}.gemspec" |
| 59 | + puts spec.version.to_s |
| 60 | + end |
| 61 | + end |
| 62 | + capture_proc(func).strip |
| 63 | +end |
0 commit comments