Add a way to check the minimum version supported by a LURE repo

This commit is contained in:
Elara 2022-11-22 12:51:45 -08:00
parent 3361358b3c
commit 3437df8676
6 changed files with 59 additions and 2 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
/lure /lure
/dist/ /dist/
/version.txt

View File

@ -1,6 +1,7 @@
before: before:
hooks: hooks:
- go mod tidy - go mod tidy
- go generate
builds: builds:
- id: lure - id: lure
env: env:

View File

@ -1,4 +1,4 @@
lure: lure: version.txt
go build go build
clean: clean:
@ -9,5 +9,8 @@ install: lure
uninstall: uninstall:
rm -f /usr/local/bin/lure rm -f /usr/local/bin/lure
version.txt:
go generate
.PHONY: install clean uninstall .PHONY: install clean uninstall

43
repo.go
View File

@ -41,6 +41,12 @@ func (p PkgNotFoundError) Error() string {
return "package '" + p.pkgName + "' could not be found in any repository" return "package '" + p.pkgName + "' could not be found in any repository"
} }
type RepoConfig struct {
Repo struct {
MinVersion string `toml:"minVersion"`
}
}
func addrepoCmd(c *cli.Context) error { func addrepoCmd(c *cli.Context) error {
name := c.String("name") name := c.String("name")
repoURL := c.String("url") repoURL := c.String("url")
@ -223,6 +229,26 @@ func pullRepos(ctx context.Context) error {
} else if err != nil { } else if err != nil {
return err return err
} }
fl, err := w.Filesystem.Open("lure-repo.toml")
if err != nil {
log.Warn("Git repository does not appear to be a valid LURE repo").Str("repo", repo.Name).Send()
continue
}
var repoCfg RepoConfig
err = toml.NewDecoder(fl).Decode(&repoCfg)
if err != nil {
return err
}
fl.Close()
currentVer, _, _ := strings.Cut(version, "-")
if vercmp(currentVer, repoCfg.Repo.MinVersion) == -1 {
log.Warn("LURE repo's minumum LURE version is greater than the current version. Try updating LURE if something doesn't work.").Str("repo", repo.Name).Send()
}
continue
} }
err = os.RemoveAll(repoDir) err = os.RemoveAll(repoDir)
@ -246,6 +272,23 @@ func pullRepos(ctx context.Context) error {
if err != nil { if err != nil {
return err return err
} }
fl, err := os.Open(filepath.Join(repoDir, "lure-repo.toml"))
if err != nil {
log.Warn("Git repository does not appear to be a valid LURE repo").Str("repo", repo.Name).Send()
}
var repoCfg RepoConfig
err = toml.NewDecoder(fl).Decode(&repoCfg)
if err != nil {
return err
}
fl.Close()
currentVer, _, _ := strings.Cut(version, "-")
if vercmp(currentVer, repoCfg.Repo.MinVersion) == -1 {
log.Warn("LURE repo's minumum LURE version is greater than the current version. Try updating LURE if something doesn't work.").Str("repo", repo.Name).Send()
}
} }
return nil return nil

3
scripts/gen-version.sh Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
git describe --tags > version.txt

View File

@ -19,12 +19,18 @@
package main package main
import ( import (
_ "embed"
"strconv" "strconv"
"strings" "strings"
"golang.org/x/exp/slices" "golang.org/x/exp/slices"
) )
//go:generate scripts/gen-version.sh
//go:embed version.txt
var version string
// vercmp compares two version strings. // vercmp compares two version strings.
// It returns 1 if v1 is greater, // It returns 1 if v1 is greater,
// 0 if the versions are equal, // 0 if the versions are equal,