Skip to content

Commit

Permalink
chore: Update generation script (#8291)
Browse files Browse the repository at this point in the history
  • Loading branch information
dazuma authored Feb 8, 2022
1 parent 390be35 commit 314c69d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 9 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/generate-updates.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: Generate-Updates
on:
# schedule:
# - cron: '02 11 * * *'
schedule:
- cron: '02 11 * * *'
workflow_dispatch:
inputs:
args:
Expand Down
32 changes: 25 additions & 7 deletions .toys/generate-updates.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
include :terminal

def run
require "json"
require "pull_request_generator"
extend PullRequestGenerator
ensure_pull_request_generation_dependencies
Expand All @@ -37,8 +38,9 @@ def run
end

@timestamp = Time.now.utc.strftime("%Y%m%d-%H%M%S")
list_apis_versions.each do |(api, version)|
pr_single_gem api, version
apis_versions = list_apis_versions
apis_versions.each_with_index do |(api, version), index|
pr_single_gem api, version, index + 1, apis_versions.size
end
pr_clean_old_gems
end
Expand All @@ -52,25 +54,35 @@ def list_apis_versions
apis_versions.compact.shuffle
end

def pr_single_gem api, version
def pr_single_gem api, version, index, total
branch_name = "gen/#{api}-#{version}-#{@timestamp}"
commit_message = "feat: Automated regeneration of #{api} #{version} client"
if open_pr_exists? commit_message
puts "(#{index}/#{total}) Pull request already exists for google-apis-#{api}_#{version}", :yellow
return
end
result = generate_pull_request git_remote: git_remote,
branch_name: branch_name,
commit_message: commit_message do
regen_single_gem api, version
end
case result
when :opened
puts "Opened pull request for google-apis-#{api}_#{version}", :green, :bold
when :uknchanged
puts "No changes for google-apis-#{api}_#{version}", :magenta
puts "(#{index}/#{total}) Opened pull request for google-apis-#{api}_#{version}", :green, :bold
when :unchanged
puts "(#{index}/#{total}) No changes for google-apis-#{api}_#{version}", :magenta
else
puts "(#{index}/#{total}) Generated google-apis-#{api}_#{version}", :cyan
end
end

def pr_clean_old_gems
branch_name = "gen/clean-#{@timestamp}"
commit_message = "feat: Automated cleanup of obsolete clients"
if open_pr_exists? commit_message
puts "Pull request already exists for cleaning obsolete gems", :yellow
return
end
result = generate_pull_request git_remote: git_remote,
branch_name: branch_name,
commit_message: commit_message do
Expand All @@ -79,11 +91,17 @@ def pr_clean_old_gems
case result
when :opened
puts "Opened pull request for cleaning obsolete gems", :green, :bold
when :uknchanged
when :unchanged
puts "No obsolete gems to clean", :magenta
end
end

def open_pr_exists? title
content = capture ["gh", "pr", "list", "--search", "\"#{title}\" in:title", "--state=open", "--json=number"]
result = JSON.parse content
!result.empty?
end

def regen_single_gem api, version
Dir.chdir "#{context_directory}/google-apis-generator" do
cmd = [
Expand Down

0 comments on commit 314c69d

Please sign in to comment.