浏览代码

Set vscodeCommitId in package.json to track which vscode commit the package has been built from.

Henning Dieterichs 2 年之前
父节点
当前提交
ccb646cca9

+ 2 - 2
.azure-pipelines/publish-nightly.yml

@@ -34,7 +34,7 @@ extends:
           - script: npm ci
             displayName: Install NPM dependencies
 
-          - script: yarn ts-node ./scripts/ci/prepare-monaco-editor-core nightly
+          - script: yarn ts-node ./scripts/ci/monaco-editor-core-prepare nightly
             displayName: Setup, Build & Test monaco-editor-core
 
         tag: next
@@ -48,7 +48,7 @@ extends:
           - script: npm ci
             displayName: Install NPM dependencies
 
-          - script: yarn ts-node ./scripts/ci/prepare-monaco-editor nightly
+          - script: yarn ts-node ./scripts/ci/monaco-editor-prepare nightly
             displayName: Setup, Build & Test monaco-editor
 
         tag: next

+ 2 - 2
.azure-pipelines/publish-stable.yml

@@ -36,7 +36,7 @@ extends:
           - script: npm ci
             displayName: Install NPM dependencies
 
-          - script: yarn ts-node ./scripts/ci/prepare-monaco-editor-core stable
+          - script: yarn ts-node ./scripts/ci/monaco-editor-core-prepare stable
             displayName: Setup, Build & Test monaco-editor-core
 
         tag: latest
@@ -50,7 +50,7 @@ extends:
           - script: npm ci
             displayName: Install NPM dependencies
 
-          - script: yarn ts-node ./scripts/ci/prepare-monaco-editor stable
+          - script: yarn ts-node ./scripts/ci/monaco-editor-prepare stable
             displayName: Setup, Build & Test monaco-editor
 
         tag: latest

+ 13 - 2
scripts/ci/prepare-monaco-editor-core.ts → scripts/ci/monaco-editor-core-prepare.ts

@@ -1,6 +1,7 @@
 import { mkdir, rm } from 'fs/promises';
 import { join, resolve } from 'path';
 import { group, gitShallowClone, run, writeJsonFile, getNightlyVersion } from '../lib';
+import { PackageJson } from './types';
 
 const selfPath = __dirname;
 const rootPath = join(selfPath, '..', '..');
@@ -37,9 +38,17 @@ async function prepareMonacoEditorCoreRelease(version: string, vscodeRef: string
 
 	await rm(dependenciesPath, { force: true, recursive: true });
 
+	let vscodeCommitId: string;
+
 	await group('Checkout vscode', async () => {
-		await gitShallowClone(vscodePath, 'https://github.com/microsoft/vscode.git', vscodeRef);
+		const result = await gitShallowClone(
+			vscodePath,
+			'https://github.com/microsoft/vscode.git',
+			vscodeRef
+		);
+		vscodeCommitId = result.commitId;
 	});
+
 	await group('Checkout vscode-loc', async () => {
 		await gitShallowClone(
 			// Must be a sibling to the vscode repository
@@ -54,8 +63,10 @@ async function prepareMonacoEditorCoreRelease(version: string, vscodeRef: string
 			vscodePath,
 			'./build/monaco/package.json'
 		);
-		const packageJson = require(monacoEditorCorePackageJsonSourcePath) as { version: string };
+		const packageJson = require(monacoEditorCorePackageJsonSourcePath) as PackageJson;
 		packageJson.version = version;
+		// This ensures we can always figure out which commit monaco-editor-core was built from
+		packageJson.vscodeCommitId = vscodeCommitId;
 		await writeJsonFile(monacoEditorCorePackageJsonSourcePath, packageJson);
 	});
 

+ 27 - 6
scripts/ci/prepare-monaco-editor.ts → scripts/ci/monaco-editor-prepare.ts

@@ -1,15 +1,22 @@
 import { readFile } from 'fs/promises';
 import { join, resolve } from 'path';
 import { getNightlyVersion, group, run, writeJsonFile } from '../lib';
+import { PackageJson } from './types';
 
 const selfPath = __dirname;
 const rootPath = join(selfPath, '..', '..');
 const monacoEditorPackageJsonPath = resolve(rootPath, 'package.json');
+const monacoEditorCorePackageJsonPath = resolve(
+	rootPath,
+	'node_modules',
+	'monaco-editor-core',
+	'package.json'
+);
 
 async function prepareMonacoEditorReleaseStableOrNightly() {
 	const monacoEditorPackageJson = JSON.parse(
 		await readFile(monacoEditorPackageJsonPath, { encoding: 'utf-8' })
-	) as { version: string };
+	) as PackageJson;
 
 	let version: string;
 
@@ -27,18 +34,32 @@ async function prepareMonacoEditorReleaseStableOrNightly() {
 	// npm package is now in ./release, ready to be published
 }
 
-async function prepareMonacoEditorRelease(version: string) {
+async function prepareMonacoEditorRelease(monacoEditorCoreVersion: string) {
 	await group('npm ci', async () => {
 		await run('npm ci', { cwd: resolve(rootPath, 'webpack-plugin') });
 	});
 
-	await group('Set Version', async () => {
+	await group('Set Version & Update monaco-editor-core Version', async () => {
 		const packageJson = JSON.parse(
 			await readFile(monacoEditorPackageJsonPath, { encoding: 'utf-8' })
-		) as { version: string; devDependencies: Record<string, string> };
-		packageJson.version = version;
-		packageJson.devDependencies['monaco-editor-core'] = version;
+		) as PackageJson;
+		packageJson.version = monacoEditorCoreVersion;
+		packageJson.devDependencies['monaco-editor-core'] = monacoEditorCoreVersion;
+		await writeJsonFile(monacoEditorPackageJsonPath, packageJson);
+	});
+
+	await group('npm install to pick up monaco-editor-core', async () => {
+		await run('npm install', { cwd: rootPath });
+	});
 
+	await group('Setting vscode commitId from monaco-editor-core', async () => {
+		const monacoEditorCorePackageJson = JSON.parse(
+			await readFile(monacoEditorCorePackageJsonPath, { encoding: 'utf-8' })
+		) as PackageJson;
+		const packageJson = JSON.parse(
+			await readFile(monacoEditorPackageJsonPath, { encoding: 'utf-8' })
+		) as PackageJson;
+		packageJson.vscodeCommitId = monacoEditorCorePackageJson.vscodeCommitId;
 		await writeJsonFile(monacoEditorPackageJsonPath, packageJson);
 	});
 

+ 0 - 2
scripts/ci/monaco-editor.sh

@@ -1,8 +1,6 @@
 #!/bin/bash
 set -e
 
-# execute `npm install` to pick up local monaco-editor-core
-npm install
 # Install OS Dependencies for Playwright
 sudo npm run playwright-install-deps
 # Check prettier

+ 6 - 0
scripts/ci/types.ts

@@ -0,0 +1,6 @@
+export interface PackageJson {
+	version: string;
+	vscodeRef?: string;
+	vscodeCommitId?: string;
+	devDependencies: Record<string, string>;
+}

+ 25 - 1
scripts/lib/index.ts

@@ -19,13 +19,37 @@ export async function run(command: string, options: RunOptions) {
 	});
 }
 
-export async function gitShallowClone(targetPath: string, repositoryUrl: string, ref: string) {
+export async function runGetOutput(command: string, options: RunOptions): Promise<string> {
+	console.log(`Running ${command} in ${options.cwd}`);
+	return new Promise<string>((resolve, reject) => {
+		const process = spawn(command, { shell: true, cwd: options.cwd, stdio: 'pipe' });
+		let output = '';
+		process.stdout.on('data', (data) => {
+			output += data;
+		});
+		process.on('exit', (code) => {
+			if (code !== 0) {
+				reject(new Error(`Command ${command} exited with code ${code}`));
+			} else {
+				resolve(output);
+			}
+		});
+	});
+}
+
+export async function gitShallowClone(
+	targetPath: string,
+	repositoryUrl: string,
+	ref: string
+): Promise<{ commitId: string }> {
 	await mkdir(targetPath, { recursive: true });
 	const options: RunOptions = { cwd: targetPath };
 	await run('git init', options);
 	await run(`git remote add origin ${repositoryUrl}`, options);
 	await run(`git fetch --depth 1 origin ${ref}`, options);
 	await run(`git checkout ${ref}`, options);
+	const commitId = await runGetOutput('git rev-parse HEAD', options);
+	return { commitId };
 }
 
 export async function group(name: string, body: () => Promise<void>): Promise<void> {