toys-release 0.1.1 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/toys/_onclosed.rb CHANGED
@@ -88,7 +88,7 @@ def handle_release_merged
88
88
  @utils.error("GitHub checks failed", *github_check_errors)
89
89
  end
90
90
  performer = create_performer
91
- performer.perform_pr_releases
91
+ performer.perform_pr_releases unless performer.error?
92
92
  performer.report_results
93
93
  if performer.error?
94
94
  @utils.error("Releases reported failure")
data/toys/perform.rb CHANGED
@@ -106,11 +106,13 @@ def run
106
106
 
107
107
  setup_arguments
108
108
  setup_performer
109
- components.each do |component_spec|
110
- name, version = component_spec.split(/[:=]/, 2)
111
- confirmation_ui(name, version)
112
- gem_version = version ? ::Gem::Version.new(version) : nil
113
- @performer.perform_adhoc_release(name, assert_version: gem_version)
109
+ unless @performer.error?
110
+ components.each do |component_spec|
111
+ name, version = component_spec.split(/[:=]/, 2)
112
+ confirmation_ui(name, version)
113
+ gem_version = version ? ::Gem::Version.new(version) : nil
114
+ @performer.perform_adhoc_release(name, assert_version: gem_version)
115
+ end
114
116
  end
115
117
  puts @performer.build_report_text
116
118
  end
data/toys/retry.rb CHANGED
@@ -18,12 +18,13 @@ flag_group desc: "Flags" do
18
18
  "Run in dry-run mode, where checks are made and releases are built" \
19
19
  " but are not pushed."
20
20
  end
21
- flag :gh_pages_dir, "--gh-pages-dir=VAL" do
22
- desc "The directory to use for the gh-pages branch"
21
+ flag :work_dir, "--work-dir=VAL" do
22
+ desc "The directory to use for artifacts and temporary files"
23
23
  long_desc \
24
- "Set to the path of a directory to use as the gh-pages workspace when" \
25
- " building and pushing gem documentation. If left unset, a temporary" \
26
- " directory will be created (and removed when finished)."
24
+ "If provided, the given directory path is used for artifacts and" \
25
+ " temporary files, and is left intact after the release so the" \
26
+ " artifacts can be inspected. If omitted, a new temporary directory" \
27
+ " is created, and is automatically deleted after the release."
27
28
  end
28
29
  flag :git_remote, "--git-remote=VAL" do
29
30
  default "origin"
@@ -84,13 +85,13 @@ def setup_objects
84
85
  @repo_settings = Toys::Release::RepoSettings.load_from_environment(@utils)
85
86
  @repository = Toys::Release::Repository.new(@utils, @repo_settings)
86
87
  @repository.git_set_user_info
88
+ @pull_request = @repository.load_pr(release_pr)
87
89
  end
88
90
 
89
91
  def verify_release_pr
90
- @pr_info = @repository.load_pr(release_pr)
91
- @utils.error("Could not load pull request ##{release_pr}") unless @pr_info
92
+ @utils.error("Could not load pull request ##{release_pr}") unless @pull_request
92
93
  expected_labels = [@repo_settings.release_pending_label, @repo_settings.release_error_label]
93
- return if @pr_info["labels"].any? { |label| expected_labels.include?(label["name"]) }
94
+ return if @pull_request.labels.any? { |label| expected_labels.include?(label) }
94
95
  warning = "PR #{release_pr} doesn't have the release pending or release error label."
95
96
  if yes
96
97
  logger.warn(warning)
@@ -102,12 +103,17 @@ def verify_release_pr
102
103
  end
103
104
 
104
105
  def setup_params
105
- [:gh_pages_dir, :rubygems_api_key].each do |key|
106
+ [
107
+ :git_remote,
108
+ :release_ref,
109
+ :rubygems_api_key,
110
+ :work_dir,
111
+ ].each do |key|
106
112
  set(key, nil) if get(key).to_s.empty?
107
113
  end
108
- ::ENV["GEM_HOST_API_KEY"] = rubygems_api_key if rubygems_api_key
109
114
  set(:dry_run, /^t/i.match?(::ENV["TOYS_RELEASE_DRY_RUN"].to_s)) if dry_run.nil?
110
- set :release_ref, @repository.current_sha(release_ref || @pr_info["merge_commit_sha"])
115
+ ::ENV["GEM_HOST_API_KEY"] = rubygems_api_key if rubygems_api_key
116
+ set :release_ref, @repository.current_sha(release_ref || @pull_request.merge_commit_sha)
111
117
  end
112
118
 
113
119
  def create_performer
@@ -116,14 +122,14 @@ def create_performer
116
122
  release_pr: release_pr,
117
123
  enable_prechecks: enable_prechecks,
118
124
  git_remote: git_remote,
119
- gh_pages_dir: gh_pages_dir,
125
+ work_dir: work_dir,
120
126
  dry_run: dry_run)
121
127
  end
122
128
 
123
129
  def perform_pending_releases
124
- @repository.wait_github_checks(release_ref) if enable_prechecks
130
+ @repository.wait_github_checks(ref: release_ref) if enable_prechecks
125
131
  performer = create_performer
126
- performer.perform_pr_releases
132
+ performer.perform_pr_releases unless performer.error?
127
133
  performer.report_results
128
134
  if performer.error?
129
135
  @utils.error("Releases reported failure")
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toys-release
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Azuma
@@ -48,7 +48,6 @@ files:
48
48
  - toys/.data/templates/gh-pages-gitignore.erb
49
49
  - toys/.data/templates/gh-pages-index.html.erb
50
50
  - toys/.data/templates/release-hook-on-closed.yml.erb
51
- - toys/.data/templates/release-hook-on-open.yml.erb
52
51
  - toys/.data/templates/release-hook-on-push.yml.erb
53
52
  - toys/.data/templates/release-perform.yml.erb
54
53
  - toys/.data/templates/release-request.yml.erb
@@ -59,6 +58,7 @@ files:
59
58
  - toys/.lib/toys/release/component.rb
60
59
  - toys/.lib/toys/release/environment_utils.rb
61
60
  - toys/.lib/toys/release/performer.rb
61
+ - toys/.lib/toys/release/pipeline.rb
62
62
  - toys/.lib/toys/release/pull_request.rb
63
63
  - toys/.lib/toys/release/repo_settings.rb
64
64
  - toys/.lib/toys/release/repository.rb
@@ -69,7 +69,6 @@ files:
69
69
  - toys/.lib/toys/release/version_rb_file.rb
70
70
  - toys/.toys.rb
71
71
  - toys/_onclosed.rb
72
- - toys/_onopen.rb
73
72
  - toys/_onpush.rb
74
73
  - toys/create-labels.rb
75
74
  - toys/gen-gh-pages.rb
@@ -82,10 +81,10 @@ homepage: https://github.com/dazuma/toys
82
81
  licenses:
83
82
  - MIT
84
83
  metadata:
85
- changelog_uri: https://dazuma.github.io/toys/gems/toys-release/v0.1.1/file.CHANGELOG.html
84
+ changelog_uri: https://dazuma.github.io/toys/gems/toys-release/v0.2.2/file.CHANGELOG.html
86
85
  source_code_uri: https://github.com/dazuma/toys/tree/main/toys-release
87
86
  bug_tracker_uri: https://github.com/dazuma/toys/issues
88
- documentation_uri: https://dazuma.github.io/toys/gems/toys-release/v0.1.1
87
+ documentation_uri: https://dazuma.github.io/toys/gems/toys-release/v0.2.2
89
88
  rdoc_options: []
90
89
  require_paths:
91
90
  - lib
@@ -1,30 +0,0 @@
1
- name: "[release hook] Check commit messages"
2
-
3
- on:
4
- pull_request_target:
5
- types: [opened, edited, synchronize, reopened]
6
-
7
- jobs:
8
- release-check-commits:
9
- if: ${{ github.repository == '<%= @settings.repo_path %>' }}
10
- env:
11
- ruby_version: "3.4"
12
- runs-on: ubuntu-latest
13
- steps:
14
- - name: Install Ruby ${{ env.ruby_version }}
15
- uses: ruby/setup-ruby@v1
16
- with:
17
- ruby-version: ${{ env.ruby_version }}
18
- - name: Checkout repo
19
- uses: actions/checkout@v5
20
- with:
21
- ref: refs/pull/${{ github.event.pull_request.number }}/merge
22
- - name: Install Toys
23
- run: "gem install --no-document toys"
24
- - name: Check commit messages
25
- env:
26
- GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
27
- run: |
28
- toys release _onopen --verbose \
29
- "--event-path=${{ github.event_path }}" \
30
- < /dev/null
data/toys/_onopen.rb DELETED
@@ -1,158 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- desc "Check a pull request"
4
-
5
- long_desc \
6
- "This tool is called by a GitHub Actions workflow when any pull request" \
7
- " is opened or synchronized. It checks the commit messages and/or pull" \
8
- " request title (as appropriate) for conventional commit style."
9
-
10
- flag :event_path, "--event-path=VAL" do
11
- default ::ENV["GITHUB_EVENT_PATH"]
12
- desc "Path to the pull request event JSON file"
13
- end
14
-
15
- include :exec
16
- include :terminal, styled: true
17
-
18
- def run
19
- setup
20
- lint_commit_messages if @utils.commit_lint_active?
21
- end
22
-
23
- def setup
24
- ::Dir.chdir(context_directory)
25
-
26
- require "json"
27
- require "toys/release/environment_utils"
28
- require "toys/release/pull_request"
29
- require "toys/release/repo_settings"
30
- require "toys/release/repository"
31
-
32
- @utils = Toys::Release::EnvironmentUtils.new(self)
33
- @settings = Toys::Release::RepoSettings.load_from_environment(@utils)
34
- @repository = Toys::Release::Repository.new(@utils, @settings)
35
-
36
- @utils.error("GitHub event path missing") unless event_path
37
- pr_resource = ::JSON.parse(::File.read(event_path))["pull_request"]
38
- @pull_request = Toys::Release::PullRequest.new(@repository, pr_resource)
39
- end
40
-
41
- def lint_commit_messages
42
- errors = []
43
- shas = find_shas
44
- if shas.size == 1 || !@settings.commit_lint_merge.intersection(["merge", "rebase"]).empty?
45
- lint_sha_messages(shas, errors)
46
- end
47
- if shas.size > 1 && @settings.commit_lint_merge.include?("squash")
48
- lint_pr_message(errors)
49
- end
50
- if errors.empty?
51
- puts "No conventional commit format problems found.", :green, :bold
52
- else
53
- report_lint_errors(errors)
54
- if @settings.commit_lint_fail_checks?
55
- @utils.error("Failing due to conventional commit format problems")
56
- end
57
- end
58
- end
59
-
60
- def find_shas
61
- @repository.git_unshallow("origin", branch: @pull_request.head_sha)
62
- log = capture(["git", "log", "#{@pull_request.base_sha}..#{@pull_request.head_sha}", "--format=%H"], e: true)
63
- shas = log.split("\n").reverse
64
- shas.find_all do |sha|
65
- parents = capture(["git", "show", "-s", "--pretty=%p", sha], e: true).strip.split
66
- @utils.log("Omitting merge commit #{sha}") if parents.size > 1
67
- parents.size == 1
68
- end
69
- end
70
-
71
- def lint_sha_messages(shas, errors)
72
- shas.each do |sha|
73
- @utils.log("Checking commit #{sha} ...")
74
- message = capture(["git", "log", "#{sha}^..#{sha}", "--format=%B"], e: true).strip
75
- lint_message(message) do |err|
76
- @utils.warning("Commit #{sha}: #{err}")
77
- suggestion = "Please consider amending the commit message."
78
- if @settings.commit_lint_merge == ["squash"]
79
- suggestion += " Alternately, because this pull request will be squashed when merged, you" \
80
- " can add multiple commits, and instead make sure the pull request _title_" \
81
- " conforms to the Conventional Commit format."
82
- end
83
- err =
84
- [
85
- "The message for commit #{sha} does not conform to the Conventional Commit format.",
86
- "",
87
- "```",
88
- ] + message.split("\n") + [
89
- "```",
90
- "",
91
- err,
92
- suggestion,
93
- ]
94
- errors << err
95
- end
96
- end
97
- end
98
-
99
- def lint_pr_message(errors)
100
- @utils.log("Checking Pull request title ...")
101
- lint_message(@pull_request.title) do |err|
102
- @utils.warning("PR title: #{err}")
103
- header = "The pull request title does not conform to the Conventional Commit format."
104
- header +=
105
- if @settings.commit_lint_merge == ["squash"]
106
- " (The title will be used as the merge commit message when this pull request is merged.)"
107
- else
108
- " (The title may be used as the merge commit message if this pull request is squashed" \
109
- " when merged.)"
110
- end
111
- errors << [
112
- header,
113
- "",
114
- "```",
115
- @pull_request.title,
116
- "```",
117
- "",
118
- err,
119
- ]
120
- end
121
- end
122
-
123
- def lint_message(message)
124
- lines = message.split("\n")
125
- matches = /^([\w-]+)(?:\(([^()]+)\))?!?:\s(.+)$/.match(lines.first)
126
- unless matches
127
- yield "The first line should follow the form `<type>: <description>`."
128
- return
129
- end
130
- allowed_types = @settings.commit_lint_allowed_types
131
- if allowed_types && !allowed_types.include?(matches[1].downcase)
132
- yield "The type `#{matches[1]}` is not allowed by this repository." \
133
- " Please use one of the types: `#{allowed_types.inspect}`."
134
- end
135
- if lines.size > 1 && !lines[1].empty?
136
- yield "You may not use multiple conventional commit formatted lines." \
137
- " If you want to include a body or footers in your commit message," \
138
- " they must be separated from the main message by a blank line." \
139
- " If you are making multiple semantic changes, please use separate" \
140
- " commits/pull requets."
141
- end
142
- end
143
-
144
- def report_lint_errors(errors)
145
- header = <<~STR
146
- Please use [Conventional Commit](https://conventionalcommits.org/) format \
147
- for commit messages and pull request titles. The automated linter found \
148
- the following problems in this pull request:
149
- STR
150
- lines = [header]
151
- errors.each do |error_lines|
152
- lines << "" << " * #{error_lines.first}"
153
- error_lines[1..].each do |err_line|
154
- lines << (err_line.empty? ? "" : " #{err_line}")
155
- end
156
- end
157
- @pull_request.add_comment(lines.join("\n"))
158
- end