From 4a00aa60aab1eb4f4429ef08a5b3d5f971f7770e Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 11 Dec 2024 10:22:46 -0800 Subject: [PATCH 1/2] Add PR check for proposed API changes Fixes #20939 Add a PR check for proposed API changes without VS Code engine update. * Modify `package.json` to add a new script entry `check-proposed-api`. * Modify `.github/workflows/pr-file-check.yml` to add a new step to run the `check-proposed-api` script. * Add `src/check-proposed-api.js` to check for changes in `enabledApiProposals` and `vscode` engine version, and fail if `enabledApiProposals` is modified but `vscode` engine version is not updated. --- For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/microsoft/vscode-python/issues/20939?shareId=XXXX-XXXX-XXXX-XXXX). --- .github/workflows/pr-file-check.yml | 3 +++ package.json | 3 ++- src/check-proposed-api.js | 22 ++++++++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 src/check-proposed-api.js diff --git a/.github/workflows/pr-file-check.yml b/.github/workflows/pr-file-check.yml index be55f4ad2f3b..30edb152b215 100644 --- a/.github/workflows/pr-file-check.yml +++ b/.github/workflows/pr-file-check.yml @@ -42,3 +42,6 @@ jobs: .github/test_plan.md skip-label: 'skip tests' failure-message: 'TypeScript code was edited without also editing a ${file-pattern} file; see the Testing page in our wiki on testing guidelines (the ${skip-label} label can be used to pass this check)' + + - name: 'Check for proposed API changes' + run: npm run check-proposed-api diff --git a/package.json b/package.json index c8fe74cc8255..51e708d7e3f2 100644 --- a/package.json +++ b/package.json @@ -1552,7 +1552,8 @@ "addExtensionPackDependencies": "gulp addExtensionPackDependencies", "updateBuildNumber": "gulp updateBuildNumber", "verifyBundle": "gulp verifyBundle", - "webpack": "webpack" + "webpack": "webpack", + "check-proposed-api": "node ./src/check-proposed-api.js" }, "dependencies": { "@iarna/toml": "^2.2.5", diff --git a/src/check-proposed-api.js b/src/check-proposed-api.js new file mode 100644 index 000000000000..e870d658f8b8 --- /dev/null +++ b/src/check-proposed-api.js @@ -0,0 +1,22 @@ +const fs = require('fs'); + +const packageJsonPath = './package.json'; + +function checkProposedApiChanges() { + const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); + + const enabledApiProposals = packageJson.enabledApiProposals; + const vscodeEngineVersion = packageJson.engines.vscode; + + const originalPackageJson = JSON.parse(fs.readFileSync(packageJsonPath + '.original', 'utf8')); + const originalEnabledApiProposals = originalPackageJson.enabledApiProposals; + const originalVscodeEngineVersion = originalPackageJson.engines.vscode; + + if (JSON.stringify(enabledApiProposals) !== JSON.stringify(originalEnabledApiProposals) && + vscodeEngineVersion === originalVscodeEngineVersion) { + console.error('Error: `enabledApiProposals` was modified but `vscode` engine version was not updated.'); + process.exit(1); + } +} + +checkProposedApiChanges(); From 97d1660f414263a045b52376c350c5a4255efd8e Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Wed, 11 Dec 2024 13:03:52 -0800 Subject: [PATCH 2/2] destructure --- src/check-proposed-api.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/check-proposed-api.js b/src/check-proposed-api.js index e870d658f8b8..a639538fae55 100644 --- a/src/check-proposed-api.js +++ b/src/check-proposed-api.js @@ -5,8 +5,8 @@ const packageJsonPath = './package.json'; function checkProposedApiChanges() { const packageJson = JSON.parse(fs.readFileSync(packageJsonPath, 'utf8')); - const enabledApiProposals = packageJson.enabledApiProposals; - const vscodeEngineVersion = packageJson.engines.vscode; + const { enabledApiProposals, engines } = packageJson; + const vscodeEngineVersion = engines.vscode; const originalPackageJson = JSON.parse(fs.readFileSync(packageJsonPath + '.original', 'utf8')); const originalEnabledApiProposals = originalPackageJson.enabledApiProposals;