mirror of
https://github.com/windmill-labs/windmill.git
synced 2026-11-28 16:06:22 +00:00
fix: resolve gitsync-settings wmill.yaml entry by workspace, not branch
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
120415af15
commit
a7579fb2ad
@@ -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, getEffectiveSettings, DEFAULT_SYNC_OPTIONS, getWmillYamlPath, findWorkspaceByGitBranch, WorkspacesConfig } from "../../core/conf.ts";
|
||||
import { SyncOptions, readConfigFile, DEFAULT_SYNC_OPTIONS, getWmillYamlPath, findWorkspaceByGitBranch, WorkspacesConfig } from "../../core/conf.ts";
|
||||
import { yamlOptions } from "../sync/sync.ts";
|
||||
import { deepEqual } from "../../utils/utils.ts";
|
||||
import { getCurrentGitBranch, isGitRepository } from "../../utils/git.ts";
|
||||
@@ -21,7 +21,8 @@ import {
|
||||
displayChanges,
|
||||
applyBackendSettingsToBranch,
|
||||
normalizeRepoPath,
|
||||
outputResult
|
||||
outputResult,
|
||||
getEffectiveSettingsForWorkspace
|
||||
} from "./utils.ts";
|
||||
|
||||
export async function pullGitSyncSettings(
|
||||
@@ -199,7 +200,7 @@ export async function pullGitSyncSettings(
|
||||
|
||||
// For existing wmill.yaml files, continue with the normal flow
|
||||
// Calculate current settings once and reuse throughout
|
||||
const currentSettings = await getEffectiveSettings(localConfig, opts.promotion, true, opts.jsonOutput);
|
||||
const currentSettings = await getEffectiveSettingsForWorkspace(localConfig, opts, workspace);
|
||||
|
||||
// Determine write mode for branch-based configuration
|
||||
let writeMode: WriteMode = "replace";
|
||||
@@ -280,7 +281,7 @@ export async function pullGitSyncSettings(
|
||||
!opts.override
|
||||
) {
|
||||
// Recalculate current settings with promotion if needed
|
||||
const effectiveCurrentSettings = await getEffectiveSettings(localConfig, opts.promotion, true, opts.jsonOutput);
|
||||
const effectiveCurrentSettings = await getEffectiveSettingsForWorkspace(localConfig, opts, workspace);
|
||||
// Use the same logic as diff to determine current settings
|
||||
const gitSyncBackend = GitSyncSettingsConverter.extractGitSyncFields(
|
||||
GitSyncSettingsConverter.normalize(backendSyncOptions),
|
||||
|
||||
@@ -7,7 +7,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, validateBranchConfiguration, getEffectiveSettings, getWmillYamlPath } from "../../core/conf.ts";
|
||||
import { SyncOptions, readConfigFile, validateBranchConfiguration, getWmillYamlPath } from "../../core/conf.ts";
|
||||
import { deepEqual } from "../../utils/utils.ts";
|
||||
|
||||
import { GitSyncRepository } from "./types.ts";
|
||||
@@ -19,7 +19,8 @@ import {
|
||||
generateChanges,
|
||||
displayChanges,
|
||||
normalizeRepoPath,
|
||||
outputResult
|
||||
outputResult,
|
||||
getEffectiveSettingsForWorkspace
|
||||
} from "./utils.ts";
|
||||
|
||||
export async function pushGitSyncSettings(
|
||||
@@ -178,7 +179,7 @@ export async function pushGitSyncSettings(
|
||||
|
||||
// Get effective settings for this workspace/repo
|
||||
const repoPath = normalizeRepoPath(selectedRepo.git_repo_resource_path);
|
||||
const effectiveSettings = await getEffectiveSettings(localConfig, opts.promotion, true, opts.jsonOutput);
|
||||
const effectiveSettings = await getEffectiveSettingsForWorkspace(localConfig, opts, workspace);
|
||||
|
||||
// Convert to backend format
|
||||
const backendFormat = GitSyncSettingsConverter.toBackendFormat(effectiveSettings);
|
||||
|
||||
@@ -1,7 +1,14 @@
|
||||
import { colors } from "@cliffy/ansi/colors";
|
||||
import * as log from "../../core/log.ts";
|
||||
import { deepEqual, selectRepository } from "../../utils/utils.ts";
|
||||
import { SyncOptions, getEffectiveSettings, DEFAULT_SYNC_OPTIONS } from "../../core/conf.ts";
|
||||
import {
|
||||
SyncOptions,
|
||||
getEffectiveSettings,
|
||||
DEFAULT_SYNC_OPTIONS,
|
||||
resolveWsNameForConfigFromFlags,
|
||||
inferWsNameFromProfile,
|
||||
inferWsNameFromForkBranch,
|
||||
} from "../../core/conf.ts";
|
||||
import { GitSyncRepository, GIT_SYNC_FIELDS } from "./types.ts";
|
||||
import { GitSyncSettingsConverter } from "./converter.ts";
|
||||
|
||||
@@ -21,6 +28,24 @@ export function outputResult(opts: { jsonOutput?: boolean }, result: {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* The wmill.yaml settings that apply to the workspace being synced. Resolved by
|
||||
* workspace first, as `sync pull/push` do: several entries can share one
|
||||
* `gitBranch`, so matching on the checked-out branch alone picks whichever of
|
||||
* them comes first in the file.
|
||||
*/
|
||||
export async function getEffectiveSettingsForWorkspace(
|
||||
config: SyncOptions,
|
||||
opts: { workspace?: string; promotion?: string; jsonOutput?: boolean },
|
||||
workspace: { remote: string; workspaceId: string },
|
||||
): Promise<SyncOptions> {
|
||||
const wsName =
|
||||
resolveWsNameForConfigFromFlags({ workspaces: config.workspaces, workspace: opts.workspace }) ??
|
||||
inferWsNameFromProfile(config, workspace) ??
|
||||
inferWsNameFromForkBranch(config, workspace.workspaceId);
|
||||
return await getEffectiveSettings(config, opts.promotion, true, opts.jsonOutput, wsName);
|
||||
}
|
||||
|
||||
// Helper to normalize repository path by removing $res: prefix
|
||||
export function normalizeRepoPath(path: string): string {
|
||||
return path.replace(/^\$res:/, "");
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
import { expect, test } from "bun:test";
|
||||
import type { SyncOptions } from "../src/core/conf.ts";
|
||||
import { getEffectiveSettingsForWorkspace } from "../src/commands/gitsync-settings/utils.ts";
|
||||
|
||||
// Entries sharing a gitBranch must resolve by workspace, not by the first one
|
||||
// bound to the branch.
|
||||
test("gitsync-settings: entries sharing a gitBranch resolve by workspace", async () => {
|
||||
const config: SyncOptions = {
|
||||
includes: ["f/**"],
|
||||
workspaces: {
|
||||
"flh-nonprod": {
|
||||
baseUrl: "https://windmill.example.com/",
|
||||
gitBranch: "nonprod",
|
||||
overrides: { includes: ["f/ops_flh/**"] },
|
||||
},
|
||||
provinzial: {
|
||||
baseUrl: "https://windmill.example.com/",
|
||||
workspaceId: "provinzial-nonprod",
|
||||
gitBranch: "nonprod",
|
||||
overrides: { includes: ["f/ops_provinzial/**"] },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const byFlag = await getEffectiveSettingsForWorkspace(
|
||||
config,
|
||||
{ workspace: "flh-nonprod", jsonOutput: true },
|
||||
{ remote: "http://windmill_server:8000/", workspaceId: "flh-nonprod" },
|
||||
);
|
||||
expect(byFlag.includes).toEqual(["f/ops_flh/**"]);
|
||||
|
||||
const byProfile = await getEffectiveSettingsForWorkspace(
|
||||
config,
|
||||
{ workspace: "provinzial-nonprod", jsonOutput: true },
|
||||
{ remote: "https://windmill.example.com/", workspaceId: "provinzial-nonprod" },
|
||||
);
|
||||
expect(byProfile.includes).toEqual(["f/ops_provinzial/**"]);
|
||||
});
|
||||
Reference in New Issue
Block a user