@@ -9,11 +9,11 @@ import (
9
9
"io"
10
10
"net/http"
11
11
"os"
12
+ "os/exec"
12
13
"path/filepath"
13
14
"strings"
14
15
15
16
"github.com/codeclysm/extract/v4"
16
- "github.com/go-git/go-git/v5"
17
17
cp "github.com/otiai10/copy"
18
18
)
19
19
@@ -50,74 +50,72 @@ func downloadFile(filepath string, url string) (err error) {
50
50
func main () {
51
51
52
52
// 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
54
54
tmpDir , err := os .MkdirTemp ("" , "sync-zephyr-artifacts" )
55
55
if err != nil {
56
56
fmt .Println ("Error creating temp dir:" , err )
57
57
return
58
58
}
59
59
defer os .RemoveAll (tmpDir ) // Clean up
60
60
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
65
62
gitCorePath := os .Args [1 ]
66
63
// Force an hash, for debug only
67
64
forceHash := ""
68
65
if len (os .Args ) > 2 {
69
66
forceHash = os .Args [2 ]
70
67
}
71
- r , err := git .PlainOpen (gitCorePath )
68
+
69
+ cmd := exec .Command ("git" , "ls-files" , "--exclude-standard" , "-dmo" , "." )
70
+ stdout , err := cmd .Output ()
72
71
if err != nil {
73
- fmt .Println ("Error opening git repository :" , err )
72
+ fmt .Println ("Error executing command :" , err )
74
73
return
75
74
}
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
+ }
80
83
}
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." )
84
91
return
85
92
}
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 ()
88
96
if err != nil {
89
- fmt .Println ("Error getting git status :" , err )
97
+ fmt .Println ("Error executing command :" , err )
90
98
return
91
99
}
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 )
107
103
if forceHash != "" {
108
104
hash = forceHash
109
105
}
106
+
107
+ // Compose download URL from git hash
110
108
filename := fmt .Sprintf ("ArduinoCore-zephyr-%s.tar.bz2" , hash )
111
109
url := fmt .Sprintf ("http://downloads.arduino.cc/cores/zephyr/%s" , filename )
112
110
fmt .Println ("Download URL:" , url )
113
111
// Download the zip file from the URL
114
112
zipFilePath := filepath .Join (tmpDir , filename )
115
113
err = downloadFile (zipFilePath , url )
116
114
if err != nil {
117
- fmt .Println ("Error downloading zip file :" , err )
115
+ fmt .Println ("Error downloading archive :" , err )
118
116
return
119
117
}
120
- fmt .Println ("Downloaded zip file to:" , zipFilePath )
118
+ fmt .Println ("Downloaded archive to:" , zipFilePath )
121
119
// Extract the tar.bz2 file to the temporary folder
122
120
// Use packer/tar and compress/bzip2 to extract the file
123
121
file , err := os .Open (filepath .Join (tmpDir , filename ))
0 commit comments