Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Build pre-release VSIX in CI #1450

Merged
merged 5 commits into from
Mar 20, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ jobs:
npm ci
npm run compile
npm run package
npm run preview-package
- name: Archive production artifacts
uses: actions/upload-artifact@v4
if: always()
Expand Down
7 changes: 7 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
"runtimeArgs": ["${workspaceFolder}/scripts/update_swift_docc_render.ts"]
},
{
"name": "Preview Package",
"type": "node",
"request": "launch",
"runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx",
"runtimeArgs": ["${workspaceFolder}/scripts/preview_package.ts"]
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "swift-vscode",
"displayName": "Swift",
"description": "Swift Language Support for Visual Studio Code.",
"version": "2.1.0",
"version": "2.0.2",
"publisher": "swiftlang",
"icon": "icon.png",
"repository": {
Expand Down Expand Up @@ -1637,7 +1637,7 @@
"compile-tests": "del-cli ./assets/test/**/.build && npm run compile",
"package": "vsce package",
"dev-package": "vsce package --no-update-package-json 2.1.0-dev",
"preview-package": "vsce package --pre-release",
"preview-package": "tsx ./scripts/preview_package.ts",
"tag": "./scripts/tag_release.sh $npm_package_version",
"contributors": "./scripts/generate_contributors_list.sh"
},
Expand Down
42 changes: 42 additions & 0 deletions scripts/lib/utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2024 the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/* eslint-disable no-console */

import * as child_process from "child_process";

export async function exec(
command: string,
args: string[],
options: child_process.SpawnOptionsWithoutStdio = {}
): Promise<void> {
let logMessage = "> " + command;
if (args.length > 0) {
logMessage += " " + args.join(" ");
}
console.log(logMessage + "\n");
return new Promise<void>((resolve, reject) => {
const childProcess = child_process.spawn(command, args, { stdio: "inherit", ...options });
childProcess.once("error", reject);
childProcess.once("close", (code, signal) => {
if (signal !== null) {
reject(new Error(`Process exited due to signal '${signal}'`));
} else if (code !== 0) {
reject(new Error(`Process exited with code ${code}`));
} else {
resolve();
}
console.log("");
});
});
}
61 changes: 61 additions & 0 deletions scripts/preview_package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2024 the VS Code Swift project authors
// Licensed under Apache License v2.0
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of VS Code Swift project authors
//
// SPDX-License-Identifier: Apache-2.0
//
//===----------------------------------------------------------------------===//
/* eslint-disable no-console */

import * as path from "path";
import * as semver from "semver";
import { readFile } from "fs/promises";
import { exec } from "./lib/utilities";

/**
* Formats the given date as a string in the form "YYYYMMddhhmm".
*
* @param date The date to format as a string.
* @returns The formatted date.
*/
function formatDate(date: Date): string {
const year = date.getUTCFullYear().toString().padStart(4, "0");
const month = (date.getUTCMonth() + 1).toString().padStart(2, "0");
const day = date.getUTCDate().toString().padStart(2, "0");
const hour = date.getUTCHours().toString().padStart(2, "0");
const minutes = date.getUTCMinutes().toString().padStart(2, "0");
return year + month + day + hour + minutes;
}

(async () => {
const rootDirectory = path.join(__dirname, "..");
// Grab the existing version number from the package.json
const packageJSON = JSON.parse(
await readFile(path.join(rootDirectory, "package.json"), "utf-8")
);
if (typeof packageJSON.version !== "string") {
throw new Error("Version number in package.json is not a string");
}
const version = semver.parse(packageJSON.version);
if (version === null) {
throw new Error("Unable to parse version number in package.json");
}
// Increment the minor version and set the patch version to today's date
const minor = version.minor + 1;
const patch = formatDate(new Date());
const previewVersion = `${version.major}.${minor}.${patch}`;
await exec(
"npx",
["vsce", "package", "--pre-release", "--no-update-package-json", previewVersion],
{ cwd: rootDirectory }
);
})().catch(error => {
console.error(error);
process.exit(1);
});
28 changes: 1 addition & 27 deletions scripts/update_swift_docc_render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
/* eslint-disable no-console */

import simpleGit, { ResetMode } from "simple-git";
import { spawn } from "child_process";
import { stat, mkdtemp, mkdir, rm, readdir } from "fs/promises";
import * as path from "path";
import { tmpdir } from "os";
import * as semver from "semver";
import { exec } from "./lib/utilities";

function checkNodeVersion() {
const nodeVersion = semver.parse(process.versions.node);
Expand Down Expand Up @@ -57,32 +57,6 @@ async function cloneSwiftDocCRender(buildDirectory: string): Promise<string> {
return swiftDocCRenderDirectory;
}

async function exec(
command: string,
args: string[],
options: { cwd?: string; env?: { [key: string]: string } } = {}
): Promise<void> {
let logMessage = "> " + command;
if (args.length > 0) {
logMessage += " " + args.join(" ");
}
console.log(logMessage + "\n");
return new Promise<void>((resolve, reject) => {
const childProcess = spawn(command, args, { stdio: "inherit", ...options });
childProcess.once("error", reject);
childProcess.once("close", (code, signal) => {
if (signal !== null) {
reject(new Error(`Process exited due to signal '${signal}'`));
} else if (code !== 0) {
reject(new Error(`Process exited with code ${code}`));
} else {
resolve();
}
console.log("");
});
});
}

(async () => {
const outputDirectory = path.join(__dirname, "..", "assets", "swift-docc-render");
if (process.argv.includes("postinstall")) {
Expand Down
Loading