Merge pull request #18258 from timvandermeij/release-reproducible
Implement reproducibility for the release builds
This commit is contained in:
commit
ff44c3be1f
39
gulpfile.mjs
39
gulpfile.mjs
@ -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";
|
||||
@ -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}`);
|
||||
});
|
||||
}
|
||||
|
||||
@ -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,
|
||||
}),
|
||||
]);
|
||||
})
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user