generate versions file
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
60c358a151
commit
814c523f52
|
|
@ -0,0 +1 @@
|
|||
/autoupdate
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
opensmtpd:
|
||||
type: github
|
||||
args:
|
||||
repository: OpenSMTPD/OpenSMTPD
|
||||
|
|
@ -0,0 +1 @@
|
|||
opensmtpd: v6.8.0p2
|
||||
4
go.mod
4
go.mod
|
|
@ -8,7 +8,11 @@ require (
|
|||
)
|
||||
|
||||
require (
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d // indirect
|
||||
github.com/davecgh/go-spew v1.1.0 // indirect
|
||||
github.com/pmezard/go-difflib v1.0.0 // indirect
|
||||
github.com/russross/blackfriday/v2 v2.0.1 // indirect
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
|
||||
github.com/urfave/cli v1.22.5 // indirect
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect
|
||||
)
|
||||
|
|
|
|||
10
go.sum
10
go.sum
|
|
@ -1,11 +1,21 @@
|
|||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d h1:U+s90UTSYgptZMwQh2aRr3LuazLJIa+Pg3Kc1ylSYVY=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.0-20190314233015-f79a8a8ca69d/go.mod h1:maD7wRr/U5Z6m/iR4s+kqSMx2CaBsrgA7czyZG/E6dU=
|
||||
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
|
||||
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/russross/blackfriday/v2 v2.0.1 h1:lPqVAte+HuHNfhJ/0LC98ESWRz8afy9tM/0RK8m9o+Q=
|
||||
github.com/russross/blackfriday/v2 v2.0.1/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0 h1:PdmoCO6wvbs+7yrJyMORt4/BmY5IYyJwS/kOiWx8mHo=
|
||||
github.com/shurcooL/sanitized_anchor_name v1.0.0/go.mod h1:1NzhyTcUVG4SuEtjjoZeVRXNmyL/1OwPU0+IJeTBvfc=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
|
||||
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||
github.com/urfave/cli v1.22.5 h1:lNq9sAHXK2qfdI8W+GRItjCEkI+2oR4d+MEHy1CKXoU=
|
||||
github.com/urfave/cli v1.22.5/go.mod h1:Gos4lmkARVdJ6EkW0WaNv/tZAAMe9V7XWyB60NtXRu0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie2QXMNeKRTHCNY2nXvo=
|
||||
|
|
|
|||
79
main.go
79
main.go
|
|
@ -1,34 +1,65 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"os"
|
||||
|
||||
"github.com/urfave/cli"
|
||||
"gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type Version interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type VersionProvider interface {
|
||||
GetVersion() (Version, error)
|
||||
}
|
||||
|
||||
func main() {
|
||||
v := GitHubVersionProvider{Repository: "OpenSMTPD/OpenSMTPD"}
|
||||
latest, err := v.GetVersion()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(latest.String())
|
||||
app := &cli.App{
|
||||
Name: "autoupdate",
|
||||
ArgsUsage: "[CONFIG_FILE] [VERSIONS_FILE]",
|
||||
|
||||
yv := YamlVersionProvider{
|
||||
File: "./versions.yml",
|
||||
Key: "opensmtpd_version",
|
||||
}
|
||||
Action: func(c *cli.Context) error {
|
||||
if c.NArg() != 2 {
|
||||
cli.ShowAppHelp(c)
|
||||
}
|
||||
|
||||
current, err := yv.GetVersion()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
fmt.Println(current.String())
|
||||
var sources map[string]struct {
|
||||
Type string `yaml:"type"`
|
||||
Args map[string]interface{} `yaml:"args"`
|
||||
}
|
||||
|
||||
conf, err := os.Open(c.Args().Get(0))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
defer conf.Close()
|
||||
|
||||
versions, err := os.Create(c.Args().Get(1))
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
defer versions.Close()
|
||||
|
||||
err = yaml.NewDecoder(conf).Decode(&sources)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
new_versions := make(map[string]string, len(sources))
|
||||
for name, source := range sources {
|
||||
provider, err := GetProvider(source.Type, source.Args)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
v, err := provider.GetVersion()
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
new_versions[name] = v.String()
|
||||
}
|
||||
yaml.NewEncoder(versions).Encode(new_versions)
|
||||
return nil
|
||||
},
|
||||
}
|
||||
app.Run(os.Args)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,25 @@
|
|||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type Version interface {
|
||||
String() string
|
||||
}
|
||||
|
||||
type VersionProvider interface {
|
||||
GetVersion() (Version, error)
|
||||
}
|
||||
|
||||
func GetProvider(p string, args map[string]interface{}) (VersionProvider, error) {
|
||||
switch p {
|
||||
case "github":
|
||||
drafts, _ := args["drafts"].(bool)
|
||||
prereleases, _ := args["prereleases"].(bool)
|
||||
return &GitHubVersionProvider{
|
||||
Repository: args["repository"].(string),
|
||||
IncludeDrafts: drafts,
|
||||
IncludePrereleases: prereleases,
|
||||
}, nil
|
||||
}
|
||||
return nil, fmt.Errorf("unknown provider: %s", p)
|
||||
}
|
||||
Loading…
Reference in New Issue