bake-gem-github 0.3.0 → 0.3.1

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: cbf4137a4b137fec26486a02e3941687f2c5fc9ded9ab95eb95619657892e1ae
4
+ data.tar.gz: c4e2cf0281e703e2d2264e5b8f08420ba7afeb5f7819e075a196e9334f24a300
5
5
  SHA512:
6
- metadata.gz: 3919da7f3c6101666341e4d9af3b4176e400a2684b3f7cc996f8c04450b1398701512a5e5bbc9c00155d149178c1d17fc056353187a99789be8a4ab9c9a50ebb
7
- data.tar.gz: 22dbd706b01561188cb1ccf8aece57b417b6e8a5edef01c22efb0ee883c41048602a356a5b0abc91cac81b24d600bd9d6e37c8d47fe1dd13a71865336cdc94e5
6
+ metadata.gz: 2996e3c56f916e0d367c6fc75e3b7d9a478d8a08ee4d6d9bd775412978965c8c83d0b2608655d5d0c23776ce29af835cfa8dea4ec23ffb9e1afb3d0cefb74069
7
+ data.tar.gz: 4b78a2dd8d672b8831b8408e59494832ef45afee93489e9f27dc4aa7aae593f541350133886fa2f7957e2befee20abd4faa92b9df0b110620db78cdd1c1b2b01
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
 
@@ -111,6 +111,8 @@ git diff
111
111
 
112
112
  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
113
 
114
+ 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.
115
+
114
116
  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
117
 
116
118
  ## 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,6 +130,31 @@ 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.
133
160
  def doctor
@@ -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.3.1"
13
13
  end
14
14
  end
15
15
  end
data/readme.md CHANGED
@@ -24,6 +24,11 @@ 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.3.1
28
+
29
+ - Publish validated release PRs from pushes to the default branch, retaining the exact merged commit and environment approval without requiring `pull_request_target`.
30
+ - Queue publishing jobs without replacing pending releases when later changes land.
31
+
27
32
  ### v0.3.0
28
33
 
29
34
  - Configure publishing environment reviewers through release setup while preserving existing environment protections.
data/releases.md CHANGED
@@ -1,5 +1,10 @@
1
1
  # Releases
2
2
 
3
+ ## v0.3.1
4
+
5
+ - Publish validated release PRs from pushes to the default branch, retaining the exact merged commit and environment approval without requiring `pull_request_target`.
6
+ - Queue publishing jobs without replacing pending releases when later changes land.
7
+
3
8
  ## v0.3.0
4
9
 
5
10
  - 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.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samuel Williams
metadata.gz.sig CHANGED
Binary file