Commit cd3a975e authored by zpc's avatar zpc

Restore inline selectors and compact release logs; allow closing idle panes

parent 12947a88
......@@ -19,9 +19,9 @@
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>1.4.0</string>
<string>1.4.1</string>
<key>CFBundleVersion</key>
<string>10</string>
<string>11</string>
<key>LSMinimumSystemVersion</key>
<string>14.0</string>
<key>LSUIElement</key>
......
......@@ -18,6 +18,9 @@ private struct SavedPane: Codable {
@Observable
final class ReleasePaneState: Identifiable {
enum State: String { case idle, queued, running, finished, skipped }
enum ConfigurationField { case project, configuration, server, module }
var expandedField: ConfigurationField?
var expandedConsole = false
let id: UUID
var projectID: UUID
......@@ -136,6 +139,7 @@ final class SplitReleaseModel {
private var batch = false
private var unread = false
private var runIDs = Set<UUID>()
private var runResults: [UUID: ReleaseResult] = [:]
private var batchStarted: Date?
private var completionTask: Task<Void, Never>?
private(set) var completionDuration: Int?
......@@ -181,18 +185,18 @@ final class SplitReleaseModel {
var current: ReleasePaneState? { panes.first { $0.state == .running } }
var progressPercentage: Int? {
let active = panes.filter { runIDs.contains($0.id) }
guard isRunning, !active.isEmpty else { return nil }
let completed = active.filter { $0.state == .finished }.count
guard isRunning, !runIDs.isEmpty else { return nil }
let completed = runResults.count
let partial = active.filter { $0.state == .running }.reduce(0) {
$0 + ($1.phase?.estimatedPercentage ?? 0)
}
return min(99, (completed * 100 + partial) / active.count)
return min(99, (completed * 100 + partial) / runIDs.count)
}
var indicator: ReleaseStatus? {
if isRunning { return nil }
if completionTask != nil { return .succeeded }
if unread {
return panes.filter { runIDs.contains($0.id) }.compactMap(\.result).first(where: {
return runResults.values.first(where: {
$0.status != .succeeded
})?.status
}
......@@ -227,7 +231,7 @@ final class SplitReleaseModel {
}
func remove(_ pane: ReleasePaneState) {
guard !isRunning else { return }
guard pane.state != .running && pane.state != .queued else { return }
pane.inventoryTask?.cancel()
panes.removeAll { $0.id == pane.id }
save()
......@@ -320,6 +324,7 @@ final class SplitReleaseModel {
batch = together
batchStarted = Date()
runIDs = Set(prepared.map { $0.pane.id })
runResults.removeAll()
if together, prepared.count > 1 {
let cityJobs = prepared.filter {
$0.project.type == .cityKeeper && $0.action == .standard
......@@ -336,6 +341,8 @@ final class SplitReleaseModel {
}
for job in prepared {
let pane = job.pane
pane.expandedField = nil
pane.expandedConsole = false
pane.consoleDismissed = false
pane.viewingLog = false
pane.state = .queued
......@@ -408,6 +415,7 @@ final class SplitReleaseModel {
pane.log = control.liveOutput()
pane.control = nil
pane.result = result
runResults[pane.id] = result
pane.state = .finished
pane.phase = nil
pane.paused = false
......@@ -426,9 +434,8 @@ final class SplitReleaseModel {
startAvailable()
} else {
unread = job.action != .preflight
let finished = panes.filter { runIDs.contains($0.id) }
if job.action != .preflight,
finished.allSatisfy({ $0.result?.status == .succeeded })
runIDs.allSatisfy({ runResults[$0]?.status == .succeeded })
{
let duration = Int(batchStarted?.distance(to: Date()) ?? 0)
showCompletion(duration: duration)
......
......@@ -27,23 +27,50 @@ struct SplitReleasePanel: View {
}
private var columnHeight: CGFloat {
let desired: CGFloat =
model.panes.contains(where: \.showsConsole) ? 650 : (model.panes.count == 1 ? 440 : 490)
let base: CGFloat = model.panes.count == 1 ? 460 : 500
let desired =
model.panes.map { pane -> CGFloat in
if pane.showsConsole { return pane.expandedConsole ? 650 : base }
guard let field = pane.expandedField else { return base }
let extra: CGFloat
switch field {
case .project:
extra = min(150, CGFloat(model.settings.projects.count) * 34 + 8) + 8
case .configuration:
let project = model.project(for: pane)
let count =
((try? project?.configurationFiles()) ?? project?.profiles.map(\.file) ?? [])
.count
extra = min(160, CGFloat(count) * 46 + 8) + 50
case .server:
extra = max(52, min(170, CGFloat(pane.servers.count) * 38 + 8)) + 8
case .module:
extra = max(44, min(220, CGFloat(pane.availableModules.count) * 31 + 8)) + 44
}
return min(650, base + extra)
}.max() ?? base
return min(desired, max(380, (NSScreen.main?.visibleFrame.height ?? 900) - 160))
}
var body: some View {
VStack(spacing: 0) {
HStack(spacing: 12) {
ZStack {
Circle().stroke(ReleaseColors.blue.opacity(0.25), lineWidth: 3)
Circle().trim(from: 0, to: 0.76)
.stroke(
ReleaseColors.blue, style: StrokeStyle(lineWidth: 3, lineCap: .round)
)
.rotationEffect(.degrees(-90))
if model.isRunning {
ZStack {
Circle().stroke(ReleaseColors.blue.opacity(0.25), lineWidth: 3)
Circle().trim(from: 0, to: 0.76)
.stroke(
ReleaseColors.blue,
style: StrokeStyle(lineWidth: 3, lineCap: .round)
)
.rotationEffect(.degrees(-90))
}
.frame(width: 32, height: 32)
} else {
Image(systemName: "shippingbox")
.font(.system(size: 26)).foregroundStyle(.white.opacity(0.9))
.frame(width: 32, height: 32)
}
.frame(width: 32, height: 32)
Text("Java 发布").font(.system(size: 23, weight: .semibold))
Spacer()
Button(action: model.add) {
......@@ -155,10 +182,6 @@ private struct ProjectReleaseColumn: View {
@Bindable var pane: ReleasePaneState
let height: CGFloat
@State private var configurationDraft: DeployProfile?
@State private var showsModules = false
@State private var showsConfiguration = false
@State private var showsProjects = false
@State private var showsServers = false
@FocusState private var moduleSearchFocused: Bool
private var project: ReleaseProject? { model.project(for: pane) }
......@@ -187,7 +210,7 @@ private struct ProjectReleaseColumn: View {
.padding(6)
}
.buttonStyle(ReleaseButtonStyle())
.disabled(!editable)
.disabled(pane.state == .running || pane.state == .queued)
}
}
if pane.showsConsole {
......@@ -200,120 +223,93 @@ private struct ProjectReleaseColumn: View {
.frame(height: height)
.background(pane.state == .running ? ReleaseColors.blue.opacity(0.09) : .clear)
.font(ReleaseTypography.body)
.popover(item: $configurationDraft) { draft in
ConfigurationEditor(profile: draft) { updated in
saveProfile(updated)
configurationDraft = nil
}
}
}
private var configuration: some View {
VStack(alignment: .leading, spacing: 16) {
VStack(spacing: 0) {
formRow("项目", symbol: "folder", value: project?.name ?? "选择项目") {
showsProjects = true
}
.popover(isPresented: $showsProjects) {
VStack(alignment: .leading, spacing: 12) {
Text("选择项目").font(.headline)
ForEach(
model.settings.projects.filter { candidate in
!model.panes.contains {
$0.id != pane.id && $0.projectID == candidate.id
}
}
) { candidate in
Button(candidate.name) {
showsProjects = false
model.replace(pane, with: candidate)
}.buttonStyle(ReleaseButtonStyle())
}
}.padding(18).frame(minWidth: 240, alignment: .leading)
.environment(\.colorScheme, .dark)
}
if project?.type == .cityKeeper {
rowDivider
formRow("发布配置", symbol: "doc.text", value: profile?.title ?? "选择配置") {
showsConfiguration = true
ScrollView(.vertical) {
VStack(alignment: .leading, spacing: 16) {
VStack(spacing: 0) {
formRow(.project, "项目", symbol: "folder", value: project?.name ?? "选择项目")
if pane.expandedField == .project { projectChoices }
if project?.type == .cityKeeper {
rowDivider
formRow(
.configuration, "发布配置", symbol: "doc.text",
value: profile?.title ?? "选择配置")
if pane.expandedField == .configuration { configurationChoices }
rowDivider
formRow(.server, "服务器", symbol: "server.rack", value: serverTitle)
if pane.expandedField == .server { serverChoices }
}
.popover(isPresented: $showsConfiguration) { configurationControls }
rowDivider
formRow("服务器", symbol: "server.rack", value: serverTitle) {
showsServers = true
}
.popover(isPresented: $showsServers) {
ScrollView {
VStack(alignment: .leading, spacing: 12) {
Text("选择服务器").font(.headline)
ForEach(pane.servers, id: \.name) { target in
Button(target.displayName) {
pane.server = target.name
model.save()
showsServers = false
}.buttonStyle(ReleaseButtonStyle())
}
if pane.servers.isEmpty { Text("未读取到服务器,请检查项目设置中的 hosts 文件。") }
}.padding(18)
}.frame(width: 310, height: 240)
.environment(\.colorScheme, .dark)
formRow(.module, "模块", symbol: "square.stack", value: moduleTitle)
if pane.expandedField == .module { modulePicker }
if project?.type == .cityKeeper {
rowDivider
HStack(spacing: 12) {
Image(systemName: "hammer").foregroundStyle(ReleaseColors.muted).frame(
width: 20)
Text("Maven").foregroundStyle(ReleaseColors.muted).frame(
width: 66, alignment: .leading)
Picker("Maven", selection: $pane.mavenCommand) {
Text("mvnd").tag(MavenCommand.mvnd)
Text("mvn").tag(MavenCommand.mvn)
}
.labelsHidden().pickerStyle(.segmented)
.onChange(of: pane.mavenCommand) { model.save() }
}.padding(.horizontal, 14).frame(height: 48)
}
}
rowDivider
formRow("模块", symbol: "square.stack", value: moduleTitle) { showsModules = true }
.popover(isPresented: $showsModules) { modulePicker }
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 14))
.clipShape(RoundedRectangle(cornerRadius: 14))
.overlay {
RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.13))
.allowsHitTesting(false)
}
.disabled(!editable)
if project?.type == .cityKeeper {
rowDivider
HStack(spacing: 12) {
Image(systemName: "hammer").foregroundStyle(ReleaseColors.muted).frame(
width: 20)
Text("Maven").foregroundStyle(ReleaseColors.muted).frame(
width: 66, alignment: .leading)
Picker("Maven", selection: $pane.mavenCommand) {
Text("mvnd").tag(MavenCommand.mvnd)
Text("mvn").tag(MavenCommand.mvn)
Toggle("使用 VPC 镜像地址", isOn: $pane.useVPC)
.toggleStyle(.checkbox).disabled(!editable)
.onChange(of: pane.useVPC) { model.save() }
}
if let project, project.supportsVerifiedRelease(profile) {
HStack {
Toggle("验证发布", isOn: $pane.verified).toggleStyle(.checkbox)
.onChange(of: pane.verified) { model.save() }
Spacer()
Button("预检") { model.publish(pane, action: .preflight) }
.buttonStyle(ReleaseButtonStyle())
.disabled(pane.modules.isEmpty)
}.disabled(!editable)
}
publishButton(title: "发布 \(pane.selectedCount) 个模块")
if let message = pane.error {
Text(message).font(.caption).foregroundStyle(.red).lineLimit(3)
}
if pane.state == .skipped {
Text("前序项目失败,本项目未执行").foregroundStyle(.orange)
}
if let result = pane.result {
HStack(alignment: .top, spacing: 8) {
Image(
systemName: result.status == .succeeded
? "checkmark.circle.fill" : "exclamationmark.circle.fill"
)
.foregroundStyle(result.status == .succeeded ? .green : .red)
VStack(alignment: .leading, spacing: 4) {
Text("\(result.headline) · 耗时 \(result.duration) 秒")
Text(result.module).font(.caption).foregroundStyle(ReleaseColors.muted)
.lineLimit(1)
}
.labelsHidden().pickerStyle(.segmented)
.onChange(of: pane.mavenCommand) { model.save() }
}.padding(.horizontal, 14).frame(height: 48)
Spacer(minLength: 0)
Button("查看日志") { pane.showLog() }.buttonStyle(ReleaseButtonStyle())
}.font(ReleaseTypography.detail)
} else {
Text("选择模块后即可发布").font(ReleaseTypography.detail).foregroundStyle(
ReleaseColors.muted)
}
}
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 14))
.overlay { RoundedRectangle(cornerRadius: 14).strokeBorder(Color.white.opacity(0.13)) }
.disabled(!editable)
if project?.type == .cityKeeper {
Toggle("使用 VPC 镜像地址", isOn: $pane.useVPC)
.toggleStyle(.checkbox).disabled(!editable)
.onChange(of: pane.useVPC) { model.save() }
}
publishButton(title: "发布 \(pane.selectedCount) 个模块")
if let message = pane.error {
Text(message).font(.caption).foregroundStyle(.red).lineLimit(3)
}
if pane.state == .skipped {
Text("前序项目失败,本项目未执行").foregroundStyle(.orange)
}
if let result = pane.result {
HStack(alignment: .top, spacing: 8) {
Image(
systemName: result.status == .succeeded
? "checkmark.circle.fill" : "exclamationmark.circle.fill"
)
.foregroundStyle(result.status == .succeeded ? .green : .red)
VStack(alignment: .leading, spacing: 4) {
Text("\(result.headline) · 耗时 \(result.duration) 秒")
Text(result.module).font(.caption).foregroundStyle(ReleaseColors.muted)
.lineLimit(1)
}
Spacer(minLength: 0)
Button("查看日志") { pane.showLog() }.buttonStyle(ReleaseButtonStyle())
}.font(ReleaseTypography.detail)
} else {
Text("选择模块后即可发布").font(ReleaseTypography.detail).foregroundStyle(
ReleaseColors.muted)
}
Spacer(minLength: 0)
}.padding(.bottom, 4)
}
}
......@@ -328,19 +324,26 @@ private struct ProjectReleaseColumn: View {
Rectangle().fill(Color.white.opacity(0.12)).frame(height: 1).padding(.horizontal, 14)
}
private func formRow(
_ label: String, symbol: String, value: String, action: @escaping () -> Void
_ field: ReleasePaneState.ConfigurationField, _ label: String, symbol: String, value: String
) -> some View {
Button(action: action) {
Button {
configurationDraft = nil
pane.expandedField = pane.expandedField == field ? nil : field
} label: {
HStack(spacing: 12) {
Image(systemName: symbol).foregroundStyle(ReleaseColors.muted).frame(width: 20)
Text(label).foregroundStyle(ReleaseColors.muted).frame(
width: 66, alignment: .leading)
Text(value).foregroundStyle(.white.opacity(0.9)).lineLimit(1).truncationMode(.tail)
.frame(maxWidth: .infinity, alignment: .leading)
Image(systemName: "chevron.down").font(.system(size: 11)).foregroundStyle(
Image(systemName: pane.expandedField == field ? "chevron.up" : "chevron.down").font(
.system(size: 11)
).foregroundStyle(
ReleaseColors.muted)
}.padding(.horizontal, 14).frame(height: 50).contentShape(Rectangle())
}.buttonStyle(ReleaseButtonStyle())
}.buttonStyle(ReleaseButtonStyle(radius: 0))
.accessibilityLabel(label)
.accessibilityValue(value)
}
private func publishButton(title: String) -> some View {
Button {
......@@ -373,6 +376,15 @@ private struct ProjectReleaseColumn: View {
Text("实时输出 · \(paneTitle)").font(.system(size: 13, weight: .medium)).lineLimit(
1)
Spacer(minLength: 4)
Button {
pane.expandedConsole.toggle()
} label: {
Image(
systemName: pane.expandedConsole
? "arrow.down.right.and.arrow.up.left"
: "arrow.up.left.and.arrow.down.right")
}
.help(pane.expandedConsole ? "收起日志" : "展开日志")
if pane.state == .running {
Button(pane.paused ? "继续" : "暂停") { model.togglePause(pane) }.disabled(
pane.stopping)
......@@ -410,12 +422,6 @@ private struct ProjectReleaseColumn: View {
private var modulePicker: some View {
VStack(alignment: .leading, spacing: 10) {
HStack {
Text("选择模块").font(.headline)
Spacer()
Button("完成") { showsModules = false }
}
TextField("输入模块名搜索…", text: $pane.search)
.textFieldStyle(.roundedBorder)
.focused($moduleSearchFocused)
......@@ -457,9 +463,7 @@ private struct ProjectReleaseColumn: View {
ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
}
.padding(12)
.frame(width: 310)
.environment(\.colorScheme, .dark)
.padding([.horizontal, .bottom], 8)
}
private var configurationSummary: String {
......@@ -469,85 +473,142 @@ private struct ProjectReleaseColumn: View {
return "\(configuration) · \(destination) · \(pane.selectedCount) 个模块"
}
private var configurationControls: some View {
VStack(alignment: .leading, spacing: 14) {
Text("发布选项").font(.headline)
if let project {
if project.type == .cityKeeper {
menuRow("发布配置", value: profile?.title ?? "选择配置文件") {
let files =
(try? project.configurationFiles())
?? project.profiles.map(\.file)
ForEach(files, id: \.self) { file in
Button(
project.profiles.first(where: { $0.file == file })?.title
?? file
) {
selectConfiguration(file, in: project)
}
}
Divider()
Button("浏览其他 YAML…") { browseConfiguration(in: project) }
private var projectChoices: some View {
let available = model.settings.projects.filter { candidate in
!model.panes.contains { $0.id != pane.id && $0.projectID == candidate.id }
}
return ScrollView {
VStack(spacing: 2) {
ForEach(available) { candidate in
choiceButton(candidate.name, selected: candidate.id == pane.projectID) {
pane.expandedField = nil
model.replace(pane, with: candidate)
}
menuRow(
"服务器",
value: pane.servers.first(where: { $0.name == pane.server })?
.displayName ?? "选择服务器"
) {
ForEach(pane.servers, id: \.name) { target in
Button(target.displayName) {
pane.server = target.name
model.save()
}
}
}
}.padding(4)
}
.frame(height: min(150, CGFloat(available.count) * 34 + 8))
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
.padding([.horizontal, .bottom], 8)
}
private var serverChoices: some View {
ScrollView {
VStack(spacing: 2) {
ForEach(pane.servers, id: \.name) { target in
choiceButton(target.displayName, selected: target.name == pane.server) {
pane.server = target.name
pane.expandedField = nil
model.save()
}
menuRow("Maven", value: pane.mavenCommand.title) {
ForEach([MavenCommand.mvnd, .mvn]) { command in
Button(command.title) {
pane.mavenCommand = command
model.save()
}
if pane.servers.isEmpty {
Text("未读取到服务器,请检查项目设置中的 hosts 文件。")
.font(.caption).foregroundStyle(ReleaseColors.muted).padding(10)
}
}.padding(4)
}
.frame(height: max(52, min(170, CGFloat(pane.servers.count) * 38 + 8)))
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
.padding([.horizontal, .bottom], 8)
}
private func choiceButton(_ title: String, selected: Bool, action: @escaping () -> Void)
-> some View
{
Button(action: action) {
HStack(spacing: 8) {
Image(systemName: selected ? "largecircle.fill.circle" : "circle")
.foregroundStyle(selected ? ReleaseColors.blue : ReleaseColors.muted)
Text(title).foregroundStyle(.primary).fixedSize(horizontal: false, vertical: true)
.frame(maxWidth: .infinity, alignment: .leading)
}.padding(.horizontal, 8).padding(.vertical, 7)
}
.buttonStyle(
ReleaseButtonStyle(
base: selected ? ReleaseColors.blue.opacity(0.12) : .clear, radius: 5)
)
.accessibilityAddTraits(selected ? .isSelected : [])
}
private var configurationChoices: some View {
let files = (try? project?.configurationFiles()) ?? project?.profiles.map(\.file) ?? []
return VStack(alignment: .leading, spacing: 6) {
if !files.isEmpty {
ScrollView {
VStack(spacing: 2) {
ForEach(files, id: \.self) { file in configurationChoice(file) }
}.padding(4)
}
.frame(height: min(160, CGFloat(files.count) * 46 + 8))
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
}
if let draft = Binding($configurationDraft) {
VStack(alignment: .leading, spacing: 8) {
Text(draft.file.wrappedValue).font(.system(.caption, design: .monospaced))
.foregroundStyle(ReleaseColors.muted).lineLimit(1)
TextField("别名(可选)", text: draft.alias).textFieldStyle(.roundedBorder)
TextField("SSH 目标(可选)", text: draft.sshTarget).textFieldStyle(.roundedBorder)
HStack {
Spacer()
Button("取消") { configurationDraft = nil }
Button("保存") {
if let configurationDraft,
saveProfile(configurationDraft, select: false)
{
self.configurationDraft = nil
}
}
}
HStack(spacing: 12) {
Toggle("VPC", isOn: $pane.useVPC)
if project.supportsVerifiedRelease(profile) {
Toggle("验证发布", isOn: $pane.verified)
Spacer(minLength: 0)
Button("预检") { model.publish(pane, action: .preflight) }
.buttonStyle(ReleaseButtonStyle())
.disabled(!editable || pane.modules.isEmpty)
} else {
Spacer(minLength: 0)
}
if let profile {
Button {
configurationDraft = profile
} label: {
Image(systemName: "slider.horizontal.3")
}
.buttonStyle(ReleaseButtonStyle())
.help("编辑配置别名和 SSH 目标")
.disabled(!editable)
}
.font(ReleaseTypography.detail).padding(8)
.background(ReleaseColors.terminal, in: RoundedRectangle(cornerRadius: 7))
}
Button {
if let project { browseConfiguration(in: project) }
} label: {
Label("浏览其他 YAML…", systemImage: "folder")
.foregroundStyle(ReleaseColors.blue).padding(8)
}.buttonStyle(ReleaseButtonStyle())
}.padding([.horizontal, .bottom], 8)
}
private func configurationChoice(_ file: String) -> some View {
var option = project?.profiles.first(where: { $0.file == file }) ?? DeployProfile()
option.file = file
let selected = profile?.file == file
return HStack(spacing: 2) {
Button {
configurationDraft = nil
if let project { selectConfiguration(file, in: project) }
} label: {
HStack(spacing: 8) {
Image(systemName: selected ? "largecircle.fill.circle" : "circle")
.foregroundStyle(selected ? ReleaseColors.blue : ReleaseColors.muted)
VStack(alignment: .leading, spacing: 2) {
Text(option.title).lineLimit(1)
if option.title != file {
Text(file).font(.system(.caption, design: .monospaced))
.foregroundStyle(ReleaseColors.muted).lineLimit(1)
}
}
.toggleStyle(.checkbox)
.font(ReleaseTypography.detail)
.disabled(!editable)
.onChange(of: pane.useVPC) { model.save() }
.onChange(of: pane.verified) { model.save() }
}
if project.type != .cityKeeper {
Text("自定义项目使用项目设置中的发布脚本。")
.foregroundStyle(ReleaseColors.muted)
}
Spacer(minLength: 3)
}.padding(.horizontal, 8).frame(height: 44).contentShape(Rectangle())
}
.buttonStyle(
ReleaseButtonStyle(
base: selected ? ReleaseColors.blue.opacity(0.12) : .clear, radius: 5)
)
.accessibilityAddTraits(selected ? .isSelected : [])
Button {
configurationDraft = option
} label: {
Image(systemName: "pencil").foregroundStyle(ReleaseColors.blue)
.frame(width: 27, height: 27)
}
Button("完成") { showsConfiguration = false }
.frame(maxWidth: .infinity, alignment: .trailing)
.buttonStyle(ReleaseButtonStyle())
.accessibilityLabel("编辑 \(file) 的别名和选项")
}
.padding(18)
.frame(width: 360)
.environment(\.colorScheme, .dark)
}
private var paneTitle: String {
......@@ -561,35 +622,10 @@ private struct ProjectReleaseColumn: View {
}
}
private func menuRow<Content: View>(
_ label: String, value: String,
@ViewBuilder content: () -> Content
) -> some View {
HStack(spacing: 8) {
Text(label).foregroundStyle(ReleaseColors.muted)
.frame(width: 60, alignment: .leading)
Menu(content: content) {
HStack {
Text(value).lineLimit(1)
Spacer(minLength: 3)
Image(systemName: "chevron.down").font(.system(size: 10))
}
.padding(.horizontal, 11)
.frame(height: 36)
.frame(maxWidth: .infinity)
.background(ReleaseColors.surface, in: RoundedRectangle(cornerRadius: 7))
.overlay { RoundedRectangle(cornerRadius: 7).strokeBorder(ReleaseColors.border) }
}
.menuStyle(.borderlessButton)
.menuIndicator(.hidden)
.frame(maxWidth: .infinity)
.disabled(!editable)
}
}
private func selectConfiguration(_ file: String, in project: ReleaseProject) {
if let existing = project.profiles.first(where: { $0.file == file }) {
pane.profileID = existing.id
pane.verified = false
model.save()
return
}
......@@ -610,8 +646,9 @@ private struct ProjectReleaseColumn: View {
selectConfiguration(name, in: project)
}
private func saveProfile(_ updated: DeployProfile) {
guard var project else { return }
@discardableResult
private func saveProfile(_ updated: DeployProfile, select: Bool = true) -> Bool {
guard var project else { return false }
do {
try project.validate(updated)
if let index = project.profiles.firstIndex(where: { $0.id == updated.id }) {
......@@ -620,27 +657,15 @@ private struct ProjectReleaseColumn: View {
project.profiles.append(updated)
}
try model.settings.save(project)
pane.profileID = updated.id
if select {
pane.profileID = updated.id
pane.verified = false
}
model.save()
return true
} catch {
pane.error = error.localizedDescription
return false
}
}
}
private struct ConfigurationEditor: View {
@State var profile: DeployProfile
let save: (DeployProfile) -> Void
var body: some View {
VStack(alignment: .leading, spacing: 9) {
Text(profile.file).font(.system(size: 12, design: .monospaced))
TextField("别名", text: $profile.alias)
TextField("SSH 目标(可选)", text: $profile.sshTarget)
Button("保存") { save(profile) }
}
.padding(15)
.frame(width: 280)
.environment(\.colorScheme, .dark)
}
}
......@@ -23,6 +23,7 @@ final class ReleaseRunnerTests: XCTestCase {
beta.name = "Beta"
try settings.save(alpha)
try settings.save(beta)
settings.projectID = alpha.id
let model = SplitReleaseModel(settings: settings, storage: storage)
model.add()
XCTAssertEqual(model.panes.count, 2)
......@@ -60,6 +61,68 @@ final class ReleaseRunnerTests: XCTestCase {
XCTAssertTrue(restored.panes.contains { $0.log.contains("first task completed") })
}
@MainActor
func testIdlePaneCanCloseWhileAnotherReleaseRuns() async throws {
let first = try Fixture()
let second = try Fixture()
defer { first.remove(); second.remove() }
try "sleep 0.4\nprintf 'active release finished\\n'\n".write(
to: first.local.appending(path: "release.sh"), atomically: true, encoding: .utf8)
let storage = first.base.appending(path: "close-state")
let settings = AppModel(storage: storage)
var alpha = first.project; alpha.name = "Alpha"
var beta = second.project; beta.name = "Beta"
try settings.save(alpha); try settings.save(beta)
settings.projectID = alpha.id
let model = SplitReleaseModel(settings: settings, storage: storage)
model.add()
let active = model.panes[0]
let idle = model.panes[1]
model.publish(active)
model.remove(active)
XCTAssertEqual(model.panes.count, 2)
model.remove(idle)
XCTAssertEqual(model.panes.count, 1)
XCTAssertTrue(model.isRunning)
for _ in 0..<200 where model.isRunning { try await Task.sleep(for: .milliseconds(10)) }
XCTAssertEqual(active.result?.status, .succeeded)
XCTAssertTrue(active.log.contains("active release finished"))
XCTAssertEqual(model.indicator, .succeeded)
}
@MainActor
func testFinishedPaneCanCloseWithoutLosingBatchOutcome() async throws {
let first = try Fixture()
let second = try Fixture()
defer { first.remove(); second.remove() }
try "printf 'first finished\\n'\n".write(
to: first.local.appending(path: "release.sh"), atomically: true, encoding: .utf8)
try "sleep 0.4\nprintf 'second finished\\n'\n".write(
to: second.local.appending(path: "release.sh"), atomically: true, encoding: .utf8)
let storage = first.base.appending(path: "batch-close-state")
let settings = AppModel(storage: storage)
var alpha = first.project; alpha.name = "Alpha"
var beta = second.project; beta.name = "Beta"
try settings.save(alpha); try settings.save(beta)
settings.projectID = alpha.id
let model = SplitReleaseModel(settings: settings, storage: storage)
model.add()
let finished = model.panes[0]
let next = model.panes[1]
model.publishAll()
model.remove(next)
XCTAssertEqual(model.panes.count, 2)
for _ in 0..<200 where finished.state != .finished { try await Task.sleep(for: .milliseconds(10)) }
XCTAssertEqual(finished.result?.status, .succeeded)
XCTAssertTrue(model.isRunning)
model.remove(finished)
XCTAssertEqual(model.panes.count, 1)
XCTAssertGreaterThanOrEqual(try XCTUnwrap(model.progressPercentage), 50)
for _ in 0..<200 where model.isRunning { try await Task.sleep(for: .milliseconds(10)) }
XCTAssertEqual(next.result?.status, .succeeded)
XCTAssertEqual(model.indicator, .succeeded)
}
@MainActor
func testFailedPaneKeepsConsoleUntilReturnedAndRetryResetsIt() async throws {
let fixture = try Fixture()
......@@ -128,6 +191,7 @@ final class ReleaseRunnerTests: XCTestCase {
beta.profiles = [profile]
try settings.save(alpha)
try settings.save(beta)
settings.projectID = alpha.id
let model = SplitReleaseModel(settings: settings, storage: storage)
model.add()
for _ in 0..<100 where model.panes.contains(where: { $0.servers.isEmpty }) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment