mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-05 22:49:25 +00:00
Use well tested logging sub-library.
This commit is contained in:
+8
-8
@@ -15,7 +15,7 @@ func updatePackage() bool {
|
||||
ghToken, ghTokenSet := os.LookupEnv("GITHUB_TOKEN")
|
||||
if ghTokenSet {
|
||||
binaryName := fmt.Sprintf("semver-gen-%s-%s", runtime.GOOS, runtime.GOARCH)
|
||||
fmt.Println("Downloading", binaryName)
|
||||
logger.Info("semver-gen", map[string]interface{}{"message": "Checking for updates"})
|
||||
gql := graphql.NewConnection()
|
||||
|
||||
gql.SetEndpoint("https://api.github.com/graphql")
|
||||
@@ -43,13 +43,13 @@ func updatePackage() bool {
|
||||
}`
|
||||
result, err := gql.Query(query, variables, headers)
|
||||
if err != nil {
|
||||
fmt.Println("Query error", err)
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to query GitHub API"})
|
||||
return false
|
||||
}
|
||||
|
||||
output, ok := ask.For(result, "repository.latestRelease.releaseAssets.edges[0].node.downloadUrl").String("")
|
||||
if !ok {
|
||||
fmt.Println("Unable to obtain download url for the binary", binaryName, output)
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": "Unable to obtain download url for the binary", "binary": binaryName, "output": output})
|
||||
return false
|
||||
}
|
||||
if flag.Lookup("test.v") == nil && os.Getenv("CI") == "" {
|
||||
@@ -57,22 +57,22 @@ func updatePackage() bool {
|
||||
g := got.New()
|
||||
err = g.Download(output, downloadedBinaryPath)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to download binary", err.Error())
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to download binary", "binaryPath": downloadedBinaryPath})
|
||||
return false
|
||||
}
|
||||
currentBinary, err := os.Executable()
|
||||
if err != nil {
|
||||
fmt.Println("Unable to obtain current binary path", err.Error())
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to obtain current binary path"})
|
||||
return false
|
||||
}
|
||||
err = os.Rename(downloadedBinaryPath, currentBinary)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to overwrite current binary", err.Error())
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to overwrite current binary"})
|
||||
return false
|
||||
}
|
||||
err = os.Chmod(currentBinary, 0777)
|
||||
if err != nil {
|
||||
fmt.Println("Unable to make binary executable", err.Error())
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to make binary executable"})
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ func checkLatestRelease() (string, bool) {
|
||||
}`
|
||||
result, err := gql.Query(query, variables, headers)
|
||||
if err != nil {
|
||||
fmt.Println("Query error >>", err)
|
||||
logger.Error("semver-gen", map[string]interface{}{"error": err.Error(), "message": "Unable to query GitHub API"})
|
||||
return "", false
|
||||
}
|
||||
output, _ := ask.For(result, "repository.releases.nodes[0].tag.name").String("")
|
||||
|
||||
Reference in New Issue
Block a user