bake-gem-github 0.3.0 → 0.4.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da7e92debf8a08450ce8af6da25ed171d4961726d5949b9a0c737f3849c613eb
4
- data.tar.gz: 85459639500f5e4af61e4d305fe0442ddff853bb8530952385e89db39db6e69c
3
+ metadata.gz: 46cf12965bbeacaeb560e4ea719f9976543dca995fc1fde8a472ecb534327cd2
4
+ data.tar.gz: 0c8f8748fd2ef7c93bd3e6dd4ea185165db0e24209c8b33a176b0a58d00b9b41
5
5
  SHA512:
6
- metadata.gz: 3919da7f3c6101666341e4d9af3b4176e400a2684b3f7cc996f8c04450b1398701512a5e5bbc9c00155d149178c1d17fc056353187a99789be8a4ab9c9a50ebb
7
- data.tar.gz: 22dbd706b01561188cb1ccf8aece57b417b6e8a5edef01c22efb0ee883c41048602a356a5b0abc91cac81b24d600bd9d6e37c8d47fe1dd13a71865336cdc94e5
6
+ metadata.gz: 0db75dbe12482f9f9c601d6f2f8e473832186de8a1609e17f94b9c4876f90234e6273a4cf0d4a4a003ad9457591bd1d00f6aacb7de0bc5cddf621e61c76c5307
7
+ data.tar.gz: b0d57a706b49d95cccb9023efb014399c1039bc1a38528643e8aa7046516fe4341c2fdc9ac10d097a4429d23ecf7d19d6b5abdca5b3e048e3791eb80f9cda09d
checksums.yaml.gz.sig CHANGED
Binary file
@@ -26,16 +26,21 @@ def major(refresh: false)
26
26
  Bake::Gem::GitHub::Project.new(context.root).prepare(context, "major", refresh: refresh)
27
27
  end
28
28
 
29
- # Resolve and validate a merged PR, emitting a commit output for the publishing job.
30
- # @parameter number [String] The merged PR number; defaults to `RELEASE_PR`.
29
+ # Resolve and validate a pushed commit, emitting its merged PR and commit for publishing.
30
+ # @parameter number [String | Nil] A merged PR number for older workflows; defaults to `RELEASE_PR`.
31
+ # @parameter commit [String | Nil] The pushed commit SHA; defaults to `RELEASE_COMMIT` and takes precedence over `number`.
31
32
  # @returns [Hash | Nil] Release metadata, or nil for an ordinary PR.
32
- def resolve(number: ENV.fetch("RELEASE_PR"))
33
- result = Bake::Gem::GitHub::Project.new(context.root).inspect_release(number)
33
+ def resolve(number: ENV["RELEASE_PR"], commit: ENV["RELEASE_COMMIT"])
34
+ project = Bake::Gem::GitHub::Project.new(context.root)
35
+ result = commit ? project.inspect_commit(commit) : project.inspect_release(number)
34
36
 
35
37
  if path = ENV["GITHUB_OUTPUT"]
36
38
  File.open(path, "a") do |file|
37
39
  file.puts "release=#{!result.nil?}"
38
- file.puts "commit=#{result.fetch(:commit)}" if result
40
+ if result
41
+ file.puts "commit=#{result.fetch(:commit)}"
42
+ file.puts "pull_request=#{result.fetch(:pull_request)}"
43
+ end
39
44
  end
40
45
  end
41
46
 
@@ -4,7 +4,7 @@ This guide explains how to configure reviewed Ruby gem releases and prepare the
4
4
 
5
5
  ## How releases work
6
6
 
7
- Maintainers prepare a release PR containing the version bump and generated release notes. CI regenerates those changes from the current base to verify the content. Native GitHub rules control approval and merging; after merge, GitHub Actions builds the exact merged commit and publishes its verified artifact to RubyGems.
7
+ Maintainers prepare a release PR containing the version bump and generated release notes. CI regenerates those changes from the current base to verify the content. Native GitHub rules control approval and merging. A push to the default branch starts release inspection; GitHub Actions builds the exact pushed commit only when it is a validated, merged release PR, then publishes its verified artifact to RubyGems.
8
8
 
9
9
  `bake-gem` provides version updates, release hooks, and clean builds. `bake-gem-github` adds PR preparation, GitHub policy, and remote publishing. The supported process uses one gemspec, stable three-part versions, merge or squash merging, and RubyGems.org.
10
10
 
@@ -69,10 +69,14 @@ reviewers:
69
69
 
70
70
  Replace `your-org/managers` with your organization and team slug, for example `socketry/managers`. Individual user logins are also supported. Reviewers need at least read access to the repository. Setup resolves their GitHub IDs without changing repository access or team membership.
71
71
 
72
+ Reviewer teams must have **Visible** visibility in GitHub team settings. Plan and apply reject **Secret** teams before changing any settings, because GitHub can silently discard them from the environment reviewer list. Setup does not change team visibility.
73
+
72
74
  GitHub accepts one to six users or teams, and **one approval from any listed reviewer or team member is sufficient**. It does not support a minimum environment approval count. The default two PR approvals are independent of this publishing approval.
73
75
 
74
76
  Create the environment and restrict its deployment branch as described above before running plan or apply with reviewers configured. The plan previews the current and desired environment settings. Apply replaces its reviewer list while preserving its wait timer, self-review prevention, administrator bypass setting, and deployment branch restrictions. Custom deployment protection rules are managed separately and are not modified. Reapplying an identical reviewer list leaves the environment unchanged.
75
77
 
78
+ After updating the environment, apply reads its settings back and fails if the reviewer identities or preserved protections differ from the requested configuration. Reviewer order does not matter. Earlier updates may already have completed; inspect the environment in GitHub and rerun `gem:github:setup:plan` before retrying apply.
79
+
76
80
  Omitting `reviewers` leaves environment settings unmanaged, including any existing reviewer requirement. An empty list is rejected. To remove an existing requirement, change the environment settings explicitly in GitHub.
77
81
 
78
82
  The RubyGems Trusted Publisher must explicitly require the `rubygems` environment; leaving that field blank would allow this trusted publisher to authenticate jobs without the environment approval. Keep administrator bypass enabled if administrators should be able to explicitly authorize publication without a reviewer. Environment approvals are available for public repositories on GitHub Free.
@@ -111,6 +115,8 @@ git diff
111
115
 
112
116
  This updates managed files in the working tree and returns their changed paths. Review the diff and selectively retain repository customizations before committing. The task does not stage, commit, or change remote settings. Repeated updates produce no further changes unless customizations differ from the templates. Apply changed rulesets after the corresponding workflows are running.
113
117
 
118
+ Regenerate existing workflows to adopt publishing on `push` instead of `pull_request_target`. The workflow filename and `rubygems` environment remain the same, so the RubyGems Trusted Publisher configuration does not change. No exception to GitHub's `pull_request_target` execution policy is needed. The resolve task continues to accept PR numbers from older workflows while you migrate.
119
+
114
120
  The release workflows follow `bake modernize` action versions and use moving major tags where available. The RubyGems credentials action uses its [documented `@main` reference](https://github.com/rubygems/configure-rubygems-credentials#trusted-publisher-recommended). Repositories that require fixed revisions can customize these references.
115
121
 
116
122
  ## Current scope
@@ -21,6 +21,14 @@ Replace `patch` with `minor` or `major`. The wrapper fetches the default branch
21
21
 
22
22
  All release changes belong in the PR. Core preparation commits additions and deletions from release hooks but never pushes, tags or publishes. Validation independently generates the expected tree from the current base. A changed base SHA alone is fine; changed generated notes are not. Ordinary PRs with no version change pass release validation and still build unsigned.
23
23
 
24
+ ## Publish the merged release
25
+
26
+ Merging into the configured default branch triggers `release-publish.yaml` through its `push` event. Inspection uses the exact pushed SHA and resolves its associated PR through GitHub. Publication requires one matching merged PR in this repository, targeting the configured branch, with that exact merge commit. Ordinary changes do not publish; release changes without a matching merged PR fail inspection. Both merge commits and squash merges are supported, including merged fork PRs.
27
+
28
+ Each release must land as the tip of its own push, as it does when merging a PR through GitHub. Later pushes do not change a pending release's source: inspection and publishing remain pinned to the original commit, and reruns use the same event. Do not combine a release and later changes into one direct push. If you automate merging, use a GitHub App or personal access token; pushes made using a workflow's `GITHUB_TOKEN` do not trigger another workflow.
29
+
30
+ Only validated releases enter the publishing queue and request approval from the `rubygems` environment when required. Ordinary pushes cannot replace them in that queue. The publishing job retains the existing signing, attestation, and artifact recovery checks.
31
+
24
32
  ## Resume interrupted preparation
25
33
 
26
34
  If preparation stops after creating or pushing the release branch, return to the current default branch and repeat the same command. The existing branch is validated and reused, so retries do not create a second version bump or PR. Resolve any uncommitted changes before switching branches.
@@ -24,4 +24,6 @@ A rerun can recover an interrupted individual asset upload once `release.tar` is
24
24
 
25
25
  ## Understand workflow reruns
26
26
 
27
- GitHub concurrency does not guarantee a durable FIFO queue: rerun any publishing run displaced while pending. Resume reruns all jobs, including integrity checks; it does not repeat or second-guess the native review policy or a permitted administrator bypass. Older publishing runs execute their original code; adding this recovery support to the default branch does not change an already-triggered workflow.
27
+ Only publishing jobs share a concurrency group. They use `queue: max`, allowing up to 100 pending publishing jobs without replacing earlier ones; ordinary pushes only run inspection and do not enter this queue. GitHub cancels additional jobs if that limit is reached. Rerun a canceled publishing workflow after capacity becomes available.
28
+
29
+ Resume reruns all jobs against the original pushed commit, including integrity checks; it does not repeat or second-guess the native review policy or a permitted administrator bypass. Older publishing runs execute their original code and concurrency policy; updating the default branch does not change an already-triggered workflow.
@@ -111,10 +111,12 @@ module Bake
111
111
 
112
112
  # Resolve release identity; ordinary merged PRs do not publish.
113
113
  # @parameter number [String | Integer] The merged PR number.
114
+ # @parameter commit [String | Nil] The expected merge commit, when resolving a push event.
114
115
  # @returns [Hash | Nil] Release metadata with symbol keys, or nil for an ordinary PR. Includes `name`, `version`, `commit`, `base`, `bump`, `repository`, `pull_request`, `merged_by`, and `pull_request_url`.
115
116
  # @raises [RuntimeError] If the merged source does not match the independently generated release.
116
- def inspect_release(number)
117
+ def inspect_release(number, commit: nil)
117
118
  pr = merged(number)
119
+ raise "PR merge commit does not match the pushed commit." if commit && pr.fetch("merge_commit_sha") != commit
118
120
 
119
121
  commit = pr.fetch("merge_commit_sha")
120
122
  metadata = @release.validate(base: "#{commit}^1", candidate: commit, optional: true)
@@ -128,8 +130,34 @@ module Bake
128
130
  end
129
131
  end
130
132
 
133
+ # Resolve a pushed release commit to the PR which merged it into the configured branch.
134
+ # @parameter commit [String] The full commit SHA from the push event.
135
+ # @returns [Hash | Nil] Release metadata from {inspect_release}, or nil for an ordinary change.
136
+ # @raises [RuntimeError] If the commit is invalid or a release has no unique matching merged PR.
137
+ # @raises [Bake::Gem::CommandExecutionError] If Git or GitHub cannot verify the release.
138
+ def inspect_commit(commit)
139
+ raise "Expected a full pushed commit SHA." unless commit.match?(/\A(?:[0-9a-f]{40}|[0-9a-f]{64})\z/)
140
+ responses = readlines(
141
+ "gh", "api", "repos/#{@repository}/commits/#{commit}/pulls?per_page=100",
142
+ "--paginate", "--slurp", chdir: @root,
143
+ )
144
+ pulls = JSON.parse(responses.join).flatten(1).select do |pr|
145
+ pr["merged_at"] && pr["merge_commit_sha"] == commit &&
146
+ pr.dig("base", "ref") == @config.fetch("branch") && pr.dig("base", "repo", "full_name") == @repository
147
+ end
148
+
149
+ if pulls.empty?
150
+ return nil unless @release.validate(base: "#{commit}^1", candidate: commit, optional: true)
151
+ raise "Release commit has no matching merged PR."
152
+ end
153
+ raise "Multiple merged PRs match the pushed commit." if pulls.size > 1
154
+
155
+ return inspect_release(pulls.first.fetch("number"), commit: commit)
156
+ end
157
+
131
158
  # Return a read-only comparison of managed settings and current repository settings.
132
159
  # @returns [Hash] Desired rules, existing rules, environments, optional environment changes, and expected Trusted Publisher settings. This does not verify RubyGems ownership or publisher configuration.
160
+ # @raises [RuntimeError] If a reviewer team is secret or belongs to another organization.
133
161
  def doctor
134
162
  {
135
163
  desired_rules: Setup.rules(@config),
@@ -147,8 +175,9 @@ module Bake
147
175
 
148
176
  # Apply the named rulesets and configured reviewers for an existing environment. Invoke after reviewing doctor output.
149
177
  # Preserves the environment's wait timer, self-review prevention, administrator bypass, and branch restrictions.
178
+ # Reads back updated environment settings to verify GitHub retained them.
150
179
  # @returns [Hash] The desired ruleset payloads after successful application.
151
- # @raises [RuntimeError] If more than one existing ruleset has a managed name.
180
+ # @raises [RuntimeError] If a reviewer team is unsuitable, managed rulesets are ambiguous, or environment verification fails. Earlier updates may already have completed.
152
181
  # @raises [Bake::Gem::CommandExecutionError] If an API operation fails; earlier updates may already have completed.
153
182
  def apply
154
183
  changes = environment_changes
@@ -166,6 +195,9 @@ module Bake
166
195
 
167
196
  if changes && changes.fetch(:current) != changes.fetch(:desired)
168
197
  write_api("repos/#{@repository}/#{environment_path}", changes.fetch(:desired), method: "PUT")
198
+ unless environment_settings == changes.fetch(:desired)
199
+ raise "GitHub did not retain the requested settings for environment #{changes.fetch(:name)}. Check its reviewers and protection rules in GitHub, then rerun gem:github:setup:plan."
200
+ end
169
201
  end
170
202
 
171
203
  return rules
@@ -182,19 +214,26 @@ module Bake
182
214
  return nil unless @config.key?("reviewers")
183
215
  Setup.validate_reviewers(@config["reviewers"])
184
216
 
217
+ current = environment_settings
218
+ reviewers = @config.fetch("reviewers").map{|name| resolve_reviewer(name)}.uniq.sort_by{|reviewer| reviewer.values_at(:type, :id)}
219
+
220
+ return {name: @config.fetch("environment"), current: current, desired: current.merge(reviewers: reviewers)}
221
+ end
222
+
223
+ # Read the environment settings, comparing reviewer identities independently of their order.
224
+ def environment_settings
185
225
  environment = api(environment_path)
186
226
  protections = environment.fetch("protection_rules").to_h{|rule| [rule.fetch("type"), rule]}
187
227
  reviews = protections.fetch("required_reviewers", {})
188
- current = {
228
+ reviewers = reviews.fetch("reviewers", []).map{|entry| {type: entry.fetch("type"), id: entry.fetch("reviewer").fetch("id")}}
229
+
230
+ return {
189
231
  wait_timer: protections.fetch("wait_timer", {}).fetch("wait_timer", 0),
190
232
  prevent_self_review: reviews.fetch("prevent_self_review", false),
191
233
  can_admins_bypass: environment.fetch("can_admins_bypass"),
192
234
  deployment_branch_policy: environment.fetch("deployment_branch_policy"),
193
- reviewers: reviews.fetch("reviewers", []).map{|entry| {type: entry.fetch("type"), id: entry.fetch("reviewer").fetch("id")}},
235
+ reviewers: reviewers.uniq.sort_by{|reviewer| reviewer.values_at(:type, :id)},
194
236
  }
195
- reviewers = @config.fetch("reviewers").map{|name| resolve_reviewer(name)}
196
-
197
- return {name: @config.fetch("environment"), current: current, desired: current.merge(reviewers: reviewers)}
198
237
  end
199
238
 
200
239
  def resolve_reviewer(name)
@@ -208,6 +247,9 @@ module Bake
208
247
  type = "User"
209
248
  end
210
249
  response = JSON.parse(readlines("gh", "api", path, chdir: @root).join)
250
+ if type == "Team" && response.fetch("privacy") == "secret"
251
+ raise "Reviewer team #{name} is Secret. Change its visibility to Visible in GitHub team settings before running setup."
252
+ end
211
253
 
212
254
  return {type: type, id: response.fetch("id")}
213
255
  end
@@ -9,7 +9,7 @@ module Bake
9
9
  module Gem
10
10
  # GitHub pull request and release orchestration for bake-gem.
11
11
  module GitHub
12
- VERSION = "0.3.0"
12
+ VERSION = "0.4.0"
13
13
  end
14
14
  end
15
15
  end
data/readme.md CHANGED
@@ -24,6 +24,15 @@ Please see the [project documentation](https://socketry.github.io/bake-gem-githu
24
24
 
25
25
  Please see the [project releases](https://socketry.github.io/bake-gem-github/releases/index) for all releases.
26
26
 
27
+ ### v0.4.0
28
+
29
+ - Reject Secret environment reviewer teams before applying release settings, and verify that GitHub retained the requested reviewers and existing protections after updating the environment.
30
+
31
+ ### v0.3.1
32
+
33
+ - Publish validated release PRs from pushes to the default branch, retaining the exact merged commit and environment approval without requiring `pull_request_target`.
34
+ - Queue publishing jobs without replacing pending releases when later changes land.
35
+
27
36
  ### v0.3.0
28
37
 
29
38
  - Configure publishing environment reviewers through release setup while preserving existing environment protections.
data/releases.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Releases
2
2
 
3
+ ## v0.4.0
4
+
5
+ - Reject Secret environment reviewer teams before applying release settings, and verify that GitHub retained the requested reviewers and existing protections after updating the environment.
6
+
7
+ ## v0.3.1
8
+
9
+ - Publish validated release PRs from pushes to the default branch, retaining the exact merged commit and environment approval without requiring `pull_request_target`.
10
+ - Queue publishing jobs without replacing pending releases when later changes land.
11
+
3
12
  ## v0.3.0
4
13
 
5
14
  - Configure publishing environment reviewers through release setup while preserving existing environment protections.
@@ -40,7 +40,7 @@ jobs:
40
40
  bundler-cache: true
41
41
  - name: Create release PR
42
42
  env:
43
- GH_TOKEN: ${{ github.token }}
43
+ GITHUB_TOKEN: ${{ github.token }}
44
44
  BUMP: ${{ inputs.bump }}
45
45
  REFRESH: ${{ inputs.refresh }}
46
46
  run: |
@@ -1,34 +1,28 @@
1
1
  name: Publish release
2
2
 
3
- # Only merged source is executed. Validation of unmerged PRs lives in its own
4
- # read-only pull_request workflow. This trigger also supports reviewed fork PRs.
3
+ # Inspect the exact pushed commit and publish only a validated, merged release PR.
5
4
  on:
6
- pull_request_target:
7
- types: [closed]
5
+ push:
8
6
  branches: [<%= branch.to_json %>]
9
7
 
10
8
  permissions:
11
9
  contents: read
12
10
  pull-requests: read
13
11
 
14
- concurrency:
15
- group: release-publish
16
- cancel-in-progress: false
17
-
18
12
  env:
19
13
  BUNDLE_WITH: maintenance
20
- RELEASE_PR: ${{ github.event.pull_request.number }}
21
14
 
22
15
  jobs:
23
16
  inspect:
24
- if: github.event.pull_request.merged == true
25
17
  runs-on: ubuntu-latest
26
18
  outputs:
27
19
  release: ${{ steps.inspect.outputs.release }}
28
20
  commit: ${{ steps.inspect.outputs.commit }}
21
+ pull_request: ${{ steps.inspect.outputs.pull_request }}
29
22
  steps:
30
23
  - uses: actions/checkout@v7
31
24
  with:
25
+ ref: ${{ github.sha }}
32
26
  fetch-depth: 0
33
27
  persist-credentials: false
34
28
  - uses: ruby/setup-ruby@v1
@@ -37,7 +31,8 @@ jobs:
37
31
  bundler-cache: true
38
32
  - id: inspect
39
33
  env:
40
- GH_TOKEN: ${{ github.token }}
34
+ GITHUB_TOKEN: ${{ github.token }}
35
+ RELEASE_COMMIT: ${{ github.sha }}
41
36
  run: bundle exec bake gem:github:release:resolve
42
37
 
43
38
  publish:
@@ -45,6 +40,12 @@ jobs:
45
40
  if: needs.inspect.outputs.release == 'true'
46
41
  runs-on: ubuntu-latest
47
42
  environment: rubygems
43
+ concurrency:
44
+ group: release-publish
45
+ cancel-in-progress: false
46
+ queue: max
47
+ env:
48
+ RELEASE_PR: ${{ needs.inspect.outputs.pull_request }}
48
49
  permissions:
49
50
  contents: write
50
51
  pull-requests: read
@@ -55,8 +56,6 @@ jobs:
55
56
  - uses: actions/checkout@v7
56
57
  with:
57
58
  # Inspection verified this merged commit belongs to the default branch.
58
- # Checkout v7 also blocks merged fork PRs without this explicit opt-in.
59
- allow-unsafe-pr-checkout: true
60
59
  ref: ${{ needs.inspect.outputs.commit }}
61
60
  fetch-depth: 0
62
61
  persist-credentials: false
@@ -68,7 +67,7 @@ jobs:
68
67
  - name: Build or restore artifact
69
68
  id: build
70
69
  env:
71
- GH_TOKEN: ${{ github.token }}
70
+ GITHUB_TOKEN: ${{ github.token }}
72
71
  <% if signing -%>
73
72
  GEM_SIGNING_KEY: ${{ secrets.GEM_SIGNING_KEY }}
74
73
  <% end -%>
@@ -102,5 +101,5 @@ jobs:
102
101
  - uses: rubygems/configure-rubygems-credentials@main
103
102
  - name: Verify, publish, and finalize
104
103
  env:
105
- GH_TOKEN: ${{ github.token }}
104
+ GITHUB_TOKEN: ${{ github.token }}
106
105
  run: bundle exec bake gem:github:release:publish
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bake-gem-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file