Skip to content
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
12 changes: 11 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,17 @@
files: coverage/coverage-final.json
token: ${{ secrets.CODECOV_TOKEN }}

version:
name: Version sync
runs-on: ubuntu-latest
steps:
- *checkout
- *setup-node-22
- *install
- name: Check src/version.ts matches package.json
run: npm run check:version

examples:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {}
name: Examples
runs-on: ubuntu-latest
steps:
Expand All @@ -90,7 +100,7 @@
check:
name: CI check
if: always()
needs: [lint, typecheck, test, examples]
needs: [lint, typecheck, test, examples, version]
runs-on: ubuntu-latest
steps:
- uses: re-actors/alls-green@release/v1
Expand Down
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@
],
"scripts": {
"generate": "rm -rf src/generated && buf generate",
"build": "tsc",
"gen-version": "node scripts/gen-version.mjs",
"check:version": "node scripts/gen-version.mjs --check",
"build": "node scripts/gen-version.mjs && tsc",
"lint": "biome check src/ test/",
"format": "biome format --write src/ test/",
"typecheck": "tsc --noEmit",
Expand Down
28 changes: 28 additions & 0 deletions scripts/gen-version.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/usr/bin/env node
// Generates src/version.ts from package.json.
// With --check: exits non-zero if the file is out of sync.
import { readFileSync, writeFileSync } from "node:fs";

const pkg = JSON.parse(readFileSync("package.json", "utf8"));
const version = pkg.version;

const content =
`// Generated by scripts/gen-version.mjs — do not edit manually.\n` +
`export const VERSION = "${version}";\n`;

if (process.argv.includes("--check")) {
const existing = readFileSync("src/version.ts", "utf8");
if (existing !== content) {
const match = existing.match(/VERSION = "([^"]+)"/);
console.error(
`src/version.ts is out of sync with package.json\n` +
` package.json : ${version}\n` +
` src/version.ts: ${match?.[1] ?? "(unreadable)"}`,
);
process.exit(1);
}
console.log(`src/version.ts is in sync with package.json (${version})`);
} else {
writeFileSync("src/version.ts", content);
console.log(`Generated src/version.ts with VERSION = "${version}"`);
}
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* @packageDocumentation
*/

export const VERSION = "0.2.0-alpha.1";
export { VERSION } from "./version.js";
export const SUPPORTED_SERVER_VERSION = ">=0.8.0,<1.0.0";
export const PROTO_VERSION = "v1";

Expand Down
2 changes: 2 additions & 0 deletions src/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// Generated by scripts/gen-version.mjs — do not edit manually.
export const VERSION = "0.3.0-alpha.1";
8 changes: 6 additions & 2 deletions test/version.test.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
import { createRequire } from "node:module";
import { describe, expect, it } from "vitest";
import { PROTO_VERSION, SUPPORTED_SERVER_VERSION, VERSION } from "../src/index.js";

const require = createRequire(import.meta.url);
const pkg = require("../package.json") as { version: string };

describe("version constants", () => {
it("exports SDK version", () => {
expect(VERSION).toBe("0.2.0-alpha.1");
it("exports SDK version matching package.json", () => {
expect(VERSION).toBe(pkg.version);
});

it("exports supported server version range", () => {
Expand Down