Skip to content

Commit be520bd

Browse files
authored
Merge pull request #10 from mouuff/rework/executable_name
More modular executable name option
2 parents 4602f11 + ae12ac6 commit be520bd

8 files changed

Lines changed: 30 additions & 28 deletions

File tree

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ Here is an example using Github releases:
3636
u := &updater.Updater{
3737
Provider: &provider.Github{
3838
RepositoryURL: "github.com/mouuff/go-rocket-update-example",
39-
ZipName: "binaries_" + runtime.GOOS + ".zip",
39+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
4040
},
41-
ExecutableName: "go-rocket-update-example",
42-
Version: "v0.1",
41+
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
42+
Version: "v0.0.1",
4343
}
4444
log.Println(u.Version)
4545
err := u.Update()
@@ -63,28 +63,30 @@ Here is few examples of providers:
6363

6464
The updater will list the files and retrieve them the same way for all the providers:
6565

66-
The directory should contain files with the name: ExecutableName-$GOOS-$ARCH.
66+
The directory should have files containing `ExecutableName`.
6767

68-
Example with ExecutableName `test`:
68+
Example directory with `ExecutableName: fmt.Sprintf("test_%s_%s", runtime.GOOS, runtime.GOARCH)`:
6969

70-
test-windows-386
71-
test-darwin-amd64
72-
test-linux-arm
70+
test_windows_amd64.exe
71+
test_darwin_amd64
72+
test_linux_arm
7373

7474
We recommend using [goxc](https://github.com/laher/goxc) for compiling your Go application for multiple platforms.
7575

7676
### Planned features
7777
This project is currently under construction, here is some of the things to come:
7878
* More documentation and examples
79-
* Google cloud storage and FTP providers
79+
* Google cloud storage, tar.gz, and FTP providers
8080
* Mutliple providers (enables the use of another provider if the first one is down)
8181
* Update channels for Github provider (alpha, beta, ...)
82+
* Validation of the executable being installed
8283

8384

8485

8586
## API Breaking Changes
86-
- **Feb 7, 2021**: The `BinaryName` variable used in `Updater` have been renamed to `ExecutableName`.
87-
- **Feb 12, 2021**: The method `Updater.Update()` now returns `(UpdateStatus, error)` instead of just `(error)`.
87+
- **Feb 7, 2021**: Minor: The `BinaryName` variable used in `Updater` have been renamed to `ExecutableName`.
88+
- **Feb 12, 2021**: Minor: The method `Updater.Update()` now returns `(UpdateStatus, error)` instead of just `(error)`.
89+
- **Feb 14, 2021**: Major: The `ExecutableName` variable used in `Updater` is not automatically prefixed with `"_" + runtime.GOOS + "_" + runtime.GOARCH` anymore.
8890

8991

9092
[tu]: https://twitter.com/tenntenn

examples/github-background/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"runtime"
67
"sync"
@@ -16,9 +17,9 @@ func main() {
1617
u := &updater.Updater{
1718
Provider: &provider.Github{
1819
RepositoryURL: "github.com/mouuff/go-rocket-update-example",
19-
ZipName: "binaries_" + runtime.GOOS + ".zip",
20+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
2021
},
21-
ExecutableName: "go-rocket-update-example",
22+
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
2223
Version: "v0.0.0",
2324
}
2425

examples/github-rollback/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ func main() {
6363
u := &updater.Updater{
6464
Provider: &provider.Github{
6565
RepositoryURL: "github.com/mouuff/go-rocket-update-example",
66-
ZipName: "binaries_" + runtime.GOOS + ".zip",
66+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
6767
},
68-
ExecutableName: "go-rocket-update-example",
68+
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
6969
Version: "v0.0.0",
7070
}
7171

examples/github-simple/main.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"runtime"
67

@@ -13,9 +14,9 @@ func main() {
1314
u := &updater.Updater{
1415
Provider: &provider.Github{
1516
RepositoryURL: "github.com/mouuff/go-rocket-update-example",
16-
ZipName: "binaries_" + runtime.GOOS + ".zip",
17+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1718
},
18-
ExecutableName: "go-rocket-update-example",
19+
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
1920
Version: "v0.0.0",
2021
}
2122

examples/gitlab-simple/main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"fmt"
45
"log"
56
"runtime"
67

@@ -9,13 +10,14 @@ import (
910
)
1011

1112
func main() {
13+
1214
// Example project here: https://gitlab.com/arnaudalies.py/go-rocket-update-example
1315
u := &updater.Updater{
1416
Provider: &provider.Gitlab{
1517
ProjectID: 24021648,
16-
ZipName: "binaries_" + runtime.GOOS + ".zip",
18+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1719
},
18-
ExecutableName: "go-rocket-update-example",
20+
ExecutableName: fmt.Sprintf("go-rocket-update-example_%s_%s", runtime.GOOS, runtime.GOARCH),
1921
Version: "v0.0.0",
2022
}
2123

pkg/provider/provider_github_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider_test
22

33
import (
4+
"fmt"
45
"runtime"
56
"testing"
67

@@ -10,7 +11,7 @@ import (
1011
func TestProviderGithub(t *testing.T) {
1112
p := &provider.Github{
1213
RepositoryURL: "github.com/mouuff/go-rocket-update-example",
13-
ZipName: "binaries_" + runtime.GOOS + ".zip",
14+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1415
}
1516
if err := p.Open(); err != nil {
1617
t.Fatal(err)

pkg/provider/provider_gitlab_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package provider_test
22

33
import (
4+
"fmt"
45
"runtime"
56
"testing"
67

@@ -10,7 +11,7 @@ import (
1011
func TestProviderGitlab(t *testing.T) {
1112
p := &provider.Gitlab{
1213
ProjectID: 24021648,
13-
ZipName: "binaries_" + runtime.GOOS + ".zip",
14+
ZipName: fmt.Sprintf("binaries_%s.zip", runtime.GOOS),
1415
}
1516

1617
if err := p.Open(); err != nil {

pkg/updater/updater.go

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package updater
33
import (
44
"os"
55
"path/filepath"
6-
"runtime"
76
"strings"
87

98
"github.com/mouuff/go-rocket-update/internal/fileio"
@@ -47,16 +46,11 @@ func (u *Updater) getExecutablePatcher(executableCandidatePath string) (*fileio.
4746
}, nil
4847
}
4948

50-
// getExecutableName gets the name used to find the right executable path
51-
func (u *Updater) getExecutableName() string {
52-
return u.ExecutableName + "_" + runtime.GOOS + "_" + runtime.GOARCH
53-
}
54-
5549
// findExecutableRemotePath finds the remote executable path using the provider
5650
func (u *Updater) findExecutableRemotePath() (string, error) {
5751
executableRemotePath := ""
5852
err := u.Provider.Walk(func(info *provider.FileInfo) error {
59-
if info.Mode.IsRegular() && strings.Contains(filepath.Base(info.Path), u.getExecutableName()) {
53+
if info.Mode.IsRegular() && strings.Contains(filepath.Base(info.Path), u.ExecutableName) {
6054
executableRemotePath = info.Path
6155
}
6256
return nil

0 commit comments

Comments
 (0)