Skip to content

Commit 7a25ca7

Browse files
committed
Ensure constant file timestamps
1 parent 65b1a8e commit 7a25ca7

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

release-automation/build.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,43 @@ const flipFuses = async (context) => {
8383
await context.packager.addElectronFuses(context, newFuses);
8484
};
8585

86+
/**
87+
* @param {string} directory
88+
* @param {Date} date
89+
*/
90+
const recursivelySetFileTimes = (directory, date) => {
91+
const files = fs.readdirSync(directory);
92+
for (const file of files) {
93+
const filePath = pathUtil.join(directory, file);
94+
const stat = fs.statSync(filePath);
95+
if (stat.isDirectory()) {
96+
recursivelySetFileTimes(filePath, date);
97+
} else {
98+
fs.utimesSync(filePath, date, date);
99+
}
100+
}
101+
fs.utimesSync(directory, date, date);
102+
};
103+
104+
/**
105+
* @returns {Date}
106+
*/
107+
const getSourceDateEpoch = () => {
108+
// Standard variable for defining the time for a build
109+
// https://reproducible-builds.org/docs/source-date-epoch/
110+
if (process.env.SOURCE_DATE_EPOCH) {
111+
return new Date((+process.env.SOURCE_DATE_EPOCH) * 1000);
112+
}
113+
114+
// Otherwise, use an arbitrary constant date to ensure builds are still
115+
// reproducible even without SOURCE_DATE_EPOCH being set. This constant is
116+
// from commit 35045e7c0fa4e4e14b2747e967adb4029cedb945.
117+
return new Date(1609809111000);
118+
};
119+
86120
const afterPack = async (context) => {
87121
await flipFuses(context);
122+
recursivelySetFileTimes(context.appOutDir, getSourceDateEpoch());
88123
};
89124

90125
const build = async ({

0 commit comments

Comments
 (0)