Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set SOURCE_DATE_EPOCH env var if not provided. #2882

Merged
1 commit merged into from Sep 14, 2019

Conversation

duckinator
Copy link
Member

Description:

Set SOURCE_DATE_EPOCH env var if not provided.

Fixes #2290.

  1. Gem::Specification.date returns SOURCE_DATE_EPOCH when defined,
  2. this commit makes RubyGems set it persistently when not provided.

This combination means that you can build a gem, check the build time,
and use that value to generate a new build -- and then verify they're
the same.

Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

@duckinator duckinator changed the title [WIP] Set SOURCE_DATE_EPOCH env var if not provided. Set SOURCE_DATE_EPOCH env var if not provided. Aug 17, 2019
@duckinator duckinator changed the title Set SOURCE_DATE_EPOCH env var if not provided. [WIP] Set SOURCE_DATE_EPOCH env var if not provided. Aug 17, 2019
@duckinator

This comment has been minimized.

@duckinator duckinator force-pushed the auto-define-source-date-epoch branch from 5be84d1 to 557fd7b Compare August 17, 2019 12:32
@duckinator
Copy link
Member Author

It now has a passing test for reproducibility that can be made to fail by changing:

ENV["SOURCE_DATE_EPOCH"] = new_epoch

to:

ENV["SOURCE_DATE_EPOCH"] = (new_epoch.to_i + 1).to_s

So I am a lot more confident that it actually works properly, now.

@duckinator duckinator force-pushed the auto-define-source-date-epoch branch from 557fd7b to 60ca549 Compare August 17, 2019 12:35
@duckinator
Copy link
Member Author

So, assuming CI passes, the current state of this is: there is a test proving generated .gem files for the same source with the same SOURCE_DATE_EPOCH are equivalent, but I have had difficulty doing this manually for some reason.

By screwing with SOURCE_DATE_EPOCH on the second build in the test, I can make the test fail, so I don't think it's the test that's wrong this time.

lib/rubygems.rb Outdated Show resolved Hide resolved

Time.at(ENV["SOURCE_DATE_EPOCH"].to_i).utc.freeze
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What you think of:

def self.source_date_epoch
  source_date_epoch = ENV["SOURCE_DATE_EPOCH"]
  source_date_epoch = Time.now.to_i if source_date_epoch.strip.empty?
 
  Time.at(source_date_epoch).utc.freeze
end

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The entire purpose of this PR is to set ENV["SOURCE_DATE_EPOCH"] if it hasn't been set, which your variant doesn't do.

lib/rubygems/specification.rb Outdated Show resolved Hide resolved
@duckinator
Copy link
Member Author

Thanks for the feedback @bronzdoc. I'll go through and update the code in a bit. 👍

@duckinator duckinator force-pushed the auto-define-source-date-epoch branch from 60ca549 to e993811 Compare August 30, 2019 14:13
@duckinator
Copy link
Member Author

@bronzdoc I just pushed changes which should resolve most of what you mentioned. Let me know what you think. 🙂

@duckinator duckinator changed the title [WIP] Set SOURCE_DATE_EPOCH env var if not provided. Set SOURCE_DATE_EPOCH env var if not provided. Aug 30, 2019
Fixes rubygems#2290.

1. `Gem::Specification.date` returns SOURCE_DATE_EPOCH when defined,
2. this commit makes RubyGems set it _persistently_ when not provided.

This combination means that you can build a gem, check the build time,
and use that value to generate a new build -- and then verify they're
the same.
@duckinator
Copy link
Member Author

duckinator commented Sep 13, 2019

Just rebased this off latest master.

@djberg96
Copy link
Contributor

LGTM 👍

@duckinator
Copy link
Member Author

@bundlerbot r=djberg96

ghost pushed a commit that referenced this pull request Sep 14, 2019
2882: Set SOURCE_DATE_EPOCH env var if not provided. r=djberg96 a=duckinator

# Description:

Set SOURCE_DATE_EPOCH env var if not provided.

Fixes #2290.

1. `Gem::Specification.date` returns SOURCE_DATE_EPOCH when defined,
2. this commit makes RubyGems set it _persistently_ when not provided.

This combination means that you can build a gem, check the build time,
and use that value to generate a new build -- and then verify they're
the same.

# Tasks:

- [x] Describe the problem / feature
- [x] Write tests
- [x] Write code to solve the problem
- [ ] 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).


Co-authored-by: Ellen Marie Dash <the@smallest.dog>
@ghost
Copy link

ghost commented Sep 14, 2019

Build succeeded

@ghost ghost merged commit d830d53 into rubygems:master Sep 14, 2019
@duckinator duckinator deleted the auto-define-source-date-epoch branch September 14, 2019 01:32
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

reproducible builds proposal: make gem define SOURCE_DATE_EPOCH itself
3 participants