Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
microsoft
GitHub Repository: microsoft/vscode
Path: blob/main/build/azure-pipelines/common/checkCopilotChatCompatibility.ts
5241 views
1
/*---------------------------------------------------------------------------------------------
2
* Copyright (c) Microsoft Corporation. All rights reserved.
3
* Licensed under the MIT License. See License.txt in the project root for license information.
4
*--------------------------------------------------------------------------------------------*/
5
6
import path from 'path';
7
import fs from 'fs';
8
import { retry } from './retry.ts';
9
import { type IExtensionManifest, parseApiProposalsFromSource, checkExtensionCompatibility, areAllowlistedApiProposalsMatching } from './versionCompatibility.ts';
10
11
const root = path.dirname(path.dirname(path.dirname(import.meta.dirname)));
12
13
async function fetchLatestExtensionManifest(extensionId: string): Promise<IExtensionManifest> {
14
// Use the vscode-unpkg service to get the latest extension package.json
15
const [publisher, name] = extensionId.split('.');
16
17
// First, get the latest version from the gallery endpoint
18
const galleryUrl = `https://main.vscode-unpkg.net/_gallery/${publisher}/${name}/latest`;
19
const galleryResponse = await fetch(galleryUrl, {
20
headers: { 'User-Agent': 'VSCode Build' }
21
});
22
23
if (!galleryResponse.ok) {
24
throw new Error(`Failed to fetch latest version for ${extensionId}: ${galleryResponse.status} ${galleryResponse.statusText}`);
25
}
26
27
const galleryData = await galleryResponse.json() as { versions: { version: string }[] };
28
const version = galleryData.versions[0].version;
29
30
// Now fetch the package.json using the actual version
31
const url = `https://${publisher}.vscode-unpkg.net/${publisher}/${name}/${version}/extension/package.json`;
32
33
const response = await fetch(url, {
34
headers: { 'User-Agent': 'VSCode Build' }
35
});
36
37
if (!response.ok) {
38
throw new Error(`Failed to fetch extension ${extensionId} from unpkg: ${response.status} ${response.statusText}`);
39
}
40
41
return await response.json() as IExtensionManifest;
42
}
43
44
export async function checkCopilotChatCompatibility(): Promise<void> {
45
const extensionId = 'github.copilot-chat';
46
47
console.log(`Checking compatibility of ${extensionId}...`);
48
49
// Get product version from package.json
50
const packageJson = JSON.parse(fs.readFileSync(path.join(root, 'package.json'), 'utf8'));
51
const productVersion = packageJson.version;
52
53
console.log(`Product version: ${productVersion}`);
54
55
// Get API proposals from the generated file
56
const apiProposalsPath = path.join(root, 'src/vs/platform/extensions/common/extensionsApiProposals.ts');
57
const apiProposalsContent = fs.readFileSync(apiProposalsPath, 'utf8');
58
const allApiProposals = parseApiProposalsFromSource(apiProposalsContent);
59
60
const proposalCount = Object.keys(allApiProposals).length;
61
if (proposalCount === 0) {
62
throw new Error('Failed to load API proposals from source');
63
}
64
65
console.log(`Loaded ${proposalCount} API proposals from source`);
66
67
// Load product.json to check allowlisted API proposals
68
const productJsonPath = path.join(root, 'product.json');
69
let productJson;
70
try {
71
productJson = JSON.parse(fs.readFileSync(productJsonPath, 'utf8'));
72
} catch (error) {
73
throw new Error(`Failed to load or parse product.json: ${error}`);
74
}
75
const extensionEnabledApiProposals = productJson?.extensionEnabledApiProposals;
76
const extensionIdKey = extensionEnabledApiProposals ? Object.keys(extensionEnabledApiProposals).find(key => key.toLowerCase() === extensionId.toLowerCase()) : undefined;
77
const productAllowlistedProposals = extensionIdKey ? extensionEnabledApiProposals[extensionIdKey] : undefined;
78
79
if (productAllowlistedProposals) {
80
console.log(`Product.json allowlisted proposals for ${extensionId}:`);
81
for (const proposal of productAllowlistedProposals) {
82
console.log(` ${proposal}`);
83
}
84
} else {
85
console.log(`Product.json allowlisted proposals for ${extensionId}: none`);
86
}
87
88
// Fetch the latest extension manifest
89
const manifest = await retry(() => fetchLatestExtensionManifest(extensionId));
90
91
console.log(`Extension ${extensionId}@${manifest.version}:`);
92
console.log(` engines.vscode: ${manifest.engines.vscode}`);
93
console.log(` enabledApiProposals:\n ${manifest.enabledApiProposals?.join('\n ') || 'none'}`);
94
95
// Check compatibility
96
const result = checkExtensionCompatibility(productVersion, allApiProposals, manifest);
97
if (!result.compatible) {
98
throw new Error(`Compatibility check failed:\n ${result.errors.join('\n ')}`);
99
}
100
101
console.log(` ✓ Engine version compatible`);
102
if (manifest.enabledApiProposals?.length) {
103
console.log(` ✓ API proposals compatible`);
104
}
105
106
// Check that product.json allowlist matches package.json declarations
107
const allowlistResult = areAllowlistedApiProposalsMatching(extensionId, productAllowlistedProposals, manifest.enabledApiProposals);
108
if (!allowlistResult.compatible) {
109
throw new Error(`Allowlist check failed:\n ${allowlistResult.errors.join('\n ')}`);
110
}
111
112
console.log(` ✓ Product.json allowlist matches package.json`);
113
console.log(`✓ ${extensionId} is compatible with this build`);
114
}
115
116
if (import.meta.main) {
117
const warnOnly = process.argv.includes('--warn-only');
118
119
checkCopilotChatCompatibility().then(() => {
120
console.log('Copilot Chat compatibility check passed');
121
process.exit(0);
122
}, err => {
123
if (warnOnly) {
124
// Issue a warning using Azure DevOps logging commands but don't fail the build
125
console.log(`##vso[task.logissue type=warning]Copilot Chat compatibility check failed: ${err.message}`);
126
console.log(`##vso[task.complete result=SucceededWithIssues;]Copilot Chat compatibility check failed`);
127
console.log('');
128
console.log(`⚠️ WARNING: ${err.message}`);
129
console.log('');
130
console.log('The build will continue, but the release step will fail if this is not resolved.');
131
process.exit(0);
132
} else {
133
console.error(err);
134
process.exit(1);
135
}
136
});
137
}
138
139