Builds and checks a .gem archive from your gemspec. Publishing is done by a Destination. Commands use argument arrays, not a shell.
RubyGem.new(gemspec: 'example.gemspec') uses that gemspec. Otherwise it uses GEMSPEC_PATH or the only gemspec in the root; none or several raise. gemspec returns the absolute path, which the standard workflow exports.
directory: is where build output goes. It defaults to a nonempty RELEASE_DATA_DIR or a new temporary directory, created on first use, and directory returns it. The standard workflow passes the execution provider's directory, which Actions also exports for later steps. Keep it outside the working tree so build output stays out of release commits.
version reads the gemspec version in a new Ruby process, so it sees callback edits.
build!(release) overwrites release.gem, checks its version, writes its name, version, platform, and checksum to release.json, and returns the artifact path. Call it after the release commit and before tagging; Git#tag! raises if the build changed the checkout. built?(release) checks existing output without building.
Builds are reproducible. SOURCE_DATE_EPOCH sets the gemspec date and archive timestamps. Workflow capture sets it to the committer time of the original source commit, not the release commit; an explicit value wins. Without either, RubyGems uses 1980-01-02T00:00:00Z.
To rebuild a release, use the same source commit (the same files in another commit get another timestamp) and keep toolchains, generated files, gemspecs, and signing inputs the same. The old archive is not needed. The Actions workflow builds at the checkpoint and again at publication, producing the same archive both times.
artifact(release) checks the archive against the manifest (name, version, platform, digest, and gem metadata), copies it to NAME-VERSION.gem (or NAME-VERSION-PLATFORM.gem for non-ruby platforms), and returns that path. Registries and hosted releases publish these exact bytes. Older manifests without a platform work only for ruby-platform gems.
audit: checks the files in the archive on every build and artifact read, including reopened archives. List expected files yourself, not from the gemspec:
require 'ruby-gem-release/package/content_audit'
require 'ruby-gem-release/package/ruby_gem'
audit = RubyGemRelease::Package::ContentAudit.new(
expected_files: -> { ['LICENSE.txt', 'lib/example.rb', 'lib/example.jar'] },
generated: ['lib/example.jar'],
source: 'HEAD'
)
package = RubyGemRelease::Package::RubyGem.new(audit: audit)expected_files:must match the archive exactly, so missing runtime files and stray developer files both raise. Paths must be safe and unique, and entries must be regular files.- Every file not in
generated:must match its Git version byte for byte. source:(default'HEAD') resolves to a commit on each check; pass a commit SHA to audit a kept archive from an earlier checkout.root:is the Git checkout and defaults to the current directory.
Generated files must be in both expected_files: and generated:. Only the Git comparison is skipped; checksums and the file list still apply. Test generated bytes with your own build and consumer checks. Never derive expectations from the archive or an unchecked gemspec file list.
Build failures, version mismatches, and changed archives raise. The package never contacts a registry; see Destination::RubyGems for publishing and duplicate-version checks.