bake-gem-github 0.0.3

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.
@@ -0,0 +1,111 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ require "bake/gem/release"
7
+ require "yaml"
8
+ require "tempfile"
9
+ require_relative "setup"
10
+
11
+ module Bake
12
+ module Gem
13
+ module GitHub
14
+ # GitHub operations invoked by local tasks and repository workflows.
15
+ class Project
16
+ include Shell
17
+
18
+ # Load the reviewed repository release policy.
19
+ def initialize(root)
20
+ @root = File.expand_path(root)
21
+ @config = YAML.safe_load_file(File.join(@root, "config/release.yaml"))
22
+ raise "Unsupported release configuration." unless @config.fetch("schema") == 1
23
+ @repository = @config.fetch("repository")
24
+ @release = Release.new(@root)
25
+ end
26
+
27
+ # @attribute [Hash] Reviewed desired policy.
28
+ attr_reader :config
29
+
30
+ # Execute a GitHub API read. Failures never imply that a resource is absent.
31
+ def api(path)
32
+ JSON.parse(readlines("gh", "api", "repos/#{@repository}/#{path}", chdir: @root).join)
33
+ end
34
+
35
+ # Prepare a release through core Bake tasks, then push and create its pull request.
36
+ def prepare(context, bump)
37
+ Release::BUMPS.fetch(bump)
38
+ helper = Helper.new(@root)
39
+ helper.guard_clean
40
+ branch = @config.fetch("branch")
41
+ raise "Prepare releases from #{branch}." unless helper.current_branch == branch
42
+ system("git", "fetch", "origin", branch, "--tags", chdir: @root)
43
+ raise "Local branch differs from origin/#{branch}." unless @release.resolve("HEAD") == @release.resolve("origin/#{branch}")
44
+ pulls = JSON.parse(readlines("gh", "pr", "list", "--repo", @repository, "--base", branch, "--state", "open", "--json", "headRefName,url", "--limit", "1000", chdir: @root).join)
45
+ if existing = pulls.find{|pr| pr.fetch("headRefName").start_with?("releases/v")}
46
+ return existing.fetch("url")
47
+ end
48
+ base = @release.resolve("HEAD")
49
+ result = context.lookup("gem:release:branch:#{bump}").call
50
+ @release.validate(base: base)
51
+ system("git", "-c", "credential.helper=", "-c", "credential.helper=!gh auth git-credential", "push", "--set-upstream", "origin", result.fetch(:branch), chdir: @root)
52
+ body = "Release #{helper.gemspec.name} #{result.fetch(:version)}.\n\nPrepared from #{base}. The complete release tree is regenerated during validation. Merging publishes the resulting commit through release-publish.yaml after native reviews and required CI (or explicit administrator bypass).\n"
53
+ Tempfile.create("release-pr") do |file|
54
+ file.write(body)
55
+ file.flush
56
+ readlines("gh", "pr", "create", "--repo", @repository, "--base", branch, "--head", result.fetch(:branch), "--title", "Release v#{result.fetch(:version)}", "--body-file", file.path, chdir: @root).join.strip
57
+ end
58
+ end
59
+
60
+ # Resolve a merged PR through GitHub, and require its actual merge commit in default-branch history.
61
+ def merged(number)
62
+ raise "Expected a PR number." unless number.to_s.match?(/\A[1-9]\d*\z/)
63
+ pr = api("pulls/#{number}")
64
+ raise "PR must be merged into the configured branch." unless pr["merged"] && pr.dig("base", "ref") == @config.fetch("branch") && pr.dig("base", "repo", "full_name") == @repository
65
+ commit = pr.fetch("merge_commit_sha")
66
+ raise "Invalid merged commit." unless commit.match?(/\A[0-9a-f]{40,64}\z/)
67
+ system("git", "fetch", "origin", @config.fetch("branch"), "--tags", chdir: @root)
68
+ system("git", "merge-base", "--is-ancestor", commit, "origin/#{@config.fetch('branch')}", chdir: @root)
69
+ pr
70
+ end
71
+
72
+ # Resolve release identity; ordinary merged PRs do not publish.
73
+ def inspect_release(number)
74
+ pr = merged(number)
75
+ commit = pr.fetch("merge_commit_sha")
76
+ metadata = @release.validate(base: "#{commit}^1", candidate: commit, optional: true)
77
+ if metadata
78
+ metadata.merge(repository: @repository, pull_request: pr.fetch("number"), merged_by: pr.dig("merged_by", "login"), pull_request_url: pr.fetch("html_url"))
79
+ end
80
+ end
81
+
82
+ # Return a read-only comparison of managed settings and current repository settings.
83
+ def doctor
84
+ {
85
+ desired_rules: Setup.rules(@config),
86
+ existing_rules: api("rulesets?per_page=100"),
87
+ environments: api("environments"),
88
+ trusted_publisher: {repository_owner: @repository.split("/").first, repository_name: @repository.split("/").last, workflow_filename: "release-publish.yaml", environment: @config.fetch("environment")}
89
+ }
90
+ end
91
+
92
+ # Apply only the named rulesets generated by setup. Invoke after reviewing doctor output.
93
+ def apply
94
+ existing = api("rulesets?per_page=100")
95
+ Setup.rules(@config).each_value do |rule|
96
+ matches = existing.select{|current| current.fetch("name") == rule.fetch(:name)}
97
+ raise "Multiple rulesets match #{rule[:name]}." if matches.size > 1
98
+ current = matches.first
99
+ path = "repos/#{@repository}/rulesets"
100
+ path += "/#{current.fetch('id')}" if current
101
+ Tempfile.create("release-rule") do |file|
102
+ file.write(JSON.generate(rule))
103
+ file.flush
104
+ system("gh", "api", path, "--method", current ? "PUT" : "POST", "--input", file.path, chdir: @root)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
111
+ end
@@ -0,0 +1,215 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ require_relative "project"
7
+ require "digest"
8
+ require "net/http"
9
+ require "openssl"
10
+
11
+ module Bake
12
+ module Gem
13
+ module GitHub
14
+ # Builds one artifact, preserves it before upload, and resumes without moving existing tags.
15
+ class Publisher < Project
16
+ # Build or restore this workflow run's artifact, after validating the actual merged commit.
17
+ def build(number)
18
+ guard_environment
19
+ evidence = inspect_release(number) or raise "PR does not change the version."
20
+ raise "Checkout must match the merged commit." unless @release.resolve("HEAD") == evidence.fetch(:commit)
21
+ path = File.join(@root, "pkg")
22
+ FileUtils.mkdir_p(path)
23
+ artifact = "release-#{evidence.fetch(:commit)}"
24
+ run = ENV.fetch("GITHUB_RUN_ID")
25
+ artifacts = api("actions/runs/#{run}/artifacts?per_page=100").fetch("artifacts")
26
+ if retained = artifacts.find{|entry| entry.fetch("name") == artifact}
27
+ raise "Retained artifact expired; restore it from the GitHub release before retrying." if retained.fetch("expired")
28
+ system("gh", "run", "download", run, "--repo", @repository, "--name", artifact, "--dir", path, chdir: @root)
29
+ receipt = load_receipt
30
+ [:name, :version, :commit, :repository, :pull_request].each do |key|
31
+ raise "Retained artifact has different #{key}." unless receipt[key] == evidence[key]
32
+ end
33
+ return output(receipt, restored: true)
34
+ end
35
+ filename = "#{evidence.fetch(:name)}-#{evidence.fetch(:version)}.gem"
36
+ if registry_digest(evidence.fetch(:name), evidence.fetch(:version))
37
+ raise "Version is already published but this run has no retained artifact. Restore the original artifact; do not rebuild."
38
+ end
39
+ package = build_package(path)
40
+ raise "Unexpected package filename." unless File.basename(package) == filename
41
+ receipt = evidence.merge(file: filename, sha256: Digest::SHA256.file(package).hexdigest, run_id: run, signing: @config.fetch("signing"))
42
+ File.write(File.join(path, "release.json"), JSON.pretty_generate(receipt) + "\n")
43
+ output(receipt, restored: false)
44
+ end
45
+
46
+ # Verify both attestations, upload exactly those bytes, then create only the intended tag and release.
47
+ def publish(number)
48
+ guard_environment
49
+ receipt = load_receipt
50
+ pr = merged(number)
51
+ raise "Artifact is not for this merged PR." unless receipt[:commit] == pr.fetch("merge_commit_sha") && receipt[:pull_request] == pr.fetch("number") && receipt[:repository] == @repository
52
+ raise "Checkout must match the artifact source." unless @release.resolve("HEAD") == receipt[:commit]
53
+ metadata = @release.validate(base: "#{receipt[:commit]}^1", candidate: receipt[:commit])
54
+ [:name, :version, :commit].each do |key|
55
+ raise "Artifact #{key} differs from the merged source." unless receipt[key] == metadata[key]
56
+ end
57
+ package = File.join(@root, "pkg", receipt.fetch(:file))
58
+ verify_certificate(package) if @config.fetch("signing")
59
+ bundle = "#{package}.sigstore.json"
60
+ identity = "https://github.com/#{@repository}/.github/workflows/release-publish.yaml@refs/heads/#{@config.fetch('branch')}"
61
+ gem_command("exec", "sigstore-cli:0.2.3", "verify", package, "--bundle", bundle, "--certificate-identity", identity, "--certificate-oidc-issuer", "https://token.actions.githubusercontent.com")
62
+ verify_provenance(package)
63
+ tag = "v#{receipt.fetch(:version)}"
64
+ guard_tag(tag, receipt.fetch(:commit))
65
+ remote_digest = registry_digest(receipt.fetch(:name), receipt.fetch(:version))
66
+ if remote_digest
67
+ raise "Published version has different bytes." unless remote_digest == receipt.fetch(:sha256)
68
+ else
69
+ gem_command("push", package, "--host", "https://rubygems.org", "--attestation", bundle)
70
+ end
71
+ # A failed read after upload is recoverable by rerunning the same workflow.
72
+ raise "Registry artifact does not match; retry after registry propagation." unless registry_digest(receipt.fetch(:name), receipt.fetch(:version)) == receipt.fetch(:sha256)
73
+ attestations = registry_get("https://rubygems.org/api/v1/attestations/#{receipt.fetch(:name)}-#{receipt.fetch(:version)}.json")
74
+ raise "Registry attestation is missing." unless attestations
75
+ registry_bundles = JSON.parse(attestations)
76
+ local_bundle = JSON.parse(File.read(bundle))
77
+ raise "Registry does not contain this artifact's Sigstore bundle." unless contains_bundle?(registry_bundles, local_bundle)
78
+ unless readlines("git", "tag", "--list", tag, chdir: @root).any?
79
+ system("git", "tag", tag, receipt.fetch(:commit), chdir: @root)
80
+ end
81
+ system("git", "-c", "credential.helper=", "-c", "credential.helper=!gh auth git-credential", "push", "origin", "refs/tags/#{tag}", chdir: @root)
82
+ releases = JSON.parse(readlines("gh", "release", "list", "--repo", @repository, "--limit", "1000", "--json", "tagName", chdir: @root).join)
83
+ unless releases.any?{|entry| entry.fetch("tagName") == tag}
84
+ Tempfile.create("release-notes") do |file|
85
+ file.write("#{receipt.fetch(:pull_request_url)}\n\nSource: #{receipt.fetch(:commit)}\nSHA256: #{receipt.fetch(:sha256)}\n\nSee releases.md at the release tag for release notes.\n")
86
+ file.flush
87
+ system("gh", "release", "create", tag, "--repo", @repository, "--verify-tag", "--title", "#{receipt.fetch(:name)} #{tag}", "--notes-file", file.path, chdir: @root)
88
+ end
89
+ end
90
+ # Existing immutable assets are checked before upload; never clobber them.
91
+ assets = api("releases/tags/#{tag}").fetch("assets")
92
+ [package, bundle, File.join(@root, "pkg", "release.json"), File.join(@root, "pkg", "provenance.sigstore.json")].each do |file|
93
+ if existing = assets.find{|asset| asset.fetch("name") == File.basename(file)}
94
+ digest = existing.fetch("digest")
95
+ raise "Existing release asset differs: #{file}" unless digest == "sha256:#{Digest::SHA256.file(file).hexdigest}"
96
+ else
97
+ system("gh", "release", "upload", tag, file, "--repo", @repository, chdir: @root)
98
+ end
99
+ end
100
+ receipt
101
+ end
102
+
103
+ # Load artifact evidence and verify the stored digest and filename.
104
+ def load_receipt
105
+ receipt = JSON.parse(File.read(File.join(@root, "pkg", "release.json")), symbolize_names: true)
106
+ filename = receipt.fetch(:file)
107
+ raise "Invalid artifact filename." unless filename == File.basename(filename) && filename.end_with?(".gem")
108
+ raise "Artifact digest mismatch." unless Digest::SHA256.file(File.join(@root, "pkg", filename)).hexdigest == receipt.fetch(:sha256)
109
+ receipt
110
+ end
111
+
112
+ # Refuse local or remote tag collisions before uploading a package.
113
+ def guard_tag(tag, commit)
114
+ local = readlines("git", "tag", "--list", tag, chdir: @root)
115
+ raise "Release tag points to another commit." if local.any? && @release.resolve(tag) != commit
116
+ remote = readlines("git", "ls-remote", "--tags", "origin", "refs/tags/#{tag}", "refs/tags/#{tag}^{}", chdir: @root).map{|line| line.split}
117
+ peeled = remote.find{|sha, ref| ref.end_with?("^{}")} || remote.first
118
+ raise "Remote release tag points to another commit." if peeled && peeled.first != commit
119
+ end
120
+
121
+ private
122
+
123
+ def gem_command(*arguments)
124
+ if defined?(::Bundler)
125
+ ::Bundler.with_unbundled_env{system("gem", *arguments, chdir: @root)}
126
+ else
127
+ system("gem", *arguments, chdir: @root)
128
+ end
129
+ end
130
+
131
+ def guard_environment
132
+ raise "Publishing requires the configured GitHub repository." unless ENV["GITHUB_REPOSITORY"] == @repository
133
+ raise "Publishing requires the default branch workflow." unless ENV["GITHUB_REF"] == "refs/heads/#{@config.fetch('branch')}"
134
+ end
135
+
136
+ def contains_bundle?(value, bundle)
137
+ return true if value == bundle
138
+ case value
139
+ when Hash then value.values.any?{|child| contains_bundle?(child, bundle)}
140
+ when Array then value.any?{|child| contains_bundle?(child, bundle)}
141
+ else false
142
+ end
143
+ end
144
+
145
+ def verify_certificate(path)
146
+ policy = ::Gem::Security::Policy.new("Release", only_trusted: false)
147
+ package = ::Gem::Package.new(path, policy)
148
+ package.verify
149
+ signer = OpenSSL::X509::Certificate.new(package.spec.cert_chain.last)
150
+ expected = OpenSSL::X509::Certificate.new(File.read(File.join(@root, "release.cert")))
151
+ raise "Package signer differs from release.cert." unless signer.to_der == expected.to_der
152
+ end
153
+
154
+ def build_package(path)
155
+ unless @config.fetch("signing")
156
+ return @release.worktree("HEAD"){|source| @release.bake(source, "gem:build", root: path, signing_key: false)}
157
+ end
158
+ certificate = OpenSSL::X509::Certificate.new(File.read(File.join(@root, "release.cert")))
159
+ key = OpenSSL::PKey.read(ENV.fetch("GEM_SIGNING_KEY"))
160
+ raise "Signing key does not match release.cert." unless certificate.check_private_key(key)
161
+ raise "Signing certificate is not currently valid." unless (certificate.not_before..certificate.not_after).cover?(Time.now)
162
+ Tempfile.create("gem-signing-key") do |file|
163
+ file.chmod(0600)
164
+ file.write(ENV.fetch("GEM_SIGNING_KEY"))
165
+ file.flush
166
+ package = @release.worktree("HEAD"){|source| @release.bake(source, "gem:build", root: path, signing_key: file.path)}
167
+ verify_certificate(package)
168
+ package
169
+ end
170
+ end
171
+
172
+ def output(receipt, restored:)
173
+ if path = ENV["GITHUB_OUTPUT"]
174
+ File.open(path, "a") do |file|
175
+ file.puts "package=pkg/#{receipt.fetch(:file)}"
176
+ file.puts "artifact=release-#{receipt.fetch(:commit)}"
177
+ file.puts "restored=#{restored}"
178
+ end
179
+ end
180
+ receipt
181
+ end
182
+
183
+ def verify_provenance(package)
184
+ ref = "refs/heads/#{@config.fetch('branch')}"
185
+ identity = "https://github.com/#{@repository}/.github/workflows/release-publish.yaml@#{ref}"
186
+ # The signed receipt binds the package digest to the release commit, independently of the workflow revision.
187
+ [package, File.join(@root, "pkg", "release.json")].each do |file|
188
+ system("gh", "attestation", "verify", file, "--repo", @repository, "--bundle", File.join(@root, "pkg", "provenance.sigstore.json"), "--cert-identity", identity, "--source-ref", ref, "--deny-self-hosted-runners", chdir: @root)
189
+ end
190
+ end
191
+
192
+ def registry_digest(name, version)
193
+ # Missing downloads can return 403; use the version API to establish absence.
194
+ return nil unless registry_get("https://rubygems.org/api/v2/rubygems/#{name}/versions/#{version}.json?platform=ruby")
195
+ body = registry_get("https://rubygems.org/downloads/#{name}-#{version}.gem")
196
+ raise "Published gem download is missing; retry after registry propagation." unless body
197
+ Digest::SHA256.hexdigest(body)
198
+ end
199
+
200
+ def registry_get(url, redirects: 5)
201
+ uri = URI(url)
202
+ raise "Registry redirect requires HTTPS." unless uri.scheme == "https"
203
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: true, open_timeout: 15, read_timeout: 60){|http| http.get(uri.request_uri)}
204
+ return nil if response.is_a?(Net::HTTPNotFound)
205
+ if response.is_a?(Net::HTTPRedirection)
206
+ raise "Too many registry redirects." unless redirects > 0
207
+ return registry_get(URI.join(url, response.fetch("location")).to_s, redirects: redirects - 1)
208
+ end
209
+ raise "Registry request failed: #{response.code}" unless response.is_a?(Net::HTTPSuccess)
210
+ response.body
211
+ end
212
+ end
213
+ end
214
+ end
215
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ require "erb"
7
+ require "yaml"
8
+ require "json"
9
+ require "fileutils"
10
+
11
+ module Bake
12
+ module Gem
13
+ module GitHub
14
+ # Generates reviewable repository files without changing remote settings.
15
+ class Setup
16
+ # @parameter root [String] Destination repository.
17
+ def initialize(root)
18
+ @root = File.expand_path(root)
19
+ end
20
+
21
+ # Generate workflows, policy payloads, and maintainer instructions. Refuse conflicting existing files.
22
+ def generate(repository:, branch: "main", checks:, approvals: 2, signing: File.file?(File.join(@root, "release.cert")), ruby: "3.4")
23
+ raise "Expected owner/repository." unless repository.match?(/\A[\w.-]+\/[\w.-]+\z/)
24
+ raise "Unsupported branch name." unless branch.match?(/\A[\w.\/-]+\z/)
25
+ raise "Select the required CI check names." if checks.empty?
26
+ raise "Review count must be between 1 and 6." unless (1..6).include?(approvals)
27
+ config = {"schema" => 1, "repository" => repository, "branch" => branch, "checks" => (checks + ["Release validation"]).uniq, "approvals" => approvals, "signing" => signing, "ruby" => ruby, "environment" => "rubygems"}
28
+ templates = File.expand_path("../../../../templates", __dir__)
29
+ files = {"config/release.yaml" => YAML.dump(config)}
30
+ Dir.glob("*.erb", base: templates).each do |name|
31
+ files[".github/workflows/#{name.delete_suffix('.erb')}"] = ERB.new(File.read(File.join(templates, name)), trim_mode: "-").result(binding)
32
+ end
33
+ self.class.rules(config).each do |name, rule|
34
+ files[".github/release-rules/#{name}.json"] = JSON.pretty_generate(rule) + "\n"
35
+ end
36
+ files[".github/releasing.md"] = File.read(File.join(templates, "releasing.md"))
37
+ conflicts = files.keys.select{|name| File.exist?(File.join(@root, name)) && File.read(File.join(@root, name)) != files[name]}
38
+ raise "Existing files differ; review them before regenerating: #{conflicts.join(', ')}" unless conflicts.empty?
39
+ files.each do |name, content|
40
+ path = File.join(@root, name)
41
+ FileUtils.mkdir_p(File.dirname(path))
42
+ File.write(path, content) unless File.exist?(path)
43
+ end
44
+ files.keys
45
+ end
46
+
47
+ # Native review/check rules allow PR-only administrator bypass; history rules have no bypass.
48
+ def self.rules(config)
49
+ conditions = {ref_name: {include: ["refs/heads/#{config.fetch('branch')}"], exclude: []}}
50
+ common = {target: "branch", enforcement: "active", conditions: conditions}
51
+ bypass = [{actor_id: 5, actor_type: "RepositoryRole", bypass_mode: "pull_request"}]
52
+ {
53
+ "reviews" => common.merge(name: "Gem release reviews", bypass_actors: bypass, rules: [{type: "pull_request", parameters: {required_approving_review_count: config.fetch("approvals"), dismiss_stale_reviews_on_push: true, require_last_push_approval: true, required_review_thread_resolution: true, require_code_owner_review: false, allowed_merge_methods: ["merge", "squash"]}}]),
54
+ "checks" => common.merge(name: "Gem release checks", bypass_actors: bypass, rules: [{type: "required_status_checks", parameters: {strict_required_status_checks_policy: true, do_not_enforce_on_create: false, required_status_checks: config.fetch("checks").map{|name| {context: name}}}}]),
55
+ "history" => common.merge(name: "Gem release history", bypass_actors: [], rules: [{type: "deletion"}, {type: "non_fast_forward"}]),
56
+ "tags" => {name: "Gem release tags", target: "tag", enforcement: "active", bypass_actors: [], conditions: {ref_name: {include: ["refs/tags/v*"], exclude: []}}, rules: [{type: "deletion"}, {type: "non_fast_forward"}]}
57
+ }
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Released under the MIT License.
4
+ # Copyright, 2026, by Samuel Williams.
5
+
6
+ # @namespace
7
+ module Bake
8
+ # @namespace
9
+ module Gem
10
+ # GitHub pull request and release orchestration for bake-gem.
11
+ module GitHub
12
+ VERSION = "0.0.3"
13
+ end
14
+ end
15
+ end
data/license.md ADDED
@@ -0,0 +1,22 @@
1
+ # MIT License
2
+
3
+ Copyright, 2021-2026, by Samuel Williams.
4
+ Copyright, 2025, by Copilot.
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
data/readme.md ADDED
@@ -0,0 +1,12 @@
1
+ # Bake::Gem::GitHub
2
+
3
+ Reviewed GitHub releases for Ruby gems, using `bake-gem` for branch preparation, independent content validation, and clean builds.
4
+
5
+ - `gem:github:release:patch` / `minor` / `major`: prepare, push and open a release PR.
6
+ - `gem:github:setup`: generate the three workflows and native review/CI policy.
7
+ - `gem:github:setup:plan` / `apply`: inspect and apply the managed GitHub rulesets.
8
+ - `gem:github:release:resume run=ID`: retry with the original artifact.
9
+
10
+ Read [the setup, release and recovery guide](guides/getting-started/readme.md) before enabling publishing. Context is distributed through `agent-context`. This initial implementation requires `bake-gem` 0.15 or later and a live pilot before wider rollout.
11
+
12
+ For this gem's releases, follow [the maintainer instructions](.github/releasing.md). Release workflows use the source checkout through Bundler's `gemspec` dependency, so the first release does not require an already published copy of `bake-gem-github`.
data/release.cert ADDED
@@ -0,0 +1,24 @@
1
+ -----BEGIN CERTIFICATE-----
2
+ MIIEFDCCAnygAwIBAgIBATANBgkqhkiG9w0BAQsFADAwMREwDwYDVQQKDAhTb2Nr
3
+ ZXRyeTEbMBkGA1UEAwwSU29ja2V0cnkgUnVieSBHZW1zMB4XDTI2MDkyMTA3NTgx
4
+ NFoXDTI3MDkyMTA3NTgxNFowMDERMA8GA1UECgwIU29ja2V0cnkxGzAZBgNVBAMM
5
+ ElNvY2tldHJ5IFJ1YnkgR2VtczCCAaIwDQYJKoZIhvcNAQEBBQADggGPADCCAYoC
6
+ ggGBAM/QgjVgDzDo/xJEQoFvAzcVFP7msnswkhPJB2UDsbxXCZmers5jV512TM5s
7
+ NwLHfzJiC4DcI5ax9ZYKM9Q+dS21YYagNqjtg3YPyDqR6phoibEA0VoMuInUQW68
8
+ i5OkCJzYKGD2pYYVZnuFNqyM2ECUvXh/fBmvPoHbncAHhWPaCBH8mQJ8sRNc6+RV
9
+ SoZZu1Yo/aW1zQ+SpZwad7s1ZmigfDNHKhJ22KwZHk+/5Zw1QXVfcajjswV0Mm2P
10
+ irgjKN3fyNVkwlly63EBlR4VydT+g9QtJtqh7ee0ThhI+v4wYovf4dbLNcEBTHu1
11
+ x1pGbXGx/2fBAST5eVwaXIx1V8VU22AJcBk1H2o5/1F0HfbD2HQjmFOA112KUwBW
12
+ 9TtspZD3g6rCQFX53XvL9h6j2y1ukl7s5AdEzOe/x6r1MO8tSDtgcYoF89wgF/88
13
+ Q/Eski0FckQ+znfESZcFcpzs2sPDoYW6SNVX4tZcNty85Y6WBHfHKio14x63PeyC
14
+ CG1gMwIDAQABozkwNzAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU
15
+ SuMc0x24Xshtaa8SQVkBr2Z5WzIwDQYJKoZIhvcNAQELBQADggGBABI62ey5lDWm
16
+ j8jsTQaNBMBb7LbKS3XkBwyL1UNGEwlicp399rJDeuNgVSHqBCZ/nE4yleNjgW9Y
17
+ N6DKdxXCvXmFUoHvUINeAvThHxmlEGhSfXl1x55xHEig0rEP4jgdjnYdQI4fqeOM
18
+ zIDN0F3ruArke4Y62SQgWVN7vspdAA41hBIRl1vsvs0KWG8DIVQ8cmR+TG6zjOmK
19
+ iUiUZGNPnStV1O1xW83c+Ba4Am0krP6/forxDPhRvTehqkVYvMdPfYcICNb5IM58
20
+ 5vaYvuj5AtfZuZWN0F/0KtSphhNC17rh6h8QmuYdMJ1clvlrkiEaO1UjPVwjgtxC
21
+ x/ARh5X6q0/YTXl4r7EfSJEeqW7qhgu9EUj3mGIPHYdX0Dqih/NgK20F3GvQtTfB
22
+ 7sse0duKBHXONYVwKAsceUVvqtCfyF608bCilCkbhw3QaInRj+BkRQKJ5Tuj2PZR
23
+ 76a/hwaV2wWn5RtAFBaUQzQdo/xTqJ7IkwaFjOZe/QyvyoRjCK9Rdg==
24
+ -----END CERTIFICATE-----
data/releases.md ADDED
@@ -0,0 +1,5 @@
1
+ # Releases
2
+
3
+ ## v0.0.1
4
+
5
+ - Initial implementation.
@@ -0,0 +1,45 @@
1
+ name: Prepare release
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ bump:
7
+ description: Version increment
8
+ required: true
9
+ type: choice
10
+ options: [patch, minor, major]
11
+
12
+ permissions:
13
+ contents: write
14
+ pull-requests: write
15
+
16
+ concurrency:
17
+ group: release-prepare
18
+ cancel-in-progress: false
19
+
20
+ env:
21
+ BUNDLE_WITH: maintenance
22
+
23
+ jobs:
24
+ prepare:
25
+ if: github.ref == 'refs/heads/<%= branch %>'
26
+ runs-on: ubuntu-latest
27
+ steps:
28
+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
29
+ with:
30
+ ref: <%= branch %>
31
+ fetch-depth: 0
32
+ persist-credentials: false
33
+ - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1
34
+ with:
35
+ ruby-version: <%= ruby.to_json %>
36
+ bundler-cache: true
37
+ - name: Create release PR
38
+ env:
39
+ GH_TOKEN: ${{ github.token }}
40
+ BUMP: ${{ inputs.bump }}
41
+ run: |
42
+ git config user.name 'github-actions[bot]'
43
+ git config user.email '41898282+github-actions[bot]@users.noreply.github.com'
44
+ case "$BUMP" in patch|minor|major) ;; *) exit 1 ;; esac
45
+ bundle exec bake "gem:github:release:$BUMP"
@@ -0,0 +1,103 @@
1
+ name: Publish release
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.
5
+ on:
6
+ pull_request_target:
7
+ types: [closed]
8
+ branches: [<%= branch.to_json %>]
9
+
10
+ permissions:
11
+ contents: read
12
+ pull-requests: read
13
+
14
+ concurrency:
15
+ group: release-publish
16
+ cancel-in-progress: false
17
+
18
+ env:
19
+ BUNDLE_WITH: maintenance
20
+ RELEASE_PR: ${{ github.event.pull_request.number }}
21
+
22
+ jobs:
23
+ inspect:
24
+ if: github.event.pull_request.merged == true
25
+ runs-on: ubuntu-latest
26
+ outputs:
27
+ release: ${{ steps.inspect.outputs.release }}
28
+ commit: ${{ steps.inspect.outputs.commit }}
29
+ steps:
30
+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
31
+ with:
32
+ fetch-depth: 0
33
+ persist-credentials: false
34
+ - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1
35
+ with:
36
+ ruby-version: <%= ruby.to_json %>
37
+ bundler-cache: true
38
+ - id: inspect
39
+ env:
40
+ GH_TOKEN: ${{ github.token }}
41
+ run: bundle exec bake gem:github:release:resolve
42
+
43
+ publish:
44
+ needs: inspect
45
+ if: needs.inspect.outputs.release == 'true'
46
+ runs-on: ubuntu-latest
47
+ environment: rubygems
48
+ permissions:
49
+ contents: write
50
+ pull-requests: read
51
+ actions: read
52
+ id-token: write
53
+ attestations: write
54
+ steps:
55
+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
56
+ with:
57
+ ref: ${{ needs.inspect.outputs.commit }}
58
+ fetch-depth: 0
59
+ persist-credentials: false
60
+ - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1
61
+ with:
62
+ ruby-version: <%= ruby.to_json %>
63
+ rubygems: '4.0.21'
64
+ bundler-cache: true
65
+ - name: Build or restore artifact
66
+ id: build
67
+ env:
68
+ GH_TOKEN: ${{ github.token }}
69
+ <% if signing -%>
70
+ GEM_SIGNING_KEY: ${{ secrets.GEM_SIGNING_KEY }}
71
+ <% end -%>
72
+ run: bundle exec bake gem:github:release:build
73
+ - name: Sign RubyGems attestation
74
+ if: steps.build.outputs.restored != 'true'
75
+ env:
76
+ PACKAGE: ${{ steps.build.outputs.package }}
77
+ run: gem exec sigstore-cli:0.2.3 sign "$PACKAGE" --bundle "$PACKAGE.sigstore.json"
78
+ - name: Attest gem and release receipt
79
+ if: steps.build.outputs.restored != 'true'
80
+ id: attest
81
+ uses: actions/attest@1e69f48acb82d1966a394da916b4c1698aa569d6 # v4
82
+ with:
83
+ subject-path: |
84
+ ${{ steps.build.outputs.package }}
85
+ pkg/release.json
86
+ - name: Retain provenance bundle
87
+ if: steps.build.outputs.restored != 'true'
88
+ env:
89
+ ATTESTATION_BUNDLE: ${{ steps.attest.outputs.bundle-path }}
90
+ run: cp "$ATTESTATION_BUNDLE" pkg/provenance.sigstore.json
91
+ - name: Preserve release before upload
92
+ if: steps.build.outputs.restored != 'true'
93
+ uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4
94
+ with:
95
+ name: ${{ steps.build.outputs.artifact }}
96
+ path: pkg/
97
+ if-no-files-found: error
98
+ retention-days: 90
99
+ - uses: rubygems/configure-rubygems-credentials@2a7221c7c44c30ebc68eda38fa25c60b918245c7
100
+ - name: Verify, publish, and finalize
101
+ env:
102
+ GH_TOKEN: ${{ github.token }}
103
+ run: bundle exec bake gem:github:release:publish
@@ -0,0 +1,32 @@
1
+ name: Validate release
2
+
3
+ on:
4
+ pull_request:
5
+ branches: [<%= branch.to_json %>]
6
+
7
+ permissions:
8
+ contents: read
9
+
10
+ env:
11
+ BUNDLE_WITH: maintenance
12
+
13
+ jobs:
14
+ validate:
15
+ name: Release validation
16
+ runs-on: ubuntu-latest
17
+ steps:
18
+ - uses: actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803 # v6
19
+ with:
20
+ ref: ${{ github.event.pull_request.head.sha }}
21
+ fetch-depth: 0
22
+ persist-credentials: false
23
+ - uses: ruby/setup-ruby@a0102e0972be65f351c307e2d64b9314a57c8073 # v1
24
+ with:
25
+ ruby-version: <%= ruby.to_json %>
26
+ bundler-cache: true
27
+ - name: Regenerate release content
28
+ env:
29
+ RELEASE_BASE: ${{ github.event.pull_request.base.sha }}
30
+ run: bundle exec bake gem:release:validate "base=$RELEASE_BASE" optional=true
31
+ - name: Build unsigned package
32
+ run: bundle exec bake gem:build signing_key=false