Skip to content

Commit 42bc916

Browse files
committed
sync-zephyr-artifacts: replace go-git with git command
1 parent 6d4844e commit 42bc916

File tree

2 files changed

+30
-30
lines changed

2 files changed

+30
-30
lines changed

Diff for: extra/sync-zephyr-artifacts/go.mod

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ go 1.24.1
44

55
require (
66
github.com/codeclysm/extract/v4 v4.0.0
7-
github.com/go-git/go-git/v5 v5.14.0
87
github.com/otiai10/copy v1.14.1
98
)
109

Diff for: extra/sync-zephyr-artifacts/main.go

+30-29
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
"io"
1010
"net/http"
1111
"os"
12+
"os/exec"
1213
"path/filepath"
1314
"strings"
1415

1516
"github.com/codeclysm/extract/v4"
16-
"github.com/go-git/go-git/v5"
1717
cp "github.com/otiai10/copy"
1818
)
1919

@@ -58,7 +58,7 @@ func main() {
5858
}
5959
defer os.RemoveAll(tmpDir) // Clean up
6060

61-
// Download the zip file from http://downloads.arduino.cc/cores/zephyr/zephyr-core-llext-{git_tag}.zip
61+
// Download the zip file from http://downloads.arduino.cc/cores/zephyr/ArduinoCore-zephyr-{git_tag}.zip
6262
// and save it to zipFilePath
6363
// Replace {git_tag} with the actual git tag
6464

@@ -68,45 +68,46 @@ func main() {
6868
if len(os.Args) > 2 {
6969
forceHash = os.Args[2]
7070
}
71-
r, err := git.PlainOpen(gitCorePath)
71+
72+
cmd := exec.Command("git", "ls-files", "--exclude-standard", "-dmo", ".")
73+
stdout, err := cmd.Output()
7274
if err != nil {
73-
fmt.Println("Error opening git repository:", err)
75+
fmt.Println("Error executing command:", err)
7476
return
7577
}
76-
ref, err := r.Head()
77-
if err != nil {
78-
fmt.Println("Error getting git reference:", err)
79-
return
78+
79+
var lines []string
80+
var failures []string
81+
lines = strings.Split(string(stdout), "\n")
82+
for _, path := range lines {
83+
if strings.HasPrefix(path, "firmwares/") || strings.HasPrefix(path, "variants/") {
84+
failures = append(failures, path)
85+
}
8086
}
81-
w, err := r.Worktree()
82-
if err != nil {
83-
fmt.Println("Error getting git worktree:", err)
87+
88+
if len(failures) > 0 {
89+
fmt.Println("The git repository contains uncommitted changes:")
90+
for _, path := range failures {
91+
fmt.Println("- ", path)
92+
}
93+
fmt.Println("Please stash them before running this script.")
8494
return
8595
}
86-
// Check if the repo contains modifications in either variants or firmwares folders
87-
status, err := w.StatusWithOptions(git.StatusOptions{Strategy: git.Preload})
96+
97+
cmd = exec.Command("git", "describe", "--always", "--abbrev=7")
98+
stdout, err = cmd.Output()
8899
if err != nil {
89-
fmt.Println("Error getting git status:", err)
100+
fmt.Println("Error executing command:", err)
90101
return
91102
}
92-
if !status.IsClean() {
93-
// Check if there are untracked/modified files in the firmwares or variants folders
94-
for path, s := range status {
95-
if strings.HasPrefix(path, "firmwares/") || strings.HasPrefix(path, "variants/") {
96-
fmt.Println("The git repository contains uncommitted changes in", path)
97-
if s.Worktree != git.Untracked {
98-
fmt.Println("Please stash them before running this script.")
99-
}
100-
return
101-
}
102-
}
103-
}
104-
fmt.Println("Git tag:", ref.Hash())
105-
// Replace {git_tag} with the actual git tag in the URL
106-
hash := ref.Hash().String()[0:7]
103+
104+
hash := strings.TrimSpace(string(stdout))
105+
fmt.Println("Git SHA:", hash)
107106
if forceHash != "" {
108107
hash = forceHash
109108
}
109+
110+
// Compose download URL from git hash
110111
filename := fmt.Sprintf("ArduinoCore-zephyr-%s.tar.bz2", hash)
111112
url := fmt.Sprintf("http://downloads.arduino.cc/cores/zephyr/%s", filename)
112113
fmt.Println("Download URL:", url)

0 commit comments

Comments
 (0)