refactor(build): name release workflow helpers explicitly
Co-Authored-By: Virgil <virgil@lethean.io>
This commit is contained in:
parent
bb46675131
commit
4921058bf3
3 changed files with 38 additions and 37 deletions
|
|
@ -29,9 +29,9 @@ var (
|
|||
releaseWorkflowOutputSnakeAliasInput string
|
||||
)
|
||||
|
||||
// releaseWorkflowInputs keeps the workflow alias inputs grouped by meaning
|
||||
// rather than by call-site position.
|
||||
type releaseWorkflowInputs struct {
|
||||
// releaseWorkflowRequestInputs keeps the workflow alias inputs grouped by the
|
||||
// public request fields they represent, rather than by call-site position.
|
||||
type releaseWorkflowRequestInputs struct {
|
||||
pathInput string
|
||||
workflowPathInput string
|
||||
workflowPathHyphenInput string
|
||||
|
|
@ -47,12 +47,12 @@ type releaseWorkflowInputs struct {
|
|||
workflowOutputPathSnakeInput string
|
||||
}
|
||||
|
||||
// resolvedWorkflowTargetPath resolves both workflow path inputs and workflow
|
||||
// resolveWorkflowTargetPath resolves both workflow path inputs and workflow
|
||||
// output inputs before merging them into the final target path.
|
||||
//
|
||||
// inputs := releaseWorkflowInputs{pathInput: "ci/release.yml"}
|
||||
// path, err := inputs.resolvedWorkflowTargetPath("/tmp/project")
|
||||
func (inputs releaseWorkflowInputs) resolvedWorkflowTargetPath(projectDir string) (string, error) {
|
||||
// inputs := releaseWorkflowRequestInputs{pathInput: "ci/release.yml"}
|
||||
// path, err := inputs.resolveWorkflowTargetPath("/tmp/project")
|
||||
func (inputs releaseWorkflowRequestInputs) resolveWorkflowTargetPath(projectDir string) (string, error) {
|
||||
resolvedWorkflowPath, err := resolveReleaseWorkflowInputPathAliases(
|
||||
projectDir,
|
||||
inputs.pathInput,
|
||||
|
|
@ -86,7 +86,7 @@ func (inputs releaseWorkflowInputs) resolvedWorkflowTargetPath(projectDir string
|
|||
var releaseWorkflowCmd = &cli.Command{
|
||||
Use: "workflow",
|
||||
RunE: func(cmd *cli.Command, args []string) error {
|
||||
return runReleaseWorkflow(cmd.Context(), releaseWorkflowInputs{
|
||||
return runReleaseWorkflow(cmd.Context(), releaseWorkflowRequestInputs{
|
||||
pathInput: releaseWorkflowPathInput,
|
||||
workflowPathInput: releaseWorkflowPathAliasInput,
|
||||
workflowPathHyphenInput: releaseWorkflowPathHyphenAliasInput,
|
||||
|
|
@ -133,27 +133,28 @@ func AddWorkflowCommand(buildCmd *cli.Command) {
|
|||
buildCmd.AddCommand(releaseWorkflowCmd)
|
||||
}
|
||||
|
||||
// runReleaseWorkflow writes the embedded release workflow into the current project directory.
|
||||
// runReleaseWorkflow writes the embedded release workflow into the current
|
||||
// project directory.
|
||||
//
|
||||
// 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{workflowOutputHyphenInput: "ci/release.yml"}) // uses the workflow-output alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowInputs{workflowOutputSnakeInput: "ci/release.yml"}) // uses the workflow_output 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 {
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{}) // writes .github/workflows/release.yml
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{pathInput: "ci/release.yml"}) // writes ./ci/release.yml under the project root
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowPathInput: "ci/release.yml"}) // uses the workflowPath alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowPathSnakeInput: "ci/release.yml"}) // uses the workflow_path alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowPathHyphenInput: "ci/release.yml"}) // uses the workflow-path alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{outputPathInput: "ci/release.yml"}) // uses the outputPath alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{legacyOutputInput: "ci/release.yml"}) // uses the legacy output alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowOutputPathInput: "ci/release.yml"}) // uses the workflowOutputPath alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowOutputHyphenInput: "ci/release.yml"}) // uses the workflow-output alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowOutputSnakeInput: "ci/release.yml"}) // uses the workflow_output alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowOutputPathSnakeInput: "ci/release.yml"}) // uses the workflow_output_path alias
|
||||
// runReleaseWorkflow(ctx, releaseWorkflowRequestInputs{workflowOutputPathHyphenInput: "ci/release.yml"}) // uses the workflow-output-path alias
|
||||
func runReleaseWorkflow(_ context.Context, inputs releaseWorkflowRequestInputs) error {
|
||||
projectDir, err := ax.Getwd()
|
||||
if err != nil {
|
||||
return coreerr.E("build.runReleaseWorkflow", "failed to get working directory", err)
|
||||
}
|
||||
|
||||
resolvedWorkflowPath, err := inputs.resolvedWorkflowTargetPath(projectDir)
|
||||
resolvedWorkflowPath, err := inputs.resolveWorkflowTargetPath(projectDir)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
|
|
@ -598,18 +598,18 @@ type ReleaseWorkflowRequest struct {
|
|||
WorkflowOutputPathHyphen string `json:"workflow-output-path"`
|
||||
}
|
||||
|
||||
// resolvedWorkflowTargetPath resolves both workflow path inputs and workflow
|
||||
// resolveWorkflowTargetPath resolves both workflow path inputs and workflow
|
||||
// output inputs before merging them into the final target path.
|
||||
//
|
||||
// req := ReleaseWorkflowRequest{Path: "ci/release.yml"}
|
||||
// path, err := req.resolvedWorkflowTargetPath("/tmp/project", io.Local)
|
||||
func (r ReleaseWorkflowRequest) resolvedWorkflowTargetPath(dir string, medium io.Medium) (string, error) {
|
||||
outputPath, err := r.resolvedOutputPath(dir, medium)
|
||||
// path, err := req.resolveWorkflowTargetPath("/tmp/project", io.Local)
|
||||
func (r ReleaseWorkflowRequest) resolveWorkflowTargetPath(dir string, medium io.Medium) (string, error) {
|
||||
outputPath, err := r.resolveOutputPath(dir, medium)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
workflowPath, err := r.resolvedWorkflowPath(dir, medium)
|
||||
workflowPath, err := r.resolveWorkflowPath(dir, medium)
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
|
@ -617,12 +617,12 @@ func (r ReleaseWorkflowRequest) resolvedWorkflowTargetPath(dir string, medium io
|
|||
return build.ResolveReleaseWorkflowInputPathWithMedium(medium, dir, workflowPath, outputPath)
|
||||
}
|
||||
|
||||
// resolvedWorkflowPath resolves the workflow path aliases with the same
|
||||
// resolveWorkflowPath 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 := req.resolveWorkflowPath("/tmp/project", io.Local)
|
||||
func (r ReleaseWorkflowRequest) resolveWorkflowPath(dir string, medium io.Medium) (string, error) {
|
||||
workflowPath, err := build.ResolveReleaseWorkflowInputPathAliases(
|
||||
medium,
|
||||
dir,
|
||||
|
|
@ -638,12 +638,12 @@ func (r ReleaseWorkflowRequest) resolvedWorkflowPath(dir string, medium io.Mediu
|
|||
return workflowPath, nil
|
||||
}
|
||||
|
||||
// resolvedOutputPath resolves the workflow output aliases with the same
|
||||
// resolveOutputPath 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, medium io.Medium) (string, error) {
|
||||
// outputPath, err := req.resolveOutputPath("/tmp/project")
|
||||
func (r ReleaseWorkflowRequest) resolveOutputPath(dir string, medium io.Medium) (string, error) {
|
||||
resolvedOutputPath, err := build.ResolveReleaseWorkflowOutputPathAliasesInProjectWithMedium(
|
||||
medium,
|
||||
dir,
|
||||
|
|
@ -680,7 +680,7 @@ func (p *BuildProvider) generateReleaseWorkflow(c *gin.Context) {
|
|||
}
|
||||
}
|
||||
|
||||
workflowPath, err := req.resolvedWorkflowTargetPath(dir, p.medium)
|
||||
workflowPath, err := req.resolveWorkflowTargetPath(dir, p.medium)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusBadRequest, api.Fail("invalid_request", err.Error()))
|
||||
return
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ func TestProvider_ReleaseWorkflowRequestResolvedOutputPath_Good(t *testing.T) {
|
|||
WorkflowOutputPath: absoluteDir,
|
||||
}
|
||||
|
||||
path, err := req.resolvedOutputPath(projectDir, io.Local)
|
||||
path, err := req.resolveOutputPath(projectDir, io.Local)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ax.Join(absoluteDir, "release.yml"), path)
|
||||
}
|
||||
|
|
@ -174,7 +174,7 @@ func TestProvider_ReleaseWorkflowRequestResolvedOutputPathAliases_Good(t *testin
|
|||
WorkflowOutputHyphen: "ci/workflow-output.yml",
|
||||
}
|
||||
|
||||
path, err := req.resolvedOutputPath(projectDir, io.Local)
|
||||
path, err := req.resolveOutputPath(projectDir, io.Local)
|
||||
require.NoError(t, err)
|
||||
assert.Equal(t, ax.Join(projectDir, "ci", "workflow-output.yml"), path)
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue