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 all commits
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"]
}
]
}
5 changes: 3 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 @@ -1630,14 +1630,15 @@
"postinstall": "npm run update-swift-docc-render",
"pretest": "npm run compile-tests",
"soundness": "scripts/soundness.sh",
"check-package-json": "tsx ./scripts/check_package_json.ts",
"test": "vscode-test",
"integration-test": "npm test -- --label integrationTests",
"unit-test": "npm test -- --label unitTests",
"coverage": "npm test -- --coverage",
"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
25 changes: 25 additions & 0 deletions scripts/check_package_json.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2025 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 { getExtensionVersion, main } from "./lib/utilities";

main(async () => {
const version = await getExtensionVersion();
if (version.minor % 2 !== 0) {
throw new Error(
`Invalid version number in package.json. ${version.toString()} does not have an even numbered minor version.`
);
}
});
92 changes: 92 additions & 0 deletions scripts/lib/utilities.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2025 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";
import { readFile } from "fs/promises";
import * as path from "path";
import * as semver from "semver";

/**
* Executes the provided main function for the script while logging any errors.
*
* If an error is caught then the process will exit with code 1.
*
* @param mainFn The main function of the script that will be run.
*/
export async function main(mainFn: () => Promise<void>): Promise<void> {
try {
await mainFn();
} catch (error) {
console.error(error);
process.exit(1);
}
}

/**
* Returns the root directory of the repository.
*/
export function getRootDirectory(): string {
return path.join(__dirname, "..", "..");
}

/**
* Retrieves the version number from the package.json.
*/
export async function getExtensionVersion(): Promise<semver.SemVer> {
const packageJSON = JSON.parse(
await readFile(path.join(getRootDirectory(), "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");
}
return version;
}

/**
* Executes the given command, inheriting the current process' stdio.
*
* @param command The command to execute.
* @param args The arguments to provide to the command.
* @param options The options for executing the command.
*/
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("");
});
});
}
53 changes: 53 additions & 0 deletions scripts/preview_package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the VS Code Swift open source project
//
// Copyright (c) 2025 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 { exec, getExtensionVersion, getRootDirectory, main } 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;
}

main(async () => {
const rootDirectory = getRootDirectory();
const version = await getExtensionVersion();
// 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}`;
// Make sure that the new minor version is odd
if (minor % 2 !== 1) {
throw new Error(
`The minor version for the pre-release extension is even (${previewVersion}).` +
" The version in the package.json has probably been incorrectly set to an odd minor version."
);
}
// Use VSCE to package the extension
await exec(
"npx",
["vsce", "package", "--pre-release", "--no-update-package-json", previewVersion],
{ cwd: rootDirectory }
);
});
3 changes: 3 additions & 0 deletions scripts/soundness.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ function replace_acceptable_years() {
sed -e 's/20[12][0123456789]-20[12][0123456789]/YEARS/' -e 's/20[12][0123456789]/YEARS/'
}

printf "=> Checking package.json..."
npm run check-package-json

printf "=> Checking license headers... "
tmp=$(mktemp /tmp/.vscode-swift-soundness_XXXXXX)

Expand Down
35 changes: 3 additions & 32 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, getRootDirectory, main } from "./lib/utilities";

function checkNodeVersion() {
const nodeVersion = semver.parse(process.versions.node);
Expand Down Expand Up @@ -57,34 +57,8 @@ 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");
main(async () => {
const outputDirectory = path.join(getRootDirectory(), "assets", "swift-docc-render");
if (process.argv.includes("postinstall")) {
try {
await stat(outputDirectory);
Expand Down Expand Up @@ -114,7 +88,4 @@ async function exec(
console.error(error);
});
}
})().catch(error => {
console.error(error);
process.exit(1);
});
Loading