Skip to content

Commit 19acd5a

Browse files
committed
sync-zephyr-artifacts: replace go-git with git command
1 parent b946d76 commit 19acd5a

File tree

2 files changed

+33
-36
lines changed

2 files changed

+33
-36
lines changed

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

extra/sync-zephyr-artifacts/main.go

+33-35
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

@@ -50,74 +50,72 @@ func downloadFile(filepath string, url string) (err error) {
5050
func main() {
5151

5252
// Create a temporary folder, download a URL based on a git tag in it
53-
// and extract the zip file to the temporary folder
53+
// and extract the file to the temporary folder
5454
tmpDir, err := os.MkdirTemp("", "sync-zephyr-artifacts")
5555
if err != nil {
5656
fmt.Println("Error creating temp dir:", err)
5757
return
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
62-
// and save it to zipFilePath
63-
// Replace {git_tag} with the actual git tag
64-
61+
// Download the file from http://downloads.arduino.cc/cores/zephyr/ArduinoCore-zephyr-{git_tag}.zip
6562
gitCorePath := os.Args[1]
6663
// Force an hash, for debug only
6764
forceHash := ""
6865
if len(os.Args) > 2 {
6966
forceHash = os.Args[2]
7067
}
71-
r, err := git.PlainOpen(gitCorePath)
68+
69+
cmd := exec.Command("git", "ls-files", "--exclude-standard", "-dmo", ".")
70+
stdout, err := cmd.Output()
7271
if err != nil {
73-
fmt.Println("Error opening git repository:", err)
72+
fmt.Println("Error executing command:", err)
7473
return
7574
}
76-
ref, err := r.Head()
77-
if err != nil {
78-
fmt.Println("Error getting git reference:", err)
79-
return
75+
76+
var lines []string
77+
var changes []string
78+
lines = strings.Split(string(stdout), "\n")
79+
for _, path := range lines {
80+
if strings.HasPrefix(path, "firmwares/") || strings.HasPrefix(path, "variants/") {
81+
changes = append(changes, path)
82+
}
8083
}
81-
w, err := r.Worktree()
82-
if err != nil {
83-
fmt.Println("Error getting git worktree:", err)
84+
85+
if len(changes) > 0 {
86+
fmt.Println("The git repository contains uncommitted files:")
87+
for _, path := range changes {
88+
fmt.Println("- ", path)
89+
}
90+
fmt.Println("Please commit or stash them before running this script.")
8491
return
8592
}
86-
// Check if the repo contains modifications in either variants or firmwares folders
87-
status, err := w.StatusWithOptions(git.StatusOptions{Strategy: git.Preload})
93+
94+
cmd = exec.Command("git", "describe", "--always", "--abbrev=7")
95+
stdout, err = cmd.Output()
8896
if err != nil {
89-
fmt.Println("Error getting git status:", err)
97+
fmt.Println("Error executing command:", err)
9098
return
9199
}
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]
100+
101+
hash := strings.TrimSpace(string(stdout))
102+
fmt.Println("Git SHA:", hash)
107103
if forceHash != "" {
108104
hash = forceHash
109105
}
106+
107+
// Compose download URL from git hash
110108
filename := fmt.Sprintf("ArduinoCore-zephyr-%s.tar.bz2", hash)
111109
url := fmt.Sprintf("http://downloads.arduino.cc/cores/zephyr/%s", filename)
112110
fmt.Println("Download URL:", url)
113111
// Download the zip file from the URL
114112
zipFilePath := filepath.Join(tmpDir, filename)
115113
err = downloadFile(zipFilePath, url)
116114
if err != nil {
117-
fmt.Println("Error downloading zip file:", err)
115+
fmt.Println("Error downloading archive:", err)
118116
return
119117
}
120-
fmt.Println("Downloaded zip file to:", zipFilePath)
118+
fmt.Println("Downloaded archive to:", zipFilePath)
121119
// Extract the tar.bz2 file to the temporary folder
122120
// Use packer/tar and compress/bzip2 to extract the file
123121
file, err := os.Open(filepath.Join(tmpDir, filename))

0 commit comments

Comments
 (0)