Skip to content

Commit

Permalink
Merge pull request #18258 from timvandermeij/release-reproducible
Browse files Browse the repository at this point in the history
Implement reproducibility for the release builds
  • Loading branch information
timvandermeij authored Jun 16, 2024
2 parents 7b0c034 + 44e0fae commit ff44c3b
Showing 1 changed file with 29 additions and 10 deletions.
39 changes: 29 additions & 10 deletions gulpfile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {
babelPluginPDFJSPreprocessor,
preprocessPDFJSCode,
} from "./external/builder/babel-plugin-pdfjs-preprocessor.mjs";
import { exec, spawn, spawnSync } from "child_process";
import { exec, execSync, spawn, spawnSync } from "child_process";
import autoprefixer from "autoprefixer";
import babel from "@babel/core";
import crypto from "crypto";
Expand Down Expand Up @@ -1682,13 +1682,13 @@ gulp.task(
)
);

function compressPublish(targetName, dir) {
function compressPublish({ sourceDirectory, targetFile, modifiedTime }) {
return gulp
.src(dir + "**", { encoding: false })
.pipe(zip(targetName))
.src(`${sourceDirectory}**`, { encoding: false })
.pipe(zip(targetFile, { modifiedTime }))
.pipe(gulp.dest(BUILD_DIR))
.on("end", function () {
console.log("Built distribution file: " + targetName);
console.log(`Built distribution file: ${targetFile}`);
});
}

Expand All @@ -1701,15 +1701,34 @@ gulp.task(

config.stableVersion = version;

// ZIP files record the modification date of the source files, so if files
// are generated during the build process the output is not reproducible.
// To avoid this, the modification dates should be replaced with a fixed
// date, in our case the last Git commit date, so that builds from identical
// source code result in bit-by-bit identical output. The `gulp-zip` library
// supports providing a different modification date to enable reproducible
// builds. Note that the Git command below outputs the last Git commit date
// as a Unix timestamp (in seconds since epoch), but the `Date` constructor
// in JavaScript requires millisecond input, so we have to multiply by 1000.
const lastCommitTimestamp = execSync('git log --format="%at" -n 1')
.toString()
.replace("\n", "");
const lastCommitDate = new Date(parseInt(lastCommitTimestamp, 10) * 1000);

return ordered([
createStringSource(CONFIG_FILE, JSON.stringify(config, null, 2)).pipe(
gulp.dest(".")
),
compressPublish("pdfjs-" + version + "-dist.zip", GENERIC_DIR),
compressPublish(
"pdfjs-" + version + "-legacy-dist.zip",
GENERIC_LEGACY_DIR
),
compressPublish({
sourceDirectory: GENERIC_DIR,
targetFile: `pdfjs-${version}-dist.zip`,
modifiedTime: lastCommitDate,
}),
compressPublish({
sourceDirectory: GENERIC_LEGACY_DIR,
targetFile: `pdfjs-${version}-legacy-dist.zip`,
modifiedTime: lastCommitDate,
}),
]);
})
);
Expand Down

0 comments on commit ff44c3b

Please sign in to comment.