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

build: introduce support for reproducible builds #1995

Merged
merged 2 commits into from
Feb 2, 2022
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
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,14 @@ allprojects {
javadoc.options.addStringOption('Xdoclint:all,-missing', '-quiet')
}

// support for reproducible builds
tasks.withType(AbstractArchiveTask).configureEach {
// ignore file timestamps
// be consistent in archive file order
preserveFileTimestamps = false
reproducibleFileOrder = true
}

project.afterEvaluate {
// Handle javadoc dependencies across projects. Order matters: the linksOffline for
// org.opensearch:opensearch must be the last one or all the links for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public void apply(Project project) {
params.setGradleJavaVersion(Jvm.current().getJavaVersion());
params.setGitRevision(gitInfo.getRevision());
params.setGitOrigin(gitInfo.getOrigin());
params.setBuildDate(ZonedDateTime.now(ZoneOffset.UTC));
params.setBuildDate(Util.getBuildDate(ZonedDateTime.now(ZoneOffset.UTC)));
params.setTestSeed(getTestSeed());
params.setIsCi(System.getenv("JENKINS_URL") != null);
params.setIsInternal(isInternal);
Expand Down
16 changes: 16 additions & 0 deletions buildSrc/src/main/java/org/opensearch/gradle/util/Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
import java.io.UncheckedIOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.time.Instant;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Locale;
import java.util.Optional;
import java.util.function.Supplier;
Expand Down Expand Up @@ -187,4 +190,17 @@ public String toString() {
}
};
}

public static ZonedDateTime getBuildDate(ZonedDateTime defaultValue) {
final String sourceDateEpoch = System.getenv("SOURCE_DATE_EPOCH");
if (sourceDateEpoch != null) {
try {
return ZonedDateTime.ofInstant(Instant.ofEpochSecond(Long.parseLong(sourceDateEpoch)), ZoneOffset.UTC);
} catch (NumberFormatException e) {
throw new GradleException("Sysprop [SOURCE_DATE_EPOCH] must be of type [long]", e);
}
} else {
return defaultValue;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@
import org.apache.lucene.index.LeafReader;
import org.apache.lucene.index.LeafReaderContext;
import org.apache.lucene.index.LiveIndexWriterConfig;
import org.apache.lucene.index.LogByteSizeMergePolicy;
import org.apache.lucene.index.LogDocMergePolicy;
import org.apache.lucene.index.MergePolicy;
import org.apache.lucene.index.NoMergePolicy;
Expand Down