Skip to content

Commit

Permalink
Auto merge of #2278 - anthraxx:fix/reproducible-build, r=duckinator
Browse files Browse the repository at this point in the history
support SOURCE_DATE_EPOCH to make gem spec reproducible

Optionally respect the SOURCE_DATE_EPOCH environment variable to be used
instead of TODAY to allow reproducible builds of created gem specs.

In case none is specified, fall back to the current time.
______________

The problem is that using TODAY will change during time which makes created artifacts not reproducible (bit by bit identical).

Spec:
https://reproducible-builds.org/specs/source-date-epoch/

Buy-in:
https://reproducible-builds.org/docs/buy-in/

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [x] Get code review from coworkers / friends

I will abide by the [code of conduct](https://github.com/rubygems/rubygems/blob/master/CODE_OF_CONDUCT.md).
  • Loading branch information
bundlerbot committed May 12, 2018
2 parents 794b00d + 9fc4ca4 commit 8eef507
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 5 deletions.
13 changes: 8 additions & 5 deletions lib/rubygems/specification.rb
Expand Up @@ -135,7 +135,7 @@ class Gem::Specification < Gem::BasicSpecification
:autorequire => nil,
:bindir => 'bin',
:cert_chain => [],
:date => TODAY,
:date => nil,
:dependencies => [],
:description => nil,
:email => nil,
Expand Down Expand Up @@ -1713,13 +1713,16 @@ def has_conflicts?
}
end

##
# The date this gem was created. Lazily defaults to the current UTC date.
# The date this gem was created.
#
# If SOURCE_DATE_EPOCH is set as an environment variable, use that to support
# reproducible builds; otherwise, default to the current UTC date.
#
# There is no need to set this in your gem specification.
# Details on SOURCE_DATE_EPOCH:
# https://reproducible-builds.org/specs/source-date-epoch/

def date
@date ||= TODAY
@date ||= ENV["SOURCE_DATE_EPOCH"] ? Time.utc(*Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc.to_a[3..5].reverse) : TODAY
end

DateLike = Object.new # :nodoc:
Expand Down
5 changes: 5 additions & 0 deletions test/rubygems/test_gem_specification.rb
Expand Up @@ -1630,6 +1630,11 @@ def test_date_tolerates_hour_sec_and_timezone
assert_equal Time.utc(2012,01,12,0,0,0), @a1.date
end

def test_date_use_env_source_date_epoch
ENV["SOURCE_DATE_EPOCH"] = "123456789"
assert_equal Time.utc(1973,11,29,0,0,0), @a1.date
end

def test_dependencies
util_setup_deps
assert_equal [@bonobo, @monkey], @gem.dependencies
Expand Down

0 comments on commit 8eef507

Please sign in to comment.