Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- [#79](https://github.com/dblock/ruby-gem-release/pull/79): Select the next development version part with `next_version: :minor` or `:major` on `Workflow::RubyGem` and `Workflow::SemanticRubyGem` - [@dblock](https://github.com/dblock).
- [#80](https://github.com/dblock/ruby-gem-release/pull/80): Skip posting empty Danger report comments - [@dblock](https://github.com/dblock).
- [#82](https://github.com/dblock/ruby-gem-release/pull/82): Create the default package and Git temporary directories only when release data is first used, so loading a workflow leaves none behind - [@dblock](https://github.com/dblock).
- Your contribution here.

## 0.7.0 (2026/11/20)
Expand Down
2 changes: 1 addition & 1 deletion docs/package/ruby_gem.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Owns gem metadata, building, and artifact verification independently of the publ

## Directory

The optional `directory:` defaults to a nonempty `RELEASE_DATA_DIR` or a new temporary directory. The standard workflow supplies the execution provider's directory explicitly; Actions capture also exports it for manual callbacks and subsequent processes. `directory` returns this location. Keep it outside the working tree so build artifacts do not enter release commits.
The optional `directory:` defaults to a nonempty `RELEASE_DATA_DIR` or a new temporary directory, created when first used. The standard workflow supplies the execution provider's directory explicitly; Actions capture also exports it for manual callbacks and subsequent processes. `directory` returns this location. Keep it outside the working tree so build artifacts do not enter release commits.

## Version

Expand Down
2 changes: 1 addition & 1 deletion docs/source_control/git.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ Owns local release commits and tags, branch checks, Git bundles, and remote push

## Branch and Remote

`Git.new(branch: nil, remote: 'origin', directory: nil)` uses `DEFAULT_BRANCH` or the remote's default-branch reference. The optional directory selects the Git bundle and preparation index snapshot location; it defaults to a nonempty `RELEASE_DATA_DIR` or a new temporary directory. Separate Ruby processes must share this directory, as both Actions interfaces do through their execution provider.
`Git.new(branch: nil, remote: 'origin', directory: nil)` uses `DEFAULT_BRANCH` or the remote's default-branch reference. The optional directory selects the Git bundle and preparation index snapshot location; it defaults to a nonempty `RELEASE_DATA_DIR` or a new temporary directory, created when first used. Separate Ruby processes must share this directory, as both Actions interfaces do through their execution provider.

## Configure

Expand Down
17 changes: 11 additions & 6 deletions lib/ruby-gem-release/package/ruby_gem.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@
module RubyGemRelease
module Package
class RubyGem
attr_reader :directory, :gemspec
attr_reader :gemspec

def initialize(gemspec: nil, directory: nil, audit: nil)
@gemspec = resolve_gemspec(gemspec || ENV.fetch('GEMSPEC_PATH', nil))
directory ||= ENV.fetch('RELEASE_DATA_DIR', nil)
@directory = directory.to_s.empty? ? Dir.mktmpdir('ruby-gem-release-') : directory
@directory = directory unless directory.to_s.empty?
@audit = audit
end

# Creates the default temporary directory only when artifacts are first used.
def directory
@directory ||= Dir.mktmpdir('ruby-gem-release-')
end

def version
script = 'spec = Gem::Specification.load(ARGV.fetch(0)); abort "Cannot load gemspec" unless spec; puts JSON.generate(spec.version.to_s)'
JSON.parse(run(Gem.ruby, '-rrubygems', '-rjson', '-e', script, @gemspec))
end

def build!(release)
FileUtils.mkdir_p(@directory)
FileUtils.mkdir_p(directory)
run({ 'SOURCE_DATE_EPOCH' => source_date_epoch }, Gem.ruby, '-S', 'gem', 'build', @gemspec, '--output', archive)
@manifest = build_manifest(release)
File.write(manifest_path, JSON.generate(@manifest))
Expand All @@ -47,7 +52,7 @@ def artifact(release)
platform = manifest.fetch('platform', 'ruby')
raise 'Invalid package platform' unless /\A[A-Za-z0-9][A-Za-z0-9_.-]*\z/.match?(platform)

path = File.join(@directory, Gem::Package.new(archive).spec.file_name)
path = File.join(directory, Gem::Package.new(archive).spec.file_name)
FileUtils.cp(archive, path)
path
end
Expand Down Expand Up @@ -91,11 +96,11 @@ def identity(spec)
end

def archive
File.join(@directory, 'release.gem')
File.join(directory, 'release.gem')
end

def manifest_path
File.join(@directory, 'release.json')
File.join(directory, 'release.json')
end

def resolve_gemspec(path)
Expand Down
13 changes: 9 additions & 4 deletions lib/ruby-gem-release/source_control/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def initialize(branch: nil, remote: 'origin', directory: nil)
@remote = remote
@branch = branch || ENV.fetch('DEFAULT_BRANCH', nil)
directory ||= ENV.fetch('RELEASE_DATA_DIR', nil)
@directory = directory.to_s.empty? ? Dir.mktmpdir('ruby-gem-release-git-') : directory
@directory = directory unless directory.to_s.empty?
end

def configure!(name: 'ruby-gem-release', email: 'ruby-gem-release@localhost')
Expand Down Expand Up @@ -118,8 +118,8 @@ def next_iteration(release)
end

def write_bundle(release)
FileUtils.mkdir_p(@directory)
run('bundle', 'create', File.join(@directory, 'release.bundle'), 'HEAD', "refs/tags/v#{release.version}")
FileUtils.mkdir_p(directory)
run('bundle', 'create', File.join(directory, 'release.bundle'), 'HEAD', "refs/tags/v#{release.version}")
end

private
Expand Down Expand Up @@ -214,7 +214,12 @@ def commit_changes(message, required:)
end

def preparation
@preparation ||= Preparation.new(directory: @directory, &method(:run))
@preparation ||= Preparation.new(directory: directory, &method(:run))
end

# Creates the default temporary directory only when release data is first written or read.
def directory
@directory ||= Dir.mktmpdir('ruby-gem-release-git-')
end

def run(*)
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby_gem_release/package/ruby_gem_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,17 @@
File.write('version.rb', "VERSION = '1.2.3'\n")
end

it 'creates its default temporary directory only when artifacts are first used', :aggregate_failures do
ENV.delete('RELEASE_DATA_DIR')
temporary = File.join(directory, 'default')
allow(Dir).to receive(:mktmpdir).with('ruby-gem-release-').and_return(temporary)
package = described_class.new(gemspec: 'fixture.gemspec')
expect(Dir).not_to have_received(:mktmpdir)
expect(package.built?(release)).to be(false)
expect(package.directory).to eq(temporary)
expect(Dir).to have_received(:mktmpdir).once
end

it 'builds a real archive and reopens the same verified artifact', :aggregate_failures do
path = package.build!(release)
reopened = described_class.new(gemspec: 'fixture.gemspec', directory: artifacts)
Expand Down
11 changes: 11 additions & 0 deletions spec/ruby_gem_release/source_control/git_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ def checkout
initial
end

it 'creates its default temporary directory only when release data is first used', :aggregate_failures do
ENV.delete('RELEASE_DATA_DIR')
temporary = File.join(directory, 'default')
allow(Dir).to receive(:mktmpdir).with('ruby-gem-release-git-').and_return(temporary)
lazy = described_class.new(branch: 'master')
lazy.head
expect(Dir).not_to have_received(:mktmpdir)
lazy.check_clean!
expect(Dir).to have_received(:mktmpdir).once
end

def command(*arguments)
output, error, status = Open3.capture3('git', *arguments)
raise error unless status.success?
Expand Down
Loading