Skip to content

Commit bfba771

Browse files
authored
Merge pull request #144 from tinybirdco/fix/update-local-build-output
Update tinybird build local workspace output
2 parents eff1cbe + aa01a5e commit bfba771

7 files changed

Lines changed: 55 additions & 31 deletions

File tree

src/api/dashboard.test.ts

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,28 @@ describe("getBranchDashboardUrl", () => {
9898
});
9999

100100
describe("getLocalDashboardUrl", () => {
101-
it("generates local dashboard URL with default port", () => {
102-
const result = getLocalDashboardUrl("my_local_workspace");
103-
expect(result).toBe("https://cloud.tinybird.co/local/7181/my_local_workspace");
101+
it("generates local dashboard URL with region info", () => {
102+
const result = getLocalDashboardUrl("https://api.tinybird.co", "my_cloud_workspace", "my_local_workspace");
103+
expect(result).toBe("https://cloud.tinybird.co/gcp/europe-west3/my_cloud_workspace~local~my_local_workspace");
104104
});
105105

106-
it("generates local dashboard URL with custom port", () => {
107-
const result = getLocalDashboardUrl("my_local_workspace", 8080);
108-
expect(result).toBe("https://cloud.tinybird.co/local/8080/my_local_workspace");
106+
it("generates local dashboard URL for US East GCP", () => {
107+
const result = getLocalDashboardUrl("https://api.us-east.tinybird.co", "my_cloud_workspace", "feature_branch");
108+
expect(result).toBe("https://cloud.tinybird.co/gcp/us-east4/my_cloud_workspace~local~feature_branch");
109+
});
110+
111+
it("generates local dashboard URL for AWS", () => {
112+
const result = getLocalDashboardUrl("https://api.us-west-2.aws.tinybird.co", "my_cloud_workspace", "feature_branch");
113+
expect(result).toBe("https://cloud.tinybird.co/aws/us-west-2/my_cloud_workspace~local~feature_branch");
114+
});
115+
116+
it("returns null for unknown regions", () => {
117+
const result = getLocalDashboardUrl("https://api.unknown.tinybird.co", "my_cloud_workspace", "feature_branch");
118+
expect(result).toBeNull();
109119
});
110120

111121
it("handles workspace names with underscores", () => {
112-
const result = getLocalDashboardUrl("dublin_feature_branch");
113-
expect(result).toBe("https://cloud.tinybird.co/local/7181/dublin_feature_branch");
122+
const result = getLocalDashboardUrl("https://api.tinybird.co", "tssdkgnzinit", "dublin_feature_branch");
123+
expect(result).toBe("https://cloud.tinybird.co/gcp/europe-west3/tssdkgnzinit~local~dublin_feature_branch");
114124
});
115125
});

src/api/dashboard.ts

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,16 +106,24 @@ export function getBranchDashboardUrl(
106106
/**
107107
* Generate a local Tinybird dashboard URL
108108
*
109-
* @param workspaceName - The local workspace name
110-
* @param port - The local Tinybird port (default: 7181)
111-
* @returns Local dashboard URL
109+
* The URL follows the format: https://cloud.tinybird.co/{provider}/{region}/{cloudWorkspaceName}~local~{localWorkspaceName}
110+
*
111+
* @param apiUrl - The Tinybird API base URL (e.g., "https://api.tinybird.co")
112+
* @param cloudWorkspaceName - The cloud workspace name (e.g., "tssdkgnzinit")
113+
* @param localWorkspaceName - The local workspace/branch name (e.g., "rama_nuria")
114+
* @returns Local dashboard URL or null if the API URL is not recognized
112115
*
113116
* @example
114117
* ```ts
115-
* getLocalDashboardUrl("my_local_workspace")
116-
* // => "https://cloud.tinybird.co/local/7181/my_local_workspace"
118+
* getLocalDashboardUrl("https://api.tinybird.co", "tssdkgnzinit", "rama_nuria")
119+
* // => "https://cloud.tinybird.co/gcp/europe-west3/tssdkgnzinit~local~rama_nuria"
117120
* ```
118121
*/
119-
export function getLocalDashboardUrl(workspaceName: string, port = 7181): string {
120-
return `https://cloud.tinybird.co/local/${port}/${workspaceName}`;
122+
export function getLocalDashboardUrl(apiUrl: string, cloudWorkspaceName: string, localWorkspaceName: string): string | null {
123+
const regionInfo = parseApiUrl(apiUrl);
124+
if (!regionInfo) {
125+
return null;
126+
}
127+
128+
return `https://cloud.tinybird.co/${regionInfo.provider}/${regionInfo.region}/${cloudWorkspaceName}~local~${localWorkspaceName}`;
121129
}

src/cli/commands/build.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -135,16 +135,19 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
135135

136136
const localTokens = await getLocalTokens();
137137

138+
// Always fetch the cloud workspace name for dashboard URL
139+
const authenticatedWorkspace = await getWorkspace({
140+
baseUrl: config.baseUrl,
141+
token: config.token,
142+
});
143+
const cloudWorkspaceName = authenticatedWorkspace.name;
144+
138145
// Determine workspace name: use authenticated workspace name on main branch,
139146
// otherwise use branch name (for trunk-based development support)
140147
let workspaceName: string;
141148
if (config.isMainBranch || !config.tinybirdBranch) {
142149
// On main branch: use the authenticated workspace name
143-
const authenticatedWorkspace = await getWorkspace({
144-
baseUrl: config.baseUrl,
145-
token: config.token,
146-
});
147-
workspaceName = authenticatedWorkspace.name;
150+
workspaceName = cloudWorkspaceName;
148151
if (debug) {
149152
console.log(`[debug] Using authenticated workspace name: ${workspaceName}`);
150153
}
@@ -165,7 +168,7 @@ export async function runBuild(options: BuildCommandOptions = {}): Promise<Build
165168
gitBranch: config.gitBranch,
166169
tinybirdBranch: workspaceName,
167170
wasCreated,
168-
dashboardUrl: getLocalDashboardUrl(workspaceName),
171+
dashboardUrl: getLocalDashboardUrl(config.baseUrl, cloudWorkspaceName, workspaceName) ?? undefined,
169172
isLocal: true,
170173
};
171174

src/cli/commands/dev.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -193,16 +193,19 @@ export async function runDev(
193193
// Local mode: get tokens from local container and set up workspace
194194
const localTokens = await getLocalTokens();
195195

196+
// Always fetch the cloud workspace name for dashboard URL
197+
const authenticatedWorkspace = await getWorkspace({
198+
baseUrl: config.baseUrl,
199+
token: config.token,
200+
});
201+
const cloudWorkspaceName = authenticatedWorkspace.name;
202+
196203
// Determine workspace name: use authenticated workspace name on main branch,
197204
// otherwise use branch name (for trunk-based development support)
198205
let workspaceName: string;
199206
if (config.isMainBranch || !config.tinybirdBranch) {
200207
// On main branch: use the authenticated workspace name
201-
const authenticatedWorkspace = await getWorkspace({
202-
baseUrl: config.baseUrl,
203-
token: config.token,
204-
});
205-
workspaceName = authenticatedWorkspace.name;
208+
workspaceName = cloudWorkspaceName;
206209
} else {
207210
// On feature branch: use branch name
208211
workspaceName = getLocalWorkspaceName(config.tinybirdBranch, config.cwd);
@@ -221,7 +224,7 @@ export async function runDev(
221224
isLocal: true,
222225
localWorkspace: workspace,
223226
wasCreated,
224-
dashboardUrl: getLocalDashboardUrl(workspace.name),
227+
dashboardUrl: getLocalDashboardUrl(config.baseUrl, cloudWorkspaceName, workspace.name) ?? undefined,
225228
};
226229
} else {
227230
// Branch mode: use Tinybird cloud with branches

src/cli/commands/info.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ export async function runInfo(
195195
workspaceName: localWorkspace.name,
196196
workspaceId: localWorkspace.id,
197197
apiHost: LOCAL_BASE_URL,
198-
dashboardUrl: getLocalDashboardUrl(localWorkspace.name),
198+
dashboardUrl: getLocalDashboardUrl(config.baseUrl, workspace.name, localWorkspace.name) ?? undefined,
199199
token: localWorkspace.token,
200200
};
201201
} catch {

src/cli/commands/open-dashboard.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ export async function runOpenDashboard(
125125
tokens,
126126
workspaceName
127127
);
128-
url = getLocalDashboardUrl(localWorkspace.name);
128+
url = getLocalDashboardUrl(config.baseUrl, workspace.name, localWorkspace.name);
129129
} catch (error) {
130130
return {
131131
success: false,

src/cli/output.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -268,9 +268,9 @@ export function showBranchInfo(info: BranchDisplayInfo): void {
268268
if (info.gitBranch) {
269269
console.log(`» Git branch: ${info.gitBranch}`);
270270
}
271-
// Show local workspace
271+
// Show local branch
272272
const name = info.tinybirdBranch ?? "unknown";
273-
console.log(`» Local workspace: ${name} ${status}`);
273+
console.log(Tinybird Local branch: ${name} ${status}`);
274274
// Show dashboard URL
275275
if (info.dashboardUrl) {
276276
console.log(colorize(` ↳ ${info.dashboardUrl}`, "gray"));

0 commit comments

Comments
 (0)