-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added check for update in any mandatory release of karmor CLI
Signed-off-by: sibashi <[email protected]>
- Loading branch information
1 parent
8edc262
commit e448345
Showing
3 changed files
with
65 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package checks | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/fatih/color" | ||
"github.com/google/go-github/github" | ||
"github.com/kubearmor/kubearmor-client/selfupdate" | ||
"strings" | ||
) | ||
|
||
func CheckForUpdates() error { | ||
client := github.NewClient(nil) | ||
|
||
// Fetch all releases from the GitHub API | ||
releases, _, err := client.Repositories.ListReleases(context.Background(), | ||
"kubearmor", | ||
"kubearmor-client", | ||
&github.ListOptions{ | ||
Page: 1, | ||
PerPage: 100, | ||
}, | ||
) | ||
if err != nil { | ||
fmt.Println("Error fetching releases:", err) | ||
return err | ||
} | ||
|
||
// Find the latest release with the keyword "mandatory" in its release notes | ||
var latestMandatoryRelease *github.RepositoryRelease | ||
for _, release := range releases { | ||
if strings.Contains(*release.Body, "mandatory") { | ||
latestMandatoryRelease = release | ||
break | ||
} | ||
} | ||
|
||
// Compare the current version with the latest release version | ||
currentVersion := selfupdate.GitSummary | ||
if err != nil { | ||
return err | ||
} | ||
if latestMandatoryRelease != nil && !strings.EqualFold(currentVersion, *latestMandatoryRelease.TagName) { | ||
color.HiMagenta("A mandatory update is available (current version: %s, latest release: %s).\n", | ||
currentVersion, | ||
*latestMandatoryRelease.TagName, | ||
) | ||
} else { | ||
fmt.Println("The client is up to date.") | ||
} | ||
|
||
return nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters