Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(cli): dynamically get versioned links to documentation #13455

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/argo/commands/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ func NewServerCommand() *cobra.Command {
Use: "server",
Short: "start the Argo Server",
Example: fmt.Sprintf(`
See %s`, help.ArgoServer),
See %s`, help.ArgoServer()),
RunE: func(c *cobra.Command, args []string) error {
cmd.SetLogFormatter(logFormat)
stats.RegisterStackDumper()
Expand Down
2 changes: 1 addition & 1 deletion pkg/apiclient/argo-kube-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ import (

var (
argoKubeOffloadNodeStatusRepo = sqldb.ExplosiveOffloadNodeStatusRepo
NoArgoServerErr = fmt.Errorf("this is impossible if you are not using the Argo Server, see " + help.CLI)
NoArgoServerErr = fmt.Errorf("this is impossible if you are not using the Argo Server, see " + help.CLI())
)

type argoKubeClient struct {
Expand Down
18 changes: 18 additions & 0 deletions pkg/apis/workflow/v1alpha1/version_types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package v1alpha1

import (
"errors"
"regexp"
)

type Version struct {
Version string `json:"version" protobuf:"bytes,1,opt,name=version"`
BuildDate string `json:"buildDate" protobuf:"bytes,2,opt,name=buildDate"`
Expand All @@ -10,3 +15,16 @@ type Version struct {
Compiler string `json:"compiler" protobuf:"bytes,7,opt,name=compiler"`
Platform string `json:"platform" protobuf:"bytes,8,opt,name=platform"`
}

var verRe = regexp.MustCompile(`^v(\d+)\.(\d+)\.(\d+)`)

// BrokenDown returns the major, minor and release components
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
// of the version number, or error if this is not a release
// The error path is considered "normal" in a non-release build.
func (v Version) Components() (string, string, string, error) {
matches := verRe.FindStringSubmatch(v.Version)
if matches == nil || matches[1] == "0" {
return ``, ``, ``, errors.New("Not a formal release")
}
agilgur5 marked this conversation as resolved.
Show resolved Hide resolved
return matches[1], matches[2], matches[3], nil
}
40 changes: 31 additions & 9 deletions util/help/topics.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,35 @@
package help

const (
root = "https://argo-workflows.readthedocs.io/en/latest"
Copy link
Contributor

@agilgur5 agilgur5 Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Raised in response to this

Instead of always linking to latest, link to the versioned documentation where the version of the built software is known

For reference, this was versioned before as well -- each release branch changes the tail of its root.
See also #12446, #12462, #12473.

That's why I changed the title to say "dynamically get", as before it was statically referenced. The dynamic variant is more resilient to change, so I think that's a good change.

The scope is also for the CLI in this case; per the above PRs, there are still several other places that use static version links that could be updated to use this dynamic variant instead.
Some won't be updatable as they're in static documentation (e.g. example YAML, swagger, direct README and other direct markdown (vs docs website rendered), etc). UI would also need similar code to pull out the version numbers to make its references dynamic

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, this is this story: I forgot this existed at all when writing #13265, despite me having used it before in #11646 - so #13265 wasn't using this, and I wrote this function and pulled it out into this PR.

Anyway, I think we're in agreement this is a good change, so I'll fix up some of it in #13265.

ArgoServer = root + "/argo-server/"
CLI = root + "/cli/argo"
import (
"fmt"

WorkflowTemplates = root + "/workflow-templates/"
WorkflowTemplatesReferencingOtherTemplates = WorkflowTemplates + "#referencing-other-workflowtemplates"

Scaling = root + "/scaling/"
ConfigureMaximumRecursionDepth = Scaling + "#maximum-recursion-depth"
"github.com/argoproj/argo-workflows/v3"
)

func root() string {
version := `latest`
if major, minor, _, err := argo.GetVersion().Components(); err == nil {
version = fmt.Sprintf("release-%s.%s", major, minor)
}
return fmt.Sprintf("https://argo-workflows.readthedocs.io/en/%s", version)
}

// ArgoServer returns a URL to the argo-server documentation
func ArgoServer() string {
return root() + "/argo-server/"
}

// CLI returns a URL to the cli documentation
func CLI() string {
return root() + "/cli/argo"
}

// scaling returns a URL to the scaling documentation
func scaling() string {
return root() + "/scaling/"
}

// ConfigureMaximumRecursionDepth returns a URL to the maximum recursion depth documentation
func ConfigureMaximumRecursionDepth() string {
return scaling() + "#maximum-recursion-depth"
}
2 changes: 1 addition & 1 deletion workflow/controller/operator.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var (
// ErrTimeout indicates a specific template timed out
ErrTimeout = errors.New(errors.CodeTimeout, "timeout")
// ErrMaxDepthExceeded indicates that the maximum recursion depth was exceeded
ErrMaxDepthExceeded = errors.New(errors.CodeTimeout, fmt.Sprintf("Maximum recursion depth exceeded. See %s", help.ConfigureMaximumRecursionDepth))
ErrMaxDepthExceeded = errors.New(errors.CodeTimeout, fmt.Sprintf("Maximum recursion depth exceeded. See %s", help.ConfigureMaximumRecursionDepth()))
)

// maxOperationTime is the maximum time a workflow operation is allowed to run
Expand Down
Loading