Skip to content

Commit 651965f

Browse files
authored
Publish to OpenVSX (#3879)
1 parent 650e6d5 commit 651965f

File tree

2 files changed

+46
-17
lines changed

2 files changed

+46
-17
lines changed

.github/workflows/main.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,3 +120,4 @@ jobs:
120120
---
121121
See the full [CHANGELOG](https://github.com/prettier/prettier-vscode/blob/main/CHANGELOG.md) for details."
122122
- run: npx @vscode/vsce publish -p ${{ secrets.MARKETPLACE_TOKEN }} ${{ steps.check_prerelease.outputs.is_prerelease == 'true' && '--pre-release' || '' }}
123+
- run: npx ovsx publish "${{ env.VSIX_PATH }}" -p ${{ secrets.OPENVSX_TOKEN }} ${{ steps.check_prerelease.outputs.is_prerelease == 'true' && '--pre-release' || '' }}

scripts/release.mjs

Lines changed: 45 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,33 @@
33
* Automated release script for prettier-vscode
44
*
55
* Usage:
6-
* npm run release major - Bump major version (11.0.0 -> 12.0.0)
7-
* npm run release minor - Bump minor version (11.0.0 -> 11.1.0)
8-
* npm run release patch - Bump patch version (11.0.0 -> 11.0.1)
9-
* npm run release patch -- --pre - Patch as prerelease (tag: v11.0.1-pre)
10-
* npm run release minor 12.1.0 - Use specific version
11-
* npm run release patch 12.0.1 --pre - Specific version as prerelease
6+
* npm run release major - Bump major version (11.0.0 -> 12.0.0)
7+
* npm run release minor - Bump minor version (11.0.0 -> 11.1.0)
8+
* npm run release patch - Bump patch version (11.0.0 -> 11.0.1)
9+
* npm run release patch -- --pre - Patch as prerelease (11.0.1 -> 11.0.2, tag: v11.0.2-pre)
10+
* npm run release version - Use specific version
11+
* npm run release version 12.0.1 --pre - Specific version as prerelease
12+
*
13+
*
14+
* The script performs the following steps:
15+
*
16+
* 1. Validates the input arguments.
17+
* 2. Checks for uncommitted changes in the working directory. The script should fail if there are any.
18+
* 3. Ensures that stable releases are made from the `main` branch.
19+
* 4. Reads the current version from `package.json`.
20+
* 5. Calculates the new version based on the release type or uses the provided version.
21+
* 6. Updates `package.json` with the new version.
22+
* 7. Runs `npm install` to update `package-lock.json`.
23+
* 8. Updates `CHANGELOG.md` to reflect the new version (skipped for prereleases).
24+
* 9. Stages the changes to `package.json`, `package-lock.json`, and `CHANGELOG.md`.
25+
* 10. Creates a git commit and tag for the new version.
26+
* 11. Pushes the commit and tag to the remote repository.
27+
*
1228
*/
1329
import fs from "fs/promises";
1430
import { execSync } from "child_process";
1531

16-
const RELEASE_TYPES = ["major", "minor", "patch"];
32+
const RELEASE_TYPES = ["major", "minor", "patch", "version"];
1733

1834
function exec(cmd, options = {}) {
1935
console.log(`$ ${cmd}`);
@@ -109,25 +125,32 @@ async function main() {
109125

110126
if (!releaseType || !RELEASE_TYPES.includes(releaseType)) {
111127
console.error(
112-
"Usage: npm run release <major|minor|patch> [version] [--pre]",
128+
"Usage: npm run release <major|minor|patch|version> [version] [--pre]",
113129
);
114130
console.error("");
115131
console.error("Examples:");
116-
console.error(" npm run release major - 11.0.0 -> 12.0.0");
117-
console.error(" npm run release minor - 11.0.0 -> 11.1.0");
118-
console.error(" npm run release patch - 11.0.0 -> 11.0.1");
132+
console.error(" npm run release major - 11.0.0 -> 12.0.0");
133+
console.error(" npm run release minor - 11.0.0 -> 11.1.0");
134+
console.error(" npm run release patch - 11.0.0 -> 11.0.1");
119135
console.error(
120-
" npm run release patch -- --pre - 11.0.0 -> 11.0.1 (tag: v11.0.1-pre)",
136+
" npm run release patch -- --pre - 11.0.1 -> 11.0.2 (tag: v11.0.2-pre)",
121137
);
122138
console.error(
123-
" npm run release minor 12.1.0 - Use specific version",
139+
" npm run release version 12.0.1 - Use specific version",
124140
);
125141
console.error(
126-
" npm run release patch 12.0.1 --pre - Specific version as prerelease",
142+
" npm run release version 12.0.1 --pre - Specific version as prerelease",
127143
);
128144
process.exit(1);
129145
}
130146

147+
// "version" type requires a version number
148+
if (releaseType === "version" && !manualVersion) {
149+
console.error("Error: 'version' release type requires a version number.");
150+
console.error("Usage: npm run release version <X.Y.Z> [--pre]");
151+
process.exit(1);
152+
}
153+
131154
// Validate manual version if provided
132155
if (manualVersion) {
133156
try {
@@ -153,7 +176,9 @@ async function main() {
153176
console.error(`Error: Stable releases must be run from the main branch.`);
154177
console.error(`Current branch: ${currentBranch}`);
155178
console.error("\nTo release a prerelease from this branch, use:");
156-
console.error(" npm run release <major|minor|patch> -- --pre");
179+
console.error(
180+
" npm run release <major|minor|patch|version> [version] -- --pre",
181+
);
157182
process.exit(1);
158183
}
159184

@@ -180,14 +205,17 @@ async function main() {
180205
);
181206
console.log("Updated package.json");
182207

208+
// Run npm install to update package-lock.json
209+
exec("npm install");
210+
183211
// Update changelog (skip for prereleases)
184212
await updateChangelog(newVersion, isPrerelease);
185213

186214
// Stage changes
187-
exec("git add package.json CHANGELOG.md");
215+
exec("git add package.json package-lock.json CHANGELOG.md");
188216

189217
// Create commit and tag
190-
exec(`git commit -m "${tagName}"`);
218+
exec(`git commit -m "Version ${newVersion}"`);
191219
exec(`git tag ${tagName}`);
192220

193221
console.log(`\nCreated commit and tag: ${tagName}`);

0 commit comments

Comments
 (0)