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

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 opened this issue May 20, 2024 · 7 comments
Assignees

Comments

@ehearneRedHat
Copy link
Contributor

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
Copy link
Contributor

R-Lawton commented May 21, 2024

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
Copy link
Contributor Author

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
Copy link
Contributor Author

@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 ehearneRedHat reopened this May 21, 2024
@ehearneRedHat
Copy link
Contributor Author

@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
Copy link
Contributor Author

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
Copy link
Contributor Author

WIP #85

@ehearneRedHat ehearneRedHat self-assigned this May 23, 2024
@ehearneRedHat
Copy link
Contributor Author

Closing as resolved in #85 .

@ehearneRedHat ehearneRedHat changed the title Create a GitHub Action to ensure that when a change is made to the main branch, that the commit hash is referenced as the version. 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. Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants