mirror of
https://github.com/lukaszraczylo/semver-generator.git
synced 2026-06-08 23:03:44 +00:00
fixup! Update documentation.
This commit is contained in:
+19
-19
@@ -21,7 +21,7 @@ func UpdatePackage() bool {
|
||||
|
||||
binaryName := fmt.Sprintf("semver-gen-%s-%s", runtime.GOOS, runtime.GOARCH)
|
||||
Info("Checking for updates", map[string]interface{}{"binaryName": binaryName})
|
||||
|
||||
|
||||
gql := graphql.NewConnection()
|
||||
gql.SetEndpoint("https://api.github.com/graphql")
|
||||
gql.SetOutput("mapstring")
|
||||
@@ -29,11 +29,11 @@ func UpdatePackage() bool {
|
||||
headers := map[string]interface{}{
|
||||
"Authorization": fmt.Sprintf("Bearer %s", ghToken),
|
||||
}
|
||||
|
||||
|
||||
variables := map[string]interface{}{
|
||||
"binaryName": binaryName,
|
||||
}
|
||||
|
||||
|
||||
var query = `query ($binaryName: String) {
|
||||
repository(name: "semver-generator", owner: "lukaszraczylo") {
|
||||
latestRelease {
|
||||
@@ -48,7 +48,7 @@ func UpdatePackage() bool {
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
|
||||
result, err := gql.Query(query, variables, headers)
|
||||
if err != nil {
|
||||
Error("Unable to query GitHub API", map[string]interface{}{"error": err.Error()})
|
||||
@@ -58,12 +58,12 @@ func UpdatePackage() bool {
|
||||
output, ok := ask.For(result, "repository.latestRelease.releaseAssets.edges[0].node.downloadUrl").String("")
|
||||
if !ok {
|
||||
Error("Unable to obtain download url for the binary", map[string]interface{}{
|
||||
"binary": binaryName,
|
||||
"binary": binaryName,
|
||||
"output": output,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
// Skip actual download in test mode
|
||||
if flag.Lookup("test.v") == nil && os.Getenv("CI") == "" {
|
||||
downloadedBinaryPath := fmt.Sprintf("/tmp/%s", binaryName)
|
||||
@@ -71,12 +71,12 @@ func UpdatePackage() bool {
|
||||
err = g.Download(output, downloadedBinaryPath)
|
||||
if err != nil {
|
||||
Error("Unable to download binary", map[string]interface{}{
|
||||
"error": err.Error(),
|
||||
"error": err.Error(),
|
||||
"binaryPath": downloadedBinaryPath,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
currentBinary, err := os.Executable()
|
||||
if err != nil {
|
||||
Error("Unable to obtain current binary path", map[string]interface{}{
|
||||
@@ -84,7 +84,7 @@ func UpdatePackage() bool {
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
err = os.Rename(downloadedBinaryPath, currentBinary)
|
||||
if err != nil {
|
||||
Error("Unable to overwrite current binary", map[string]interface{}{
|
||||
@@ -92,7 +92,7 @@ func UpdatePackage() bool {
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
|
||||
err = os.Chmod(currentBinary, 0777)
|
||||
if err != nil {
|
||||
Error("Unable to make binary executable", map[string]interface{}{
|
||||
@@ -101,7 +101,7 @@ func UpdatePackage() bool {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
@@ -111,16 +111,16 @@ func CheckLatestRelease() (string, bool) {
|
||||
if !ghTokenSet {
|
||||
return "[no GITHUB_TOKEN set]", false
|
||||
}
|
||||
|
||||
|
||||
gql := graphql.NewConnection()
|
||||
gql.SetEndpoint("https://api.github.com/graphql")
|
||||
|
||||
|
||||
headers := map[string]interface{}{
|
||||
"Authorization": fmt.Sprintf("bearer %s", ghToken),
|
||||
}
|
||||
|
||||
|
||||
variables := map[string]interface{}{}
|
||||
|
||||
|
||||
var query = `query {
|
||||
repository(name: "semver-generator", owner: "lukaszraczylo", followRenames: true) {
|
||||
releases(last: 2) {
|
||||
@@ -132,17 +132,17 @@ func CheckLatestRelease() (string, bool) {
|
||||
}
|
||||
}
|
||||
}`
|
||||
|
||||
|
||||
result, err := gql.Query(query, variables, headers)
|
||||
if err != nil {
|
||||
Error("Unable to query GitHub API", map[string]interface{}{"error": err.Error()})
|
||||
return "", false
|
||||
}
|
||||
|
||||
|
||||
output, _ := ask.For(result, "repository.releases.nodes[0].tag.name").String("")
|
||||
if output == "v1" {
|
||||
output, _ = ask.For(result, "repository.releases.nodes[1].tag.name").String("")
|
||||
}
|
||||
|
||||
|
||||
return output, true
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user