Skip to content

Commit 5c6122b

Browse files
committed
🐛 Fix ability to build gem without signing
- for linux package maintainers
1 parent 6462b9f commit 5c6122b

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

CONTRIBUTING.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,14 @@ Also see GitLab Contributors: [https://gitlab.com/oauth-xx/version_gem/-/graphs/
8484

8585
### One-time, Per-maintainer, Setup
8686

87-
**IMPORTANT**: Your public key for signing gems will need to be picked up by the line in the
88-
`gemspec` defining the `spec.cert_chain` (check the relevant ENV variables there),
89-
in order to sign the new release.
87+
**IMPORTANT**: If you want to sign the build you create,
88+
your public key for signing gems will need to be picked up by the line in the
89+
`gemspec` defining the `spec.cert_chain` (check the relevant ENV variables there).
90+
All releases to RubyGems.org will be signed.
9091
See: [RubyGems Security Guide][🔒️rubygems-security-guide]
9192

93+
NOTE: To build without signing the gem you must set `SKIP_GEM_SIGNING` to some value in your environment.
94+
9295
### To release a new version:
9396

9497
1. Run `bin/setup && bin/rake` as a tests, coverage, & linting sanity check

version_gem.gemspec

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@ Gem::Specification.new do |spec|
1111
# Linux distros may package ruby gems differently,
1212
# and securely certify them independently via alternate package management systems.
1313
# Ref: https://gitlab.com/oauth-xx/version_gem/-/issues/3
14-
# Hence, only enable signing if the cert_file is present.
14+
# Hence, only enable signing if `SKIP_GEM_SIGNING` is not set in ENV.
1515
# See CONTRIBUTING.md
16-
default_user_cert = "certs/#{ENV.fetch("GEM_CERT_USER", ENV["USER"])}.pem"
17-
default_user_cert_path = File.join(__dir__, default_user_cert)
18-
cert_file_path = ENV.fetch("GEM_CERT_PATH", default_user_cert_path)
16+
user_cert = "certs/#{ENV.fetch("GEM_CERT_USER", ENV["USER"])}.pem"
17+
cert_file_path = File.join(__dir__, user_cert)
1918
cert_chain = cert_file_path.split(",")
20-
if cert_file_path && cert_chain.map { |fp| File.exist?(fp) }
19+
cert_chain.select! { |fp| File.exist?(fp) }
20+
if cert_file_path && cert_chain.any?
2121
spec.cert_chain = cert_chain
22-
if $PROGRAM_NAME.end_with?("gem", "rake") && ARGV[0] == "build"
23-
spec.signing_key = File.expand_path("~/.ssh/gem-private_key.pem")
22+
if $PROGRAM_NAME.end_with?("gem") && ARGV[0] == "build" && !ENV.include?("SKIP_GEM_SIGNING")
23+
spec.signing_key = File.join(Gem.user_home, ".ssh", "gem-private_key.pem")
2424
end
2525
end
2626

0 commit comments

Comments
 (0)