update more deps

This commit is contained in:
maddalax 2024-10-25 07:48:41 -05:00
parent d538f6f7a8
commit 1924270e4e
2 changed files with 28 additions and 17 deletions

View file

@ -30,9 +30,6 @@ func (n *CustomNode) SetType(in string) {
n.Type = "h.TBody" n.Type = "h.TBody"
case "id": case "id":
n.Type = "h.Id" n.Type = "h.Id"
case "path":
n.Type = "path"
n.customType = true
case "circle": case "circle":
n.Type = "circle" n.Type = "circle"
n.customType = true n.customType = true

View file

@ -13,6 +13,13 @@ import (
) )
const frameworkRepo = "github.com/maddalax/htmgo/framework" const frameworkRepo = "github.com/maddalax/htmgo/framework"
const htmlToHtmgoRepo = "github.com/maddalax/htmgo/tools/html-to-htmgo"
var depsToUpdate = []string{
frameworkRepo,
htmlToHtmgoRepo,
}
const githubAPIURL = "https://api.github.com/repos/maddalax/htmgo/commits" const githubAPIURL = "https://api.github.com/repos/maddalax/htmgo/commits"
// Commit represents the structure of a commit object returned by the GitHub API. // Commit represents the structure of a commit object returned by the GitHub API.
@ -52,17 +59,14 @@ func main() {
// Check if the directory contains a go.mod file. // Check if the directory contains a go.mod file.
if info.IsDir() && fileExists(filepath.Join(path, "go.mod")) { if info.IsDir() && fileExists(filepath.Join(path, "go.mod")) {
// Check if the go.mod contains 'github.com/maddalax/htmgo/framework'. goModPath := filepath.Join(path, "go.mod")
if containsFrameworkDependency(filepath.Join(path, "go.mod")) {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
// Run go get github.com/maddalax/htmgo/framework@<latestCommitHash>. for _, s := range depsToUpdate {
fmt.Printf("Running 'go get' with latest commit hash in %s\n", path) updateDepToLatestVersion(s, goModPath, latestCommitHash)
RunCommand(path, "go", "get", fmt.Sprintf("%s@%s", frameworkRepo, latestCommitHash))
RunCommand(path, "go", "mod", "tidy")
}()
} }
}()
} }
return nil return nil
@ -82,8 +86,18 @@ func fileExists(path string) bool {
return !os.IsNotExist(err) return !os.IsNotExist(err)
} }
// containsFrameworkDependency checks if 'github.com/maddalax/htmgo/framework' is in the go.mod file. func updateDepToLatestVersion(dep string, goModPath string, latestCommitHash string) {
func containsFrameworkDependency(goModPath string) bool { if containsDep(dep, goModPath) {
dir := filepath.Dir(goModPath)
// Run go get github.com/maddalax/htmgo/framework@<latestCommitHash>.
fmt.Printf("Running 'go get' with latest commit hash in %s\n", dep)
RunCommand(dir, "go", "get", fmt.Sprintf("%s@%s", dep, latestCommitHash))
RunCommand(dir, "go", "mod", "tidy")
}
}
// containsDep checks if 'github.com/maddalax/htmgo/framework' is in the go.mod file.
func containsDep(dep string, goModPath string) bool {
file, err := os.Open(goModPath) file, err := os.Open(goModPath)
if err != nil { if err != nil {
fmt.Println("Error opening go.mod file:", err) fmt.Println("Error opening go.mod file:", err)
@ -93,7 +107,7 @@ func containsFrameworkDependency(goModPath string) bool {
scanner := bufio.NewScanner(file) scanner := bufio.NewScanner(file)
for scanner.Scan() { for scanner.Scan() {
if strings.Contains(scanner.Text(), frameworkRepo) { if strings.Contains(scanner.Text(), dep) {
return true return true
} }
} }