diff --git a/.azure-pipelines/publish-nightly.yml b/.azure-pipelines/publish-nightly.yml index 4490bd9f..0716118d 100644 --- a/.azure-pipelines/publish-nightly.yml +++ b/.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 diff --git a/.azure-pipelines/publish-stable.yml b/.azure-pipelines/publish-stable.yml index 464ea459..12dc7c69 100644 --- a/.azure-pipelines/publish-stable.yml +++ b/.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 diff --git a/scripts/ci/prepare-monaco-editor-core.ts b/scripts/ci/monaco-editor-core-prepare.ts similarity index 84% rename from scripts/ci/prepare-monaco-editor-core.ts rename to scripts/ci/monaco-editor-core-prepare.ts index daa66990..4c5a555e 100644 --- a/scripts/ci/prepare-monaco-editor-core.ts +++ b/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); }); diff --git a/scripts/ci/prepare-monaco-editor.ts b/scripts/ci/monaco-editor-prepare.ts similarity index 54% rename from scripts/ci/prepare-monaco-editor.ts rename to scripts/ci/monaco-editor-prepare.ts index a9b59646..96a17f6d 100644 --- a/scripts/ci/prepare-monaco-editor.ts +++ b/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 }; - 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); }); diff --git a/scripts/ci/monaco-editor.sh b/scripts/ci/monaco-editor.sh index 4efd4f74..0ec76e9e 100755 --- a/scripts/ci/monaco-editor.sh +++ b/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 diff --git a/scripts/ci/types.ts b/scripts/ci/types.ts new file mode 100644 index 00000000..4d364a3b --- /dev/null +++ b/scripts/ci/types.ts @@ -0,0 +1,6 @@ +export interface PackageJson { + version: string; + vscodeRef?: string; + vscodeCommitId?: string; + devDependencies: Record; +} diff --git a/scripts/lib/index.ts b/scripts/lib/index.ts index 62f3c9ec..b2903a92 100644 --- a/scripts/lib/index.ts +++ b/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 { + console.log(`Running ${command} in ${options.cwd}`); + return new Promise((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): Promise {