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

Support for Maven reproducible builds #104

Merged
merged 1 commit into from
Apr 12, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
long start = System.nanoTime();
File dir = session.getRequest().getMultiModuleProjectDirectory();
log.debug("running in " + dir);
String fullHash, hash;
String fullHash, hash, timestamp;
int count;
try (Git git = Git.open(dir)) {
Status status = git.status().call();
Expand All @@ -100,6 +100,7 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
hash = head.abbreviate(ABBREV_LENGTH).name();
try (RevWalk walk = new RevWalk(repo)) {
RevCommit headC = walk.parseCommit(head);
timestamp = DateTimeFormatter.ISO_INSTANT.format(Instant.ofEpochSecond(headC.getCommitTime()));
Copy link
Member

@jglick jglick Apr 12, 2024

Choose a reason for hiding this comment

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

Should produce a string such as 2024-04-12T19:40:42Z which seems to align with https://cwiki.apache.org/confluence/pages/viewpage.action?pageId=74682318#Reproducible/VerifiableBuilds-OutputArchiveEntriesTimestamp though it is vague about allowed precision.

count = revCount(walk, headC);
{ // Look for repository commits reachable from HEAD that would clash.
Map<String,List<RevCommit>> encountered = new HashMap<>();
Expand Down Expand Up @@ -133,9 +134,10 @@ public void afterSessionStart(MavenSession session) throws MavenExecutionExcepti
}
log.debug("Spent " + (System.nanoTime() - start) / 1000 / 1000 + "ms on calculations");
String value = String.format(props.getProperty("changelist.format", "-rc%d.%s"), count, sanitize(hash));
log.info("Setting: -Dchangelist=" + value + " -DscmTag=" + fullHash);
log.info("Setting: -Dchangelist=" + value + " -DscmTag=" + fullHash + " -Dproject.build.outputTimestamp=" + timestamp);
props.setProperty("changelist", value);
props.setProperty("scmTag", fullHash);
props.setProperty("project.build.outputTimestamp", timestamp);
} else {
log.info("Declining to override the `changelist` or `scmTag` properties");
}
Expand Down