Route CLI delivery through the facade
This commit is contained in:
@@ -153,6 +153,12 @@ func runDelivery(ctx context.Context, invocation cli.Invocation, stdout, stderr
|
||||
fmt.Fprintf(stderr, "load profile: %v\n", err)
|
||||
return 2
|
||||
}
|
||||
return deliverWithSettings(ctx, invocation, settings, stdout, stderr)
|
||||
}
|
||||
|
||||
// deliverWithSettings adapts prepared CLI state to the public delivery facade.
|
||||
// CI entry points can reuse it after preparing the checkout and loading its profile.
|
||||
func deliverWithSettings(ctx context.Context, invocation cli.Invocation, settings cli.Settings, stdout, stderr io.Writer) int {
|
||||
delivery := settings.Delivery
|
||||
if delivery == nil || strings.TrimSpace(delivery.BaseURL) == "" || strings.TrimSpace(delivery.Owner) == "" || strings.TrimSpace(delivery.Repository) == "" {
|
||||
fmt.Fprintln(stderr, "deliver requires base_url, owner, and repository in the profile delivery settings")
|
||||
@@ -173,8 +179,11 @@ func runDelivery(ctx context.Context, invocation cli.Invocation, stdout, stderr
|
||||
fmt.Fprintln(stderr, "--assets requires build targets in the profile")
|
||||
return 2
|
||||
}
|
||||
var build *releasekit.BuildResult
|
||||
var temporaryDir string
|
||||
var buildSpec *releasekit.BuildSpec
|
||||
var prebuilt *releasekit.BuildResult
|
||||
if invocation.AssetsDir == "" && settings.Build != nil {
|
||||
buildSpec = configuredBuildSpec(settings.Build)
|
||||
}
|
||||
if hasTargets {
|
||||
if invocation.AssetsDir != "" {
|
||||
assetsDir := invocation.AssetsDir
|
||||
@@ -190,31 +199,7 @@ func runDelivery(ctx context.Context, invocation cli.Invocation, stdout, stderr
|
||||
fmt.Fprintln(stderr, "build receipt does not match the selected repository, version, or build settings")
|
||||
return 1
|
||||
}
|
||||
build = buildResultFromReceipt(receipt)
|
||||
} else {
|
||||
repositoryDir, resolveErr := filepath.Abs(invocation.Repository)
|
||||
if resolveErr != nil {
|
||||
fmt.Fprintf(stderr, "resolve repository directory: %v\n", resolveErr)
|
||||
return 1
|
||||
}
|
||||
temporaryDir, err = cli.TemporaryBuildDir(repositoryDir)
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "create temporary build directory: %v\n", err)
|
||||
return 1
|
||||
}
|
||||
defer os.RemoveAll(temporaryDir)
|
||||
result, buildErr := releasekit.Build(ctx, releasekit.BuildRequest{
|
||||
RepositoryDir: invocation.Repository,
|
||||
Version: invocation.Version,
|
||||
Spec: *configuredBuildSpec(settings.Build),
|
||||
OutputDir: filepath.Join(temporaryDir, "assets"),
|
||||
Output: stderr,
|
||||
})
|
||||
if buildErr != nil {
|
||||
fmt.Fprintf(stderr, "build tagged-source assets: %v\n", buildErr)
|
||||
return 1
|
||||
}
|
||||
build = &result
|
||||
prebuilt = buildResultFromReceipt(receipt)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -225,7 +210,9 @@ func runDelivery(ctx context.Context, invocation cli.Invocation, stdout, stderr
|
||||
Destination: releasekit.GiteaDestination{
|
||||
BaseURL: delivery.BaseURL, Owner: delivery.Owner, Repository: delivery.Repository, Token: token,
|
||||
},
|
||||
Prebuilt: build,
|
||||
Build: buildSpec,
|
||||
Prebuilt: prebuilt,
|
||||
Output: stderr,
|
||||
})
|
||||
if err != nil {
|
||||
fmt.Fprintf(stderr, "delivery state=%s version=%s commit=%s url=%s: %v\n", result.State, result.Version, result.CandidateCommit, result.ReleaseURL, err)
|
||||
|
||||
Reference in New Issue
Block a user