mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 08:06:16 +00:00
fix: refuse ambiguous gitsync-settings override target instead of guessing
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
58ebf930f7
commit
a668e670ee
@@ -6,7 +6,7 @@ import { GlobalOptions } from "../../types.ts";
|
||||
import { requireLogin } from "../../core/auth.ts";
|
||||
import { resolveWorkspace } from "../../core/context.ts";
|
||||
import * as wmill from "../../../gen/services.gen.ts";
|
||||
import { SyncOptions, readConfigFile, DEFAULT_SYNC_OPTIONS, getWmillYamlPath, findWorkspaceByGitBranch, WorkspacesConfig } from "../../core/conf.ts";
|
||||
import { SyncOptions, readConfigFile, DEFAULT_SYNC_OPTIONS, getWmillYamlPath, findWorkspaceByGitBranch, WorkspacesConfig, getWorkspaceNames, getEffectiveGitBranch } from "../../core/conf.ts";
|
||||
import { yamlOptions } from "../sync/sync.ts";
|
||||
import { deepEqual } from "../../utils/utils.ts";
|
||||
import { getCurrentGitBranch, isGitRepository } from "../../utils/git.ts";
|
||||
@@ -450,8 +450,19 @@ export async function pullGitSyncSettings(
|
||||
if (!overrideTarget && isGitRepository()) {
|
||||
const currentBranch = getCurrentGitBranch();
|
||||
if (currentBranch) {
|
||||
overrideTarget =
|
||||
findWorkspaceByGitBranch(localConfig.workspaces, currentBranch)?.[0] ?? currentBranch;
|
||||
// A branch shared by several entries does not say which workspace this
|
||||
// is; guessing would overwrite another workspace's overrides
|
||||
const onBranch = getWorkspaceNames(localConfig.workspaces).filter(
|
||||
(name) =>
|
||||
getEffectiveGitBranch(name, (localConfig.workspaces as any)[name]) === currentBranch,
|
||||
);
|
||||
if (onBranch.length > 1) {
|
||||
throw new Error(
|
||||
`Workspace entries ${onBranch.join(", ")} all use git branch '${currentBranch}' and none matches workspace '${workspace.workspaceId}'. ` +
|
||||
`Name its entry '${workspace.workspaceId}' so it can be resolved.`,
|
||||
);
|
||||
}
|
||||
overrideTarget = onBranch[0] ?? currentBranch;
|
||||
}
|
||||
}
|
||||
if (overrideTarget) {
|
||||
|
||||
@@ -8,31 +8,31 @@ test("gitsync-settings: entries sharing a gitBranch resolve by workspace", async
|
||||
const config: SyncOptions = {
|
||||
includes: ["f/**"],
|
||||
workspaces: {
|
||||
"flh-nonprod": {
|
||||
"team-a-staging": {
|
||||
baseUrl: "https://windmill.example.com/",
|
||||
gitBranch: "nonprod",
|
||||
overrides: { includes: ["f/ops_flh/**"] },
|
||||
gitBranch: "staging",
|
||||
overrides: { includes: ["f/team_a/**"] },
|
||||
},
|
||||
provinzial: {
|
||||
"team-b": {
|
||||
baseUrl: "https://windmill.example.com/",
|
||||
workspaceId: "provinzial-nonprod",
|
||||
gitBranch: "nonprod",
|
||||
overrides: { includes: ["f/ops_provinzial/**"] },
|
||||
workspaceId: "team-b-staging",
|
||||
gitBranch: "staging",
|
||||
overrides: { includes: ["f/team_b/**"] },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const byFlag = await getEffectiveSettingsForWorkspace(
|
||||
config,
|
||||
{ workspace: "flh-nonprod", jsonOutput: true },
|
||||
{ remote: "http://windmill_server:8000/", workspaceId: "flh-nonprod" },
|
||||
{ workspace: "team-a-staging", jsonOutput: true },
|
||||
{ remote: "http://windmill_server:8000/", workspaceId: "team-a-staging" },
|
||||
);
|
||||
expect(byFlag.includes).toEqual(["f/ops_flh/**"]);
|
||||
expect(byFlag.includes).toEqual(["f/team_a/**"]);
|
||||
|
||||
const byProfile = await getEffectiveSettingsForWorkspace(
|
||||
config,
|
||||
{ workspace: "provinzial-nonprod", jsonOutput: true },
|
||||
{ remote: "https://windmill.example.com/", workspaceId: "provinzial-nonprod" },
|
||||
{ workspace: "team-b-staging", jsonOutput: true },
|
||||
{ remote: "https://windmill.example.com/", workspaceId: "team-b-staging" },
|
||||
);
|
||||
expect(byProfile.includes).toEqual(["f/ops_provinzial/**"]);
|
||||
expect(byProfile.includes).toEqual(["f/team_b/**"]);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user