forked from nektos/act
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add check for newer versions (nektos#1562)
* feat: add check for newer versions * fix: support JSON logger and rever updates to go.mod * fix: keep version updated in source code * fix: lint errors * fix: revert go.*
- Loading branch information
Showing
6 changed files
with
121 additions
and
13 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
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 @@ | ||
0.2.35 |
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,90 @@ | ||
package cmd | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"net/http" | ||
"net/url" | ||
"os" | ||
"runtime" | ||
"time" | ||
|
||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
type Notice struct { | ||
Level string `json:"level"` | ||
Message string `json:"message"` | ||
} | ||
|
||
func displayNotices(input *Input) { | ||
select { | ||
case notices := <-noticesLoaded: | ||
if len(notices) > 0 { | ||
noticeLogger := log.New() | ||
if input.jsonLogger { | ||
noticeLogger.SetFormatter(&log.JSONFormatter{}) | ||
} else { | ||
noticeLogger.SetFormatter(&log.TextFormatter{ | ||
DisableQuote: true, | ||
DisableTimestamp: true, | ||
PadLevelText: true, | ||
}) | ||
} | ||
|
||
fmt.Printf("\n") | ||
for _, notice := range notices { | ||
level, err := log.ParseLevel(notice.Level) | ||
if err != nil { | ||
level = log.InfoLevel | ||
} | ||
noticeLogger.Log(level, notice.Message) | ||
} | ||
} | ||
case <-time.After(time.Second * 1): | ||
log.Debugf("Timeout waiting for notices") | ||
} | ||
} | ||
|
||
var noticesLoaded = make(chan []Notice) | ||
|
||
func loadVersionNotices(version string) { | ||
go func() { | ||
noticesLoaded <- getVersionNotices(version) | ||
}() | ||
} | ||
|
||
const NoticeURL = "https://api.nektosact.com/notices" | ||
|
||
func getVersionNotices(version string) []Notice { | ||
if os.Getenv("ACT_DISABLE_VERSION_CHECK") == "1" { | ||
return nil | ||
} | ||
|
||
noticeURL, err := url.Parse(NoticeURL) | ||
if err != nil { | ||
log.Error(err) | ||
return nil | ||
} | ||
query := noticeURL.Query() | ||
query.Add("os", runtime.GOOS) | ||
query.Add("arch", runtime.GOARCH) | ||
query.Add("version", version) | ||
|
||
noticeURL.RawQuery = query.Encode() | ||
|
||
resp, err := http.Get(noticeURL.String()) | ||
if err != nil { | ||
log.Debug(err) | ||
return nil | ||
} | ||
|
||
defer resp.Body.Close() | ||
notices := []Notice{} | ||
if err := json.NewDecoder(resp.Body).Decode(¬ices); err != nil { | ||
log.Debug(err) | ||
return nil | ||
} | ||
|
||
return notices | ||
} |
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