Kuadrant / kuadrantctl

Kuadrant configuration command line utility
Apache License 2.0
6 stars 13 forks source link

Add to install make target to ensure that when a change is made to the main branch, that the commit hash is referenced as the version. #82

Closed ehearneRedHat closed 3 months ago

ehearneRedHat commented 4 months ago

What:

For non-releases, on main branch, when there is a new change made, a GitHub action should pick this up and change the version in version/version.go to something along the lines of dev - "commit hash" so that when the user builds the binary and runs ./kuadrantctl version it reports:

{"level":"info","ts":"2024-05-20T12:54:31+01:00","msg":"kuadrantctl version: dev - <commit hash>"}
R-Lawton commented 4 months ago

What are you thiking when you say non-releases? Could you give more info? If its what I'm thinking which is just when something is merged to main at any given time. If we automate adding the latest commit hash to version that can get very noisy and also would the latest commit not then be the commit of the gh action resulting in a new commit causing the action to be triggered again and rinse and repeat ?

ehearneRedHat commented 4 months ago

What are you thiking when you say non-releases?

I am saying that for any changes on main that the version is reported as a commit hash.

If we automate adding the latest commit hash to version that can get very noisy

Agreed, it seems like a difficult task to do.

would the latest commit not then be the commit of the gh action resulting in a new commit causing the action to be triggered again and rinse and repeat ?

I am unsure as of now, but as I understand it, the commit hash is based on the file changes. It would depend on how the logic is implemented but if it was done as a recursive check, then that is correct.

After thinking about your questions, it might be best to close this comment and re-evaluate the issue at hand, and re-open if needed. Thanks for questioning the realisation of the issue. :)

ehearneRedHat commented 4 months ago

@R-Lawton it seems like interest is ramping up for making this happen. It might be a good idea to research it further to see if it is possible. Therefore, I am going to re-open. :)

ehearneRedHat commented 4 months ago

@R-Lawton I believe it is possible to do, but not as a GitHub Action. We could use git rev-parse HEAD to get the hash of the latest commit, which would run the command as the user runs ./kuadrantctl version and would therefore show the user where exactly their version of the code is coming from.

ehearneRedHat commented 4 months ago

For example, we could implement this code in version/version.go in order to show the user what version they are on.

func getCommitHash() (string, error) {
    cmd := exec.Command("git", "rev-parse", "HEAD")
    output, err := cmd.Output()
    if err != nil {
        return "v0.0.0", err
    }
    commitHash := strings.TrimSpace(string(output))
    return commitHash, nil
}
version, err := getCommitHash()

if err != nil { 
  // implement code logic here to print v0.0.0 for systems without git installed
}
// implement code logic here to print commit hash for systems with git installed
ehearneRedHat commented 4 months ago

WIP https://github.com/Kuadrant/kuadrantctl/pull/85

ehearneRedHat commented 3 months ago

Closing as resolved in #85 .