Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
105 additions
and
47 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
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,17 @@ | ||
package messages | ||
|
||
var ( | ||
ERROR_INVALID_CLI_VERSION = "Astronomer CLI version is not valid" | ||
ERROR_GITHUB_JSON_MARSHALLING = "Failed to JSON decode Github response from %s" | ||
|
||
INFO_CURR_CLI_VERSION = "Astro CLI Version: v%s" | ||
INFO_CURR_CLI_COMMIT = "Git Commit: %s" | ||
INFO_CURR_CLI_VERSION_DATE = INFO_CURR_CLI_VERSION + " (%s)" | ||
INFO_LATEST_CLI_VERSION = "Astro CLI Latest: %s " | ||
INFO_LATEST_CLI_VERSION_DATE = INFO_LATEST_CLI_VERSION + " (%s)" | ||
INFO_CLI_INSTALL_CMD = "\t$ curl -sL https://install.astronomer.io | sudo bash" | ||
INFO_UPGRADE_CLI = "There is a more recent version of the Astronomer CLI available.\nYou can install the latest tagged release with the following command" | ||
INFO_UNTAGGED_VERSION = "Your current Astronomer CLI is not tagged.\nThis is likely the result of building from source. You can install the latest tagged release with the following command" | ||
|
||
NA = "N/A" | ||
) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package version | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
|
||
"github.com/astronomerio/astro-cli/messages" | ||
"github.com/astronomerio/astro-cli/pkg/github" | ||
) | ||
|
||
var ( | ||
api = github.NewGithubClient() | ||
) | ||
|
||
// PrintVersion outputs current cli version and git commit if exists | ||
func PrintVersion(version, gitCommit string) error { | ||
if !isValidVersion(version) { | ||
return errors.New(messages.ERROR_INVALID_CLI_VERSION) | ||
} | ||
|
||
fmt.Printf(messages.INFO_CURR_CLI_VERSION+"\n", version) | ||
fmt.Printf(messages.INFO_CURR_CLI_COMMIT+"\n", gitCommit) | ||
return nil | ||
} | ||
|
||
// CheckForUpdate checks current version against latest on github | ||
func CheckForUpdate(version, gitCommit string) error { | ||
if !isValidVersion(version) { | ||
fmt.Println(messages.INFO_UNTAGGED_VERSION) | ||
fmt.Println(messages.INFO_CLI_INSTALL_CMD) | ||
return nil | ||
} | ||
|
||
// fetch latest cli version | ||
latestTagResp, err := api.RepoLatestRequest("astronomerio", "astro-cli") | ||
if err != nil { | ||
fmt.Println(err) | ||
latestTagResp.TagName = messages.NA | ||
} | ||
|
||
// fetch meta data around current cli version | ||
currentTagResp, err := api.RepoTagRequest("astronomerio", "astro-cli", string("v")+version) | ||
if err != nil { | ||
fmt.Println(err) | ||
} | ||
|
||
currentPub := currentTagResp.PublishedAt.Format("2006.01.02") | ||
latestPub := latestTagResp.PublishedAt.Format("2006.01.02") | ||
latestTag := latestTagResp.TagName | ||
|
||
if latestTagResp.TagName > version { | ||
fmt.Printf(messages.INFO_CURR_CLI_VERSION_DATE+"\n", version, currentPub) | ||
fmt.Printf(messages.INFO_LATEST_CLI_VERSION_DATE+"\n", latestTag, latestPub) | ||
fmt.Println(messages.INFO_UPGRADE_CLI) | ||
fmt.Println(messages.INFO_CLI_INSTALL_CMD) | ||
return nil | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func isValidVersion(version string) bool { | ||
if len(version) == 0 { | ||
return false | ||
} | ||
return true | ||
} |