From 73b669cbaa0171847c009a4860e357be6e41d84f Mon Sep 17 00:00:00 2001 From: Virgil Date: Thu, 2 Apr 2026 02:21:50 +0000 Subject: [PATCH] refactor(build): clarify workflow alias examples Co-Authored-By: Virgil --- cmd/build/cmd_workflow.go | 28 +++++++++++++++------------- pkg/api/provider.go | 9 ++++++++- pkg/build/workflow.go | 24 ++++++++++++++---------- 3 files changed, 37 insertions(+), 24 deletions(-) diff --git a/cmd/build/cmd_workflow.go b/cmd/build/cmd_workflow.go index d1943ca..cb5ad03 100644 --- a/cmd/build/cmd_workflow.go +++ b/cmd/build/cmd_workflow.go @@ -37,7 +37,7 @@ type releaseWorkflowInputs struct { outputPathInput string outputPathHyphenInput string outputPathSnakeInput string - outputLegacyInput string + legacyOutputInput string workflowOutputPathInput string workflowOutputPathHyphenInput string workflowOutputPathSnakeInput string @@ -54,7 +54,7 @@ var releaseWorkflowCmd = &cli.Command{ outputPathInput: releaseWorkflowOutputPathInput, outputPathHyphenInput: releaseWorkflowOutputPathHyphenInput, outputPathSnakeInput: releaseWorkflowOutputPathSnakeInput, - outputLegacyInput: releaseWorkflowOutputLegacyInput, + legacyOutputInput: releaseWorkflowOutputLegacyInput, workflowOutputPathInput: releaseWorkflowWorkflowOutputPathInput, workflowOutputPathHyphenInput: releaseWorkflowWorkflowOutputPathHyphenInput, workflowOutputPathSnakeInput: releaseWorkflowWorkflowOutputPathSnakeInput, @@ -91,14 +91,16 @@ func AddWorkflowCommand(buildCmd *cli.Command) { // runReleaseWorkflow writes the embedded release workflow into the current project directory. // -// buildcmd.AddWorkflowCommand(buildCmd) -// runReleaseWorkflow(ctx, releaseWorkflowInputs{}) // writes to .github/workflows/release.yml -// runReleaseWorkflow(ctx, releaseWorkflowInputs{pathInput: "ci/release.yml"}) // writes to ./ci/release.yml under the project root -// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathInput: "ci/release.yml"}) // uses the workflowPath alias -// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathHyphenInput: "ci/release.yml"}) // uses the workflow-path alias -// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathSnakeInput: "ci/release.yml"}) // uses the workflow_path alias -// runReleaseWorkflow(ctx, releaseWorkflowInputs{outputPathInput: "ci/release.yml"}) // uses the outputPath alias -// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputPathInput: "ci/release.yml"}) // uses the workflowOutputPath alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{}) // writes .github/workflows/release.yml +// runReleaseWorkflow(ctx, releaseWorkflowInputs{pathInput: "ci/release.yml"}) // writes ./ci/release.yml under the project root +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathInput: "ci/release.yml"}) // uses the workflowPath alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathSnakeInput: "ci/release.yml"}) // uses the workflow_path alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowPathHyphenInput: "ci/release.yml"}) // uses the workflow-path alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{outputPathInput: "ci/release.yml"}) // uses the outputPath alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{legacyOutputInput: "ci/release.yml"}) // uses the legacy output alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputPathInput: "ci/release.yml"}) // uses the workflowOutputPath alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputPathSnakeInput: "ci/release.yml"}) // uses the workflow_output_path alias +// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputPathHyphenInput: "ci/release.yml"}) // uses the workflow-output-path alias func runReleaseWorkflow(_ context.Context, inputs releaseWorkflowInputs) error { projectDir, err := ax.Getwd() if err != nil { @@ -121,7 +123,7 @@ func runReleaseWorkflow(_ context.Context, inputs releaseWorkflowInputs) error { inputs.outputPathInput, inputs.outputPathHyphenInput, inputs.outputPathSnakeInput, - inputs.outputLegacyInput, + inputs.legacyOutputInput, inputs.workflowOutputPathInput, inputs.workflowOutputPathHyphenInput, inputs.workflowOutputPathSnakeInput, @@ -153,13 +155,13 @@ func resolveReleaseWorkflowInputPathAliases(projectDir, pathInput, workflowPathI // resolveReleaseWorkflowOutputPathAliases keeps the CLI error wording stable while // delegating the conflict detection to the shared build helper. -func resolveReleaseWorkflowOutputPathAliases(projectDir, outputPathInput, outputPathHyphenInput, outputPathSnakeInput, outputLegacyInput, workflowOutputPathInput, workflowOutputPathHyphenInput, workflowOutputPathSnakeInput string) (string, error) { +func resolveReleaseWorkflowOutputPathAliases(projectDir, outputPathInput, outputPathHyphenInput, outputPathSnakeInput, legacyOutputInput, workflowOutputPathInput, workflowOutputPathHyphenInput, workflowOutputPathSnakeInput string) (string, error) { resolvedWorkflowOutputPath, err := build.ResolveReleaseWorkflowOutputPathAliasesInProject( projectDir, outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput, diff --git a/pkg/api/provider.go b/pkg/api/provider.go index 17e02bc..3c2049b 100644 --- a/pkg/api/provider.go +++ b/pkg/api/provider.go @@ -573,6 +573,7 @@ func (p *BuildProvider) triggerRelease(c *gin.Context) { // ReleaseWorkflowRequest captures the workflow-generation inputs exposed by the API. // // req := ReleaseWorkflowRequest{Path: "ci/release.yml"} +// req := ReleaseWorkflowRequest{WorkflowOutputPath: "ops/release.yml"} type ReleaseWorkflowRequest struct { Path string `json:"path"` WorkflowPath string `json:"workflowPath"` @@ -587,8 +588,11 @@ type ReleaseWorkflowRequest struct { WorkflowOutputPathHyphen string `json:"workflow-output-path"` } -// resolvedOutputPath resolves the workflow output aliases with the same +// resolvedWorkflowPath resolves the workflow path aliases with the same // conflict rules as the CLI. +// +// req := ReleaseWorkflowRequest{WorkflowPath: "ci/release.yml"} +// workflowPath, err := req.resolvedWorkflowPath("/tmp/project", io.Local) func (r ReleaseWorkflowRequest) resolvedWorkflowPath(dir string, medium io.Medium) (string, error) { workflowPath, err := build.ResolveReleaseWorkflowInputPathAliases( medium, @@ -607,6 +611,9 @@ func (r ReleaseWorkflowRequest) resolvedWorkflowPath(dir string, medium io.Mediu // resolvedOutputPath resolves the workflow output aliases with the same // conflict rules as the CLI. +// +// req := ReleaseWorkflowRequest{WorkflowOutputPath: "ci/release.yml"} +// outputPath, err := req.resolvedOutputPath("/tmp/project") func (r ReleaseWorkflowRequest) resolvedOutputPath(dir string) (string, error) { resolvedOutputPath, err := build.ResolveReleaseWorkflowOutputPathAliasesInProject( dir, diff --git a/pkg/build/workflow.go b/pkg/build/workflow.go index 8d094d0..23aa0d6 100644 --- a/pkg/build/workflow.go +++ b/pkg/build/workflow.go @@ -153,16 +153,20 @@ func ResolveReleaseWorkflowInputPathAliases(filesystem io_interface.Medium, proj // ResolveReleaseWorkflowOutputPath resolves the core workflow output aliases. // +// path, err := build.ResolveReleaseWorkflowOutputPath("ci/release.yml", "", "") +// path, err := build.ResolveReleaseWorkflowOutputPath("", "ci/release.yml", "") +// path, err := build.ResolveReleaseWorkflowOutputPath("", "", "ci/release.yml") +// // build.ResolveReleaseWorkflowOutputPath("ci/release.yml", "", "") // "ci/release.yml" // build.ResolveReleaseWorkflowOutputPath("", "ci/release.yml", "") // "ci/release.yml" // build.ResolveReleaseWorkflowOutputPath("", "", "ci/release.yml") // "ci/release.yml" // build.ResolveReleaseWorkflowOutputPath("ci/release.yml", "ops.yml", "") // error -func ResolveReleaseWorkflowOutputPath(outputPathInput, outputPathSnakeInput, outputLegacyInput string) (string, error) { +func ResolveReleaseWorkflowOutputPath(outputPathInput, outputPathSnakeInput, legacyOutputInput string) (string, error) { return ResolveReleaseWorkflowOutputPathAliases( outputPathInput, "", outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, "", "", "", @@ -180,7 +184,7 @@ func ResolveReleaseWorkflowOutputPathAliases( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput string, @@ -189,7 +193,7 @@ func ResolveReleaseWorkflowOutputPathAliases( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput, @@ -207,7 +211,7 @@ func ResolveReleaseWorkflowOutputPathAliasesInProject( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput string, @@ -217,7 +221,7 @@ func ResolveReleaseWorkflowOutputPathAliasesInProject( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput, @@ -259,7 +263,7 @@ func resolveReleaseWorkflowOutputAliasSet( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput, @@ -269,7 +273,7 @@ func resolveReleaseWorkflowOutputAliasSet( normalizeWorkflowOutputAlias(outputPathInput), normalizeWorkflowOutputAlias(outputPathHyphenInput), normalizeWorkflowOutputAlias(outputPathSnakeInput), - normalizeWorkflowOutputAlias(outputLegacyInput), + normalizeWorkflowOutputAlias(legacyOutputInput), normalizeWorkflowOutputAlias(workflowOutputPathInput), normalizeWorkflowOutputAlias(workflowOutputPathSnakeInput), normalizeWorkflowOutputAlias(workflowOutputPathHyphenInput), @@ -299,7 +303,7 @@ func resolveReleaseWorkflowOutputAliasSetInProject( outputPathInput, outputPathHyphenInput, outputPathSnakeInput, - outputLegacyInput, + legacyOutputInput, workflowOutputPathInput, workflowOutputPathSnakeInput, workflowOutputPathHyphenInput, @@ -309,7 +313,7 @@ func resolveReleaseWorkflowOutputAliasSetInProject( cleanWorkflowInput(outputPathInput), cleanWorkflowInput(outputPathHyphenInput), cleanWorkflowInput(outputPathSnakeInput), - cleanWorkflowInput(outputLegacyInput), + cleanWorkflowInput(legacyOutputInput), cleanWorkflowInput(workflowOutputPathInput), cleanWorkflowInput(workflowOutputPathSnakeInput), cleanWorkflowInput(workflowOutputPathHyphenInput),