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 package.json
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,7 @@
"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",
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.`
);
}
});
27 changes: 27 additions & 0 deletions scripts/lib/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
/* 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.
Expand All @@ -31,6 +34,30 @@ export async function main(mainFn: () => Promise<void>): Promise<void> {
}
}

/**
* 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.
*
Expand Down
19 changes: 3 additions & 16 deletions scripts/preview_package.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@
//===----------------------------------------------------------------------===//
/* eslint-disable no-console */

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

/**
* Formats the given date as a string in the form "YYYYMMddhhmm".
Expand All @@ -34,18 +31,8 @@ function formatDate(date: Date): string {
}

main(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");
}
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());
Expand Down
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
Loading