Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix sdk pre-release version calculation and test-unit glob (#62729)

Timofey Kachalovc2016c28c85e
diff --git a/.github/workflows/release-embedding-sdk.yml b/.github/workflows/release-embedding-sdk.yml
index 99274cbd5e1..659f0cae519 100644
--- a/.github/workflows/release-embedding-sdk.yml
+++ b/.github/workflows/release-embedding-sdk.yml
@@ -195,45 +195,18 @@ jobs:
uses: actions/github-script@v7
with:
script: |
- const branch = "${{ inputs.branch }}";
+ const { getNextSdkVersion } = require('${{ github.workspace }}/release/dist/index.cjs');
+ const branch = "${{ inputs.branch }}";
const currentVersion = "${{ steps.current-sdk-version.outputs.sdk_current_version }}";
- const [currentVersionWithoutSuffix, suffix] = currentVersion.split("-");
- const versionParts = currentVersionWithoutSuffix.split(".");
- const [_, majorVersion] = versionParts
-
- if (branch === "master") {
- if (!suffix) {
- throw new Error("Expected pre-release suffix on master branch, got: " + currentVersion);
- }
-
- // When the `currentVersion` is `0.57.0-alpha.1`
- // The `suffix` is `alpha.1`
- // The `preReleaseLabel is `alpha`
- // The `preReleaseVersion` is `1`
- const suffixParts = suffix ? suffix.split(".") : [];
-
- const preReleaseLabel = suffixParts[0] ?? "";
- const preReleaseVersion = suffixParts[1] ? parseInt(suffixParts[1]) : 0;
- const nextPreReleaseVersion = preReleaseVersion + 1;
-
- return {
- version: `${currentVersionWithoutSuffix}-${preReleaseLabel}.${nextPreReleaseVersion}`,
- preReleaseLabel,
- majorVersion,
- };
- }
-
- // 0.57.0 => 0.57.1
- // 0.57.0-alpha -> 0.57.1-alpha
- versionParts[versionParts.length - 1] = parseInt(versionParts.at(-1)) + 1;
- const newVersion = versionParts.join(".");
+
+ const result = getNextSdkVersion(branch, currentVersion);
return {
- version: suffix ? `${newVersion}-${suffix}` : newVersion,
- preReleaseLabel: '',
- majorVersion
- }
+ version: result.version,
+ preReleaseLabel: result.preReleaseLabel,
+ majorVersion: result.majorVersion
+ };
- name: Append workflow summary
run: |
diff --git a/package.json b/package.json
index 0b540c82103..19a1e9e9198 100644
--- a/package.json
+++ b/package.json
@@ -437,7 +437,7 @@
"embedding-sdk:generate-changelog": "yarn conventional-changelog --config enterprise/frontend/src/embedding-sdk-bundle/conventional-changelog-config.js",
"embedding-sdk:publish": "cd ./resources/embedding-sdk && npm publish",
"embedding-sdk:generate-nextjs-compat": "tsx enterprise/frontend/src/embedding-sdk-package/bin/generate-nextjs-compat.ts",
- "embedding-sdk:test-unit": "yarn test-unit enterprise/frontend/src/embedding-sdk-{package,bundle,shared}/",
+ "embedding-sdk:test-unit": "yarn test-unit enterprise/frontend/src/embedding-sdk-package/ enterprise/frontend/src/embedding-sdk-bundle/ enterprise/frontend/src/embedding-sdk-shared/",
"embedding-sdk:dts:generate": "yarn embedding-sdk:clean:tsbuildinfo && yarn tsc --project tsconfig.sdk.json || true && yarn embedding-sdk:dts:fixup",
"embedding-sdk:dts:fixup": "node ./bin/embedding-sdk/fixup-types-after-compilation.js",
"embedding-sdk:docs:generate:pure": "typedoc --options ./.typedoc/typedoc.html.config.js && typedoc --options ./.typedoc/typedoc.markdown.config.js",
diff --git a/release/src/version-helpers.ts b/release/src/version-helpers.ts
index 1355ba3b446..5c335db4c1c 100644
--- a/release/src/version-helpers.ts
+++ b/release/src/version-helpers.ts
@@ -401,3 +401,56 @@ export const getNextPatchVersion = async ({
return nextPatch;
};
+
+export const getNextSdkVersion = (
+ branch: string,
+ currentVersion: string,
+): {
+ version: string;
+ preReleaseLabel: string;
+ majorVersion: string;
+} => {
+ const [currentVersionWithoutSuffix, suffix] = currentVersion.split("-");
+ const versionParts = currentVersionWithoutSuffix.split(".");
+ const [_, majorVersion] = versionParts;
+
+ if (branch === "master") {
+ if (!suffix) {
+ throw new Error(
+ "Expected pre-release suffix on master branch, got: " + currentVersion,
+ );
+ }
+
+ // When the `currentVersion` is `0.57.0-alpha.1`
+ // The `suffix` is `alpha.1`
+ // The `preReleaseLabel is `alpha`
+ // The `preReleaseVersion` is `1`
+ const suffixParts = suffix ? suffix.split(".") : [];
+
+ const preReleaseLabel = suffixParts[0] ?? "";
+ const preReleaseVersion = suffixParts[1] ? parseInt(suffixParts[1]) : null;
+ const nextPreReleaseVersion =
+ preReleaseVersion !== null ? preReleaseVersion + 1 : 0;
+
+ return {
+ version: `${currentVersionWithoutSuffix}-${preReleaseLabel}.${nextPreReleaseVersion}`,
+ preReleaseLabel,
+ majorVersion,
+ };
+ }
+
+ // 0.57.0 => 0.57.1
+ // 0.57.0-alpha -> 0.57.1-alpha
+ const minorVersion = versionParts.at(-1) ?? 0;
+ versionParts[versionParts.length - 1] = String(
+ minorVersion ? parseInt(minorVersion) + 1 : 0,
+ );
+
+ const newVersion = versionParts.join(".");
+
+ return {
+ version: suffix ? `${newVersion}-${suffix}` : newVersion,
+ preReleaseLabel: "",
+ majorVersion,
+ };
+};
diff --git a/release/src/version-helpers.unit.spec.ts b/release/src/version-helpers.unit.spec.ts
index 40bf6d32ce3..915d8ab1878 100644
--- a/release/src/version-helpers.unit.spec.ts
+++ b/release/src/version-helpers.unit.spec.ts
@@ -12,6 +12,7 @@ import {
getMajorVersionNumberFromReleaseBranch,
getMilestoneName,
getMinorVersion,
+ getNextSdkVersion,
getNextVersions,
getOSSVersion,
getReleaseBranch,
@@ -807,19 +808,67 @@ describe("version-helpers", () => {
it.each([
["v0.52.3", "52"],
["v1.52", "52"],
- ["v1.43.2.1", "43"]
- ])("%s -> %s" , (input, expected) => {
+ ["v1.43.2.1", "43"],
+ ])("%s -> %s", (input, expected) => {
expect(getMajorVersion(input)).toBe(expected);
- })
+ });
});
describe("getMinorVersion", () => {
it.each([
["v0.52.3", "3"],
["v1.52", "0"],
- ["v1.43.2.1", "2"]
- ])("%s -> %s" , (input, expected) => {
+ ["v1.43.2.1", "2"],
+ ])("%s -> %s", (input, expected) => {
expect(getMinorVersion(input)).toBe(expected);
- })
+ });
+ });
+
+ describe("getNextSdkVersion", () => {
+ describe("master branch (pre-release versions)", () => {
+ it("should increment pre-release version if suffix exists", () => {
+ const result = getNextSdkVersion("master", "0.57.0-alpha.1");
+ expect(result).toEqual({
+ version: "0.57.0-alpha.2",
+ preReleaseLabel: "alpha",
+ majorVersion: "57",
+ });
+ });
+
+ it("should set next pre-release version to .1 if no numeric part in suffix", () => {
+ const result = getNextSdkVersion("master", "0.57.0-beta");
+ expect(result).toEqual({
+ version: "0.57.0-beta.0",
+ preReleaseLabel: "beta",
+ majorVersion: "57",
+ });
+ });
+
+ it("should throw an error if no suffix is provided on master branch", () => {
+ expect(() => getNextSdkVersion("master", "0.57.0")).toThrow(
+ "Expected pre-release suffix on master branch, got: 0.57.0",
+ );
+ });
+ });
+
+ describe("release/stable branches (non-master)", () => {
+ it("should increment patch version when no suffix", () => {
+ const result = getNextSdkVersion("release-x.57.x", "0.57.0");
+ expect(result).toEqual({
+ version: "0.57.1",
+ preReleaseLabel: "",
+ majorVersion: "57",
+ });
+ });
+
+ it("should increment patch version but keeps suffix if present", () => {
+ const result = getNextSdkVersion("release-x.57.x", "0.57.0-alpha.1");
+ expect(result).toEqual({
+ version: "0.57.1-alpha.1",
+ preReleaseLabel: "",
+ majorVersion: "57",
+ });
+ });
+ });
});
});