Compare commits

..

3 Commits

Author SHA1 Message Date
Minghe
1cb68766f7 fix version parse (#324) 2019-10-14 20:39:47 +08:00
Minghe Huang
91fd5dc59f bump version 2019-10-14 16:49:29 +08:00
Changxin Miao
184235acb2 Automatically notify user of new release (#317)
* Automatically notify user of new release

Signed-off-by: Changxin Miao <mcx_221@foxmail.com>

* Update naming convention
2019-10-14 13:38:07 +08:00
2 changed files with 38 additions and 2 deletions

View File

@@ -97,7 +97,7 @@ jobs:
git config --global user.name "Minghe Huang"
commit=$(git rev-parse --short HEAD)
version=$(cat fx.go| grep Version | awk -F'"' '{print $2}')
version=$(cat fx.go| grep 'const version' | awk -F'"' '{print $2}')
echo "workflow is running on branch ${GITHUB_REF}"

38
fx.go
View File

@@ -1,8 +1,12 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"os"
"path"
"regexp"
"github.com/apex/log"
"github.com/google/uuid"
@@ -11,9 +15,12 @@ import (
"github.com/urfave/cli"
)
const version = "0.7.4"
var cfg *config.Config
func init() {
go checkForUpdate()
configDir := path.Join(os.Getenv("HOME"), ".fx")
cfg := config.New(configDir)
@@ -23,11 +30,40 @@ func init() {
}
}
func checkForUpdate() {
const releaseURL = "https://api.github.com/repos/metrue/fx/releases/latest"
resp, err := http.Get(releaseURL)
if err != nil {
log.Debugf("Failed to fetch Github release page, error %v", err)
return
}
defer resp.Body.Close()
decoder := json.NewDecoder(resp.Body)
var releaseJSON struct {
Tag string `json:"tag_name"`
URL string `json:"html_url"`
}
if err := decoder.Decode(&releaseJSON); err != nil {
log.Debugf("Failed to decode Github release page JSON, error %v", err)
return
}
if matched, err := regexp.MatchString(`^(\d+\.)(\d+\.)(\d+)$`, releaseJSON.Tag); err != nil || !matched {
log.Debugf("Unofficial release %s?", releaseJSON.Tag)
return
}
log.Debugf("Latest release tag is %s", releaseJSON.Tag)
if releaseJSON.Tag != version {
fmt.Fprintf(os.Stderr, "\nfx %s is available (you're using %s), get the latest release from: %s\n",
releaseJSON.Tag, version, releaseJSON.URL)
}
}
func main() {
app := cli.NewApp()
app.Name = "fx"
app.Usage = "makes function as a service"
app.Version = "0.7.3"
app.Version = version
app.Commands = []cli.Command{
{