build - reuse the same `date` across builds (#220076)

pull/220112/head
Benjamin Pasero 2024-07-05 20:06:43 +02:00 committed by GitHub
parent e09b537187
commit 7c8097dbbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 59 additions and 40 deletions

View File

@ -5,8 +5,6 @@
'use strict';
//@ts-check
const es = require('event-stream');
const gulp = require('gulp');
const path = require('path');
@ -24,7 +22,6 @@ const createReporter = require('./lib/reporter').createReporter;
const root = 'cli';
const rootAbs = path.resolve(__dirname, '..', root);
const src = `${root}/src`;
const targetCliPath = path.join(root, 'target', 'debug', process.platform === 'win32' ? 'code.exe' : 'code');
const platformOpensslDirName =
process.platform === 'win32' ? (

View File

@ -3,18 +3,24 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
//@ts-check
'use strict';
const gulp = require('gulp');
const util = require('./lib/util');
const date = require('./lib/date');
const task = require('./lib/task');
const compilation = require('./lib/compilation');
const optimize = require('./lib/optimize');
/**
* @param {boolean} disableMangle
*/
function makeCompileBuildTask(disableMangle) {
return task.series(
util.rimraf('out-build'),
util.buildWebNodePaths('out-build'),
date.writeISODate('out-build'),
compilation.compileApiProposalNamesTask,
compilation.compileTask('src', 'out-build', true, { disableMangle }),
optimize.optimizeLoaderTask('out-build', 'out-build', true)

View File

@ -18,7 +18,7 @@ const rename = require('gulp-rename');
const replace = require('gulp-replace');
const filter = require('gulp-filter');
const { getProductionDependencies } = require('./lib/dependencies');
const { date } = require('./lib/date');
const { readISODate } = require('./lib/date');
const vfs = require('vinyl-fs');
const packageJson = require('../package.json');
const flatmap = require('gulp-flatmap');
@ -301,7 +301,7 @@ function packageTask(type, platform, arch, sourceFolderName, destinationFolderNa
let productJsonContents;
const productJsonStream = gulp.src(['product.json'], { base: '.' })
.pipe(json({ commit, date, version }))
.pipe(json({ commit, date: readISODate('out-build'), version }))
.pipe(es.through(function (file) {
productJsonContents = file.contents.toString();
this.emit('data', file);

View File

@ -15,7 +15,7 @@ const replace = require('gulp-replace');
const filter = require('gulp-filter');
const util = require('./lib/util');
const { getVersion } = require('./lib/getVersion');
const { date } = require('./lib/date');
const { readISODate } = require('./lib/date');
const task = require('./lib/task');
const buildfile = require('../src/buildfile');
const optimize = require('./lib/optimize');
@ -259,7 +259,7 @@ function packageTask(platform, arch, sourceFolderName, destinationFolderName, op
let productJsonContents;
const productJsonStream = gulp.src(['product.json'], { base: '.' })
.pipe(json({ commit, date, checksums, version }))
.pipe(json({ commit, date: readISODate('out-build'), checksums, version }))
.pipe(es.through(function (file) {
productJsonContents = file.contents.toString();
this.emit('data', file);

View File

@ -12,7 +12,7 @@ const util = require('./lib/util');
const { getVersion } = require('./lib/getVersion');
const task = require('./lib/task');
const optimize = require('./lib/optimize');
const { date } = require('./lib/date');
const { readISODate } = require('./lib/date');
const product = require('../product.json');
const rename = require('gulp-rename');
const filter = require('gulp-filter');
@ -94,7 +94,7 @@ const createVSCodeWebProductConfigurationPatcher = (product) => {
...product,
version,
commit,
date
date: readISODate('out-build')
});
return content.replace('/*BUILD->INSERT_PRODUCT_CONFIGURATION*/', () => productConfiguration.substr(1, productConfiguration.length - 2) /* without { and }*/);
}

View File

@ -4,21 +4,29 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.date = void 0;
function getRoundedBuildDate() {
const now = new Date();
const minutes = now.getMinutes();
if (minutes >= 30) {
now.setHours(now.getHours() + 1);
}
now.setMinutes(0, 0, 0);
return now;
}
exports.writeISODate = writeISODate;
exports.readISODate = readISODate;
const path = require("path");
const fs = require("fs");
const root = path.join(__dirname, '..', '..');
/**
* An attempt to produce a stable date for the build that can be
* used across processes and build steps that run in parallel almost
* at the same time. The current time is rounded up or down to the
* closest hour.
* Writes a `outDir/date` file with the contents of the build
* so that other tasks during the build process can use it and
* all use the same date.
*/
exports.date = getRoundedBuildDate().toISOString();
function writeISODate(outDir) {
const result = () => new Promise((resolve, _) => {
const outDirectory = path.join(root, outDir);
fs.mkdirSync(outDirectory, { recursive: true });
const date = new Date().toISOString();
fs.writeFileSync(path.join(outDirectory, 'date'), date, 'utf8');
resolve();
});
result.taskName = 'build-date-file';
return result;
}
function readISODate(outDir) {
const outDirectory = path.join(root, outDir);
return fs.readFileSync(path.join(outDirectory, 'date'), 'utf8');
}
//# sourceMappingURL=date.js.map

View File

@ -3,23 +3,31 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
function getRoundedBuildDate() {
const now = new Date();
import * as path from 'path';
import * as fs from 'fs';
const minutes = now.getMinutes();
if (minutes >= 30) {
now.setHours(now.getHours() + 1);
}
now.setMinutes(0, 0, 0);
return now;
}
const root = path.join(__dirname, '..', '..');
/**
* An attempt to produce a stable date for the build that can be
* used across processes and build steps that run in parallel almost
* at the same time. The current time is rounded up or down to the
* closest hour.
* Writes a `outDir/date` file with the contents of the build
* so that other tasks during the build process can use it and
* all use the same date.
*/
export const date = getRoundedBuildDate().toISOString();
export function writeISODate(outDir: string) {
const result = () => new Promise<void>((resolve, _) => {
const outDirectory = path.join(root, outDir);
fs.mkdirSync(outDirectory, { recursive: true });
const date = new Date().toISOString();
fs.writeFileSync(path.join(outDirectory, 'date'), date, 'utf8');
resolve();
});
result.taskName = 'build-date-file';
return result;
}
export function readISODate(outDir: string): string {
const outDirectory = path.join(root, outDir);
return fs.readFileSync(path.join(outDirectory, 'date'), 'utf8');
}