diff --git a/CHANGELOG.md b/CHANGELOG.md index 1f6045d..afa8142 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,7 +15,7 @@ - New Feature: Filtering releases by matching regular expressions to release names (Thanks to [@fredbi](https://github.com/fredbi)). Regular expression strings specified at `Filters` field in `Config` struct are used on detecting the - latest release. Please read [documentation](https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate#Config) + latest release. Please read [documentation](https://godoc.org/github.com/MedzikUser/go-github-selfupdate/selfupdate#Config) for more details. - Allow `{cmd}_{os}_{arch}` format for executable names. - `.tgz` file name suffix was supported. @@ -24,7 +24,7 @@ ## [v1.1.0] - 2018-11-10 - New Feature: Signature validation for release assets (Thanks to [@tobiaskohlbau](https://github.com/tobiaskohlbau)). - Please read [the instruction](https://github.com/rhysd/go-github-selfupdate#hash-or-signature-validation) for usage. + Please read [the instruction](https://github.com/MedzikUser/go-github-selfupdate#hash-or-signature-validation) for usage. ## [v1.0.0] - 2018-09-23 @@ -32,9 +32,9 @@ First release! :tada: -[v1.2.3]: https://github.com/rhysd/go-github-selfupdate/compare/v1.2.2...v1.2.3 -[v1.2.2]: https://github.com/rhysd/go-github-selfupdate/compare/v1.2.1...v1.2.2 -[v1.2.1]: https://github.com/rhysd/go-github-selfupdate/compare/v1.2.0...v1.2.1 -[v1.2.0]: https://github.com/rhysd/go-github-selfupdate/compare/go-get-release...v1.2.0 -[v1.1.0]: https://github.com/rhysd/go-github-selfupdate/compare/v1.0.0...v1.1.0 -[v1.0.0]: https://github.com/rhysd/go-github-selfupdate/compare/example-1.2.4...v1.0.0 +[v1.2.3]: https://github.com/MedzikUser/go-github-selfupdate/compare/v1.2.2...v1.2.3 +[v1.2.2]: https://github.com/MedzikUser/go-github-selfupdate/compare/v1.2.1...v1.2.2 +[v1.2.1]: https://github.com/MedzikUser/go-github-selfupdate/compare/v1.2.0...v1.2.1 +[v1.2.0]: https://github.com/MedzikUser/go-github-selfupdate/compare/go-get-release...v1.2.0 +[v1.1.0]: https://github.com/MedzikUser/go-github-selfupdate/compare/v1.0.0...v1.1.0 +[v1.0.0]: https://github.com/MedzikUser/go-github-selfupdate/compare/example-1.2.4...v1.0.0 diff --git a/LICENSE b/LICENSE index 540fd4e..4c63a60 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ the MIT License -Copyright (c) 2017 rhysd +Copyright (c) 2017 MedzikUser Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 5daa089..adb3346 100644 --- a/README.md +++ b/README.md @@ -36,9 +36,9 @@ And small wrapper CLIs are provided: - [detect-latest-release](./cmd/detect-latest-release): Detect the latest release of given GitHub repository from command line - [go-get-release](./cmd/go-get-release): Like `go get`, but install a release binary from GitHub instead -[Slide at GoCon 2018 Spring (Japanese)](https://speakerdeck.com/rhysd/go-selfupdate-github-de-turuwozi-ji-atupudetosuru) +[Slide at GoCon 2018 Spring (Japanese)](https://speakerdeck.com/MedzikUser/go-selfupdate-github-de-turuwozi-ji-atupudetosuru) -[go-github-selfupdate]: https://github.com/rhysd/go-github-selfupdate +[go-github-selfupdate]: https://github.com/MedzikUser/go-github-selfupdate [GitHub Releases API]: https://developer.github.com/v3/repos/releases/ @@ -50,7 +50,7 @@ Example to understand what this library does is prepared as [CLI](./cmd/selfupda Install it at first. ``` -$ go get -u github.com/rhysd/go-github-selfupdate/cmd/selfupdate-example +$ go get -u github.com/MedzikUser/go-github-selfupdate/cmd/selfupdate-example ``` And check the version by `-version`. `-help` flag is also available to know all flags. @@ -76,9 +76,9 @@ So running `-selfupdate` again only shows 'Current binary is the latest version' Following tools are using this library. -- [dot-github](https://github.com/rhysd/dot-github) -- [dotfiles](https://github.com/rhysd/dotfiles) -- [github-clone-all](https://github.com/rhysd/github-clone-all) +- [dot-github](https://github.com/MedzikUser/dot-github) +- [dotfiles](https://github.com/MedzikUser/dotfiles) +- [github-clone-all](https://github.com/MedzikUser/github-clone-all) - [pythonbrew](https://github.com/utahta/pythonbrew) - [akashic](https://github.com/cowlick/akashic) - [butler](https://github.com/netzkern/butler) @@ -106,7 +106,7 @@ Following is the easiest way to use this package. import ( "log" "github.com/blang/semver" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" ) const version = "1.2.3" @@ -134,7 +134,7 @@ Following asks user to update or not. import ( "bufio" "github.com/blang/semver" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" "log" "os" ) @@ -196,7 +196,7 @@ Following is an example of usage with GitHub Enterprise. import ( "log" "github.com/blang/semver" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" ) const version = "1.2.3" @@ -433,12 +433,12 @@ tj/go-update: Distributed under the [MIT License](LICENSE) -[GoDoc Badge]: https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate?status.svg -[GoDoc]: https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate -[TravisCI Status]: https://travis-ci.org/rhysd/go-github-selfupdate.svg?branch=master -[TravisCI]: https://travis-ci.org/rhysd/go-github-selfupdate +[GoDoc Badge]: https://godoc.org/github.com/MedzikUser/go-github-selfupdate/selfupdate?status.svg +[GoDoc]: https://godoc.org/github.com/MedzikUser/go-github-selfupdate/selfupdate +[TravisCI Status]: https://travis-ci.org/MedzikUser/go-github-selfupdate.svg?branch=master +[TravisCI]: https://travis-ci.org/MedzikUser/go-github-selfupdate [AppVeyor Status]: https://ci.appveyor.com/api/projects/status/1tpyd9q9tw3ime5u/branch/master?svg=true -[AppVeyor]: https://ci.appveyor.com/project/rhysd/go-github-selfupdate/branch/master -[Codecov Status]: https://codecov.io/gh/rhysd/go-github-selfupdate/branch/master/graph/badge.svg -[Codecov]: https://codecov.io/gh/rhysd/go-github-selfupdate +[AppVeyor]: https://ci.appveyor.com/project/MedzikUser/go-github-selfupdate/branch/master +[Codecov Status]: https://codecov.io/gh/MedzikUser/go-github-selfupdate/branch/master/graph/badge.svg +[Codecov]: https://codecov.io/gh/MedzikUser/go-github-selfupdate [GitHub Enterprise]: https://enterprise.github.com/home diff --git a/cmd/detect-latest-release/README.md b/cmd/detect-latest-release/README.md index 86773b1..8afbd8f 100644 --- a/cmd/detect-latest-release/README.md +++ b/cmd/detect-latest-release/README.md @@ -1,9 +1,9 @@ -This command line tool is a small wrapper of [`selfupdate.DetectLatest()`](https://godoc.org/github.com/rhysd/go-github-selfupdate/selfupdate#DetectLatest). +This command line tool is a small wrapper of [`selfupdate.DetectLatest()`](https://godoc.org/github.com/MedzikUser/go-github-selfupdate/selfupdate#DetectLatest). Please install using `go get`. ``` -$ go get -u github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release +$ go get -u github.com/MedzikUser/go-github-selfupdate/cmd/detect-latest-release ``` To know the usage, please try the command without any argument. @@ -12,9 +12,9 @@ To know the usage, please try the command without any argument. $ detect-latest-release ``` -For example, following shows the latest version of [github-clone-all](https://github.com/rhysd/github-clone-all). +For example, following shows the latest version of [github-clone-all](https://github.com/MedzikUser/github-clone-all). ``` -$ detect-latest-release rhysd/github-clone-all +$ detect-latest-release MedzikUser/github-clone-all ``` diff --git a/cmd/detect-latest-release/main.go b/cmd/detect-latest-release/main.go index bf8de19..91183f4 100644 --- a/cmd/detect-latest-release/main.go +++ b/cmd/detect-latest-release/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" "os" "regexp" "strings" diff --git a/cmd/go-get-release/README.md b/cmd/go-get-release/README.md index 42b36e3..c5c1a3b 100644 --- a/cmd/go-get-release/README.md +++ b/cmd/go-get-release/README.md @@ -1,10 +1,10 @@ Like `go get`, but it downloads and installs the latest release binary from GitHub instead. -Please download a binary from [release page](https://github.com/rhysd/go-github-selfupdate/releases/tag/go-get-release) +Please download a binary from [release page](https://github.com/MedzikUser/go-github-selfupdate/releases/tag/go-get-release) and put it in `$PATH` or build from source with `go get`. ``` -$ go get -u github.com/rhysd/go-github-selfupdate/cmd/go-get-release +$ go get -u github.com/MedzikUser/go-github-selfupdate/cmd/go-get-release ``` Usage is quite similar to `go get`. But `{package}` must be hosted on GitHub. So it needs to start with `github.com/`. diff --git a/cmd/go-get-release/main.go b/cmd/go-get-release/main.go index 729d73f..d95e249 100644 --- a/cmd/go-get-release/main.go +++ b/cmd/go-get-release/main.go @@ -3,7 +3,7 @@ package main import ( "flag" "fmt" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" "go/build" "io" "net/http" @@ -28,7 +28,7 @@ func getCommand(pkg string) string { _, cmd := filepath.Split(pkg) if cmd == "" { // When pkg path is ending with path separator, we need to split it out. - // i.e. github.com/rhysd/foo/cmd/bar/ + // i.e. github.com/MedzikUser/foo/cmd/bar/ _, cmd = filepath.Split(cmd) } return cmd @@ -118,7 +118,7 @@ func main() { os.Exit(1) } } else { - if err := selfupdate.UpdateTo(latest.AssetURL, cmdPath, "" /* TODO */); err != nil { + if err := selfupdate.UpdateTo(latest.AssetURL, cmdPath); err != nil { fmt.Fprintf(os.Stderr, "Error while replacing the binary with %s: %s\n", latest.AssetURL, err) os.Exit(1) } diff --git a/cmd/selfupdate-example/main.go b/cmd/selfupdate-example/main.go index 4fa3d4e..11a9a41 100644 --- a/cmd/selfupdate-example/main.go +++ b/cmd/selfupdate-example/main.go @@ -4,7 +4,7 @@ import ( "flag" "fmt" "github.com/blang/semver" - "github.com/rhysd/go-github-selfupdate/selfupdate" + "github.com/MedzikUser/go-github-selfupdate/selfupdate" "os" ) @@ -37,7 +37,7 @@ func main() { help := flag.Bool("help", false, "Show this help") ver := flag.Bool("version", false, "Show version") update := flag.Bool("selfupdate", false, "Try go-github-selfupdate via GitHub") - slug := flag.String("slug", "rhysd/go-github-selfupdate", "Repository of this command") + slug := flag.String("slug", "MedzikUser/go-github-selfupdate", "Repository of this command") flag.Usage = usage flag.Parse() diff --git a/go.sum b/go.sum index 60474c5..3512262 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,7 @@ github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdn github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk= github.com/fsnotify/fsnotify v1.4.7 h1:IXs+QLmnXW2CcXuY+8Mzv/fWEsPGWxqefPtCP5CnV9I= github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/golang/protobuf v1.2.0 h1:P3YflyNX/ehuJFLhxviNdFxQPkGK5cDcApsge1SqnvM= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2 h1:6nsPYzhq5kReh6QImI3k5qWzO4PEbvbIW2cwSfR/6xs= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -26,11 +27,13 @@ github.com/tcnksm/go-gitconfig v0.1.2 h1:iiDhRitByXAEyjgBqsKi9QU4o2TNtv9kPP3RgPg github.com/tcnksm/go-gitconfig v0.1.2/go.mod h1:/8EhP4H7oJZdIPyT+/UIsG87kTzrzM4UsLGSItWYCpE= github.com/ulikunitz/xz v0.5.9 h1:RsKRIA2MO8x56wkkcd3LbtcE/uMszhb6DpRf+3uwa3I= github.com/ulikunitz/xz v0.5.9/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2 h1:VklqNMn3ovrHsnt90PveolxSbWFaJdECFbxSq0Mqo2M= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad h1:DN0cp81fZ3njFcrLCytUHRSUkqBjfTo4Tx9RJTWs0EY= golang.org/x/crypto v0.0.0-20201221181555-eec23a3978ad/go.mod h1:jdWPYTVW3xRLrWPugEBEK3UY2ZEsg3UU495nc5E+M+I= golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628= golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3 h1:0GoQqolDA55aaLxZyTzK/Y2ePZzZTUrRacwib7cNsYQ= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= @@ -39,10 +42,12 @@ golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288 h1:JIqe8uIcRBHXDQVvZtHwp8 golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4= golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= +golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.5 h1:i6eZZ+zk0SOf0xgBpEpPD18qWcJda6q1sxt3S0kzyUQ= golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/renovate.json b/renovate.json deleted file mode 100644 index ea822ea..0000000 --- a/renovate.json +++ /dev/null @@ -1,20 +0,0 @@ -{ - "extends": [ - "config:base" - ], - "includeForks": true, - "prHourlyLimit": 0, - "automergeType": "pr", - "prCreation": "immediate", - "packageRules": [ - { - "matchUpdateTypes": [ - "minor", - "patch", - "pin", - "digest" - ], - "automerge": true - } - ] -} diff --git a/selfupdate/detect.go b/selfupdate/detect.go index 6ca1af7..30c6113 100644 --- a/selfupdate/detect.go +++ b/selfupdate/detect.go @@ -109,7 +109,7 @@ func findReleaseAndAsset(rels []*github.RepositoryRelease, // Find the latest version from the list of releases. // Returned list from GitHub API is in the order of the date when created. - // ref: https://github.com/rhysd/go-github-selfupdate/issues/11 + // ref: https://github.com/MedzikUser/go-github-selfupdate/issues/11 for _, rel := range rels { if a, v, ok := findAssetFromRelease(rel, suffixes, targetVersion, filters); ok { // Note: any version with suffix is less than any version without suffix. diff --git a/selfupdate/detect_test.go b/selfupdate/detect_test.go index d64fe65..2bfc753 100644 --- a/selfupdate/detect_test.go +++ b/selfupdate/detect_test.go @@ -12,7 +12,7 @@ import ( ) func TestDetectReleaseWithVersionPrefix(t *testing.T) { - r, ok, err := DetectLatest("rhysd/github-clone-all") + r, ok, err := DetectLatest("MedzikUser/github-clone-all") if err != nil { t.Fatal("Fetch failed:", err) } @@ -46,7 +46,7 @@ func TestDetectReleaseWithVersionPrefix(t *testing.T) { if r.PublishedAt.IsZero() { t.Error("Release time is unexpectedly zero") } - if r.RepoOwner != "rhysd" { + if r.RepoOwner != "MedzikUser" { t.Error("Repo owner is not correct:", r.RepoOwner) } if r.RepoName != "github-clone-all" { @@ -56,7 +56,7 @@ func TestDetectReleaseWithVersionPrefix(t *testing.T) { func TestDetectVersionExisting(t *testing.T) { testVersion := "v2.2.0" - r, ok, err := DetectVersion("rhysd/github-clone-all", testVersion) + r, ok, err := DetectVersion("MedzikUser/github-clone-all", testVersion) if err != nil { t.Fatal("Fetch failed:", err) } @@ -69,7 +69,7 @@ func TestDetectVersionExisting(t *testing.T) { } func TestDetectVersionNotExisting(t *testing.T) { - r, ok, err := DetectVersion("rhysd/github-clone-all", "foobar") + r, ok, err := DetectVersion("MedzikUser/github-clone-all", "foobar") if err != nil { t.Fatal("Fetch failed:", err) } @@ -86,11 +86,11 @@ func TestDetectReleasesForVariousArchives(t *testing.T) { slug string prefix string }{ - {"rhysd-test/test-release-zip", "v"}, - {"rhysd-test/test-release-tar", "v"}, - {"rhysd-test/test-release-gzip", "v"}, - {"rhysd-test/test-release-xz", "release-v"}, - {"rhysd-test/test-release-tar-xz", "release-"}, + {"MedzikUser-test/test-release-zip", "v"}, + {"MedzikUser-test/test-release-tar", "v"}, + {"MedzikUser-test/test-release-gzip", "v"}, + {"MedzikUser-test/test-release-xz", "release-v"}, + {"MedzikUser-test/test-release-tar-xz", "release-"}, } { t.Run(tc.slug, func(t *testing.T) { r, ok, err := DetectLatest(tc.slug) @@ -128,8 +128,8 @@ func TestDetectReleasesForVariousArchives(t *testing.T) { if r.PublishedAt.IsZero() { t.Error("Release time is unexpectedly zero") } - if r.RepoOwner != "rhysd-test" { - t.Error("Repo owner should be rhysd-test:", r.RepoOwner) + if r.RepoOwner != "MedzikUser-test" { + t.Error("Repo owner should be MedzikUser-test:", r.RepoOwner) } if !strings.HasPrefix(r.RepoName, "test-release-") { t.Error("Repo name was not properly detectd:", r.RepoName) @@ -139,7 +139,7 @@ func TestDetectReleasesForVariousArchives(t *testing.T) { } func TestDetectReleaseButNoAsset(t *testing.T) { - _, ok, err := DetectLatest("rhysd/clever-f.vim") + _, ok, err := DetectLatest("MedzikUser/clever-f.vim") if err != nil { t.Fatal("Fetch failed:", err) } @@ -149,7 +149,7 @@ func TestDetectReleaseButNoAsset(t *testing.T) { } func TestDetectNoRelease(t *testing.T) { - _, ok, err := DetectLatest("rhysd/clever-f.vim") + _, ok, err := DetectLatest("MedzikUser/clever-f.vim") if err != nil { t.Fatal("Fetch failed:", err) } @@ -179,7 +179,7 @@ func TestInvalidSlug(t *testing.T) { } func TestNonExistingRepo(t *testing.T) { - v, ok, err := DetectLatest("rhysd/non-existing-repo") + v, ok, err := DetectLatest("MedzikUser/non-existing-repo") if err != nil { t.Fatal("Non-existing repo should not cause an error:", v) } @@ -189,7 +189,7 @@ func TestNonExistingRepo(t *testing.T) { } func TestNoReleaseFound(t *testing.T) { - _, ok, err := DetectLatest("rhysd/misc") + _, ok, err := DetectLatest("MedzikUser/misc") if err != nil { t.Fatal("Repo having no release should not cause an error:", err) } diff --git a/selfupdate/doc.go b/selfupdate/doc.go index 38fc167..9401b89 100644 --- a/selfupdate/doc.go +++ b/selfupdate/doc.go @@ -23,16 +23,16 @@ If newer version than itself is detected, it downloads released binary from GitH There are some naming rules. Please read following links. Naming Rules of Released Binaries: - https://github.com/rhysd/go-github-selfupdate#naming-rules-of-released-binaries + https://github.com/MedzikUser/go-github-selfupdate#naming-rules-of-released-binaries Naming Rules of Git Tags: - https://github.com/rhysd/go-github-selfupdate#naming-rules-of-git-tags + https://github.com/MedzikUser/go-github-selfupdate#naming-rules-of-git-tags This package is hosted on GitHub: - https://github.com/rhysd/go-github-selfupdate + https://github.com/MedzikUser/go-github-selfupdate Small CLI tools as wrapper of this library are available also: - https://github.com/rhysd/go-github-selfupdate/cmd/detect-latest-release - https://github.com/rhysd/go-github-selfupdate/cmd/go-get-release + https://github.com/MedzikUser/go-github-selfupdate/cmd/detect-latest-release + https://github.com/MedzikUser/go-github-selfupdate/cmd/go-get-release */ package selfupdate diff --git a/selfupdate/update.go b/selfupdate/update.go index c95b4a1..0e52bcc 100644 --- a/selfupdate/update.go +++ b/selfupdate/update.go @@ -15,8 +15,13 @@ import ( "github.com/inconshreveable/go-update" ) -func uncompressAndUpdate(src io.Reader, assetURL, cmdPath, cmdName string) error { - asset, err := UncompressCommand(src, assetURL, cmdName) +func uncompressAndUpdate(src io.Reader, assetURL, cmdPath string, binaryName string) error { + if binaryName == "" { + _, binaryName = filepath.Split(cmdPath) + } else if runtime.GOOS == "windows" { + binaryName += ".exe" + } + asset, err := UncompressCommand(src, assetURL, binaryName) if err != nil { return err } @@ -54,7 +59,7 @@ func (up *Updater) downloadDirectlyFromURL(assetURL string) (io.ReadCloser, erro // UpdateTo downloads an executable from GitHub Releases API and replace current binary with the downloaded one. // It downloads a release asset via GitHub Releases API so this function is available for update releases on private repository. // If a redirect occurs, it fallbacks into directly downloading from the redirect URL. -func (up *Updater) UpdateTo(rel *Release, cmdPath, cmdName string) error { +func (up *Updater) UpdateTo(rel *Release, cmdPath string) error { var client http.Client src, redirectURL, err := up.api.Repositories.DownloadReleaseAsset(up.apiCtx, rel.RepoOwner, rel.RepoName, rel.AssetID, &client) if err != nil { @@ -75,7 +80,7 @@ func (up *Updater) UpdateTo(rel *Release, cmdPath, cmdName string) error { } if up.validator == nil { - return uncompressAndUpdate(bytes.NewReader(data), rel.AssetURL, cmdPath, cmdName) + return uncompressAndUpdate(bytes.NewReader(data), rel.AssetURL, cmdPath, up.binaryName) } validationSrc, validationRedirectURL, err := up.api.Repositories.DownloadReleaseAsset(up.apiCtx, rel.RepoOwner, rel.RepoName, rel.ValidationAssetID, &client) @@ -101,7 +106,7 @@ func (up *Updater) UpdateTo(rel *Release, cmdPath, cmdName string) error { return fmt.Errorf("Failed validating asset content: %v", err) } - return uncompressAndUpdate(bytes.NewReader(data), rel.AssetURL, cmdPath, cmdName) + return uncompressAndUpdate(bytes.NewReader(data), rel.AssetURL, cmdPath, up.binaryName) } // UpdateCommand updates a given command binary to the latest version. @@ -137,8 +142,7 @@ func (up *Updater) UpdateCommand(cmdPath string, current semver.Version, slug st return rel, nil } log.Println("Will update", cmdPath, "to the latest version", rel.Version) - _, cmdName := filepath.Split(cmdPath) - if err := up.UpdateTo(rel, cmdPath, cmdName); err != nil { + if err := up.UpdateTo(rel, cmdPath); err != nil { return nil, err } return rel, nil @@ -158,14 +162,14 @@ func (up *Updater) UpdateSelf(current semver.Version, slug string) (*Release, er // This function is low-level API to update the binary. Because it does not use GitHub API and downloads asset directly from the URL via HTTP, // this function is not available to update a release for private repositories. // cmdPath is a file path to command executable. -func UpdateTo(assetURL, cmdPath, cmdName string) error { +func UpdateTo(assetURL, cmdPath string) error { up := DefaultUpdater() src, err := up.downloadDirectlyFromURL(assetURL) if err != nil { return err } defer src.Close() - return uncompressAndUpdate(src, assetURL, cmdPath, cmdName) + return uncompressAndUpdate(src, assetURL, cmdPath, up.binaryName) } // UpdateCommand updates a given command binary to the latest version. diff --git a/selfupdate/update_test.go b/selfupdate/update_test.go index 97848db..01da244 100644 --- a/selfupdate/update_test.go +++ b/selfupdate/update_test.go @@ -11,16 +11,34 @@ import ( "github.com/blang/semver" ) -func setupTestBinary() { - if err := exec.Command("go", "build", "./testdata/github-release-test/").Run(); err != nil { +func setupTestBinary(name ...string) { + var options []string + var output string + if len(name) == 0 { + options = []string{"build", "./testdata/github-release-test/"} + } else { + output = name[0] + if runtime.GOOS == "windows" { + output += ".exe" + } + options = []string{"build", "-o", output, "./testdata/github-release-test/"} + } + + if err := exec.Command("go", options...).Run(); err != nil { panic(err) } } -func teardownTestBinary() { - bin := "github-release-test" +func teardownTestBinary(name ...string) { + var bin string + if len(name) == 0 { + bin = "github-release-test" + } else { + bin = name[0] + } + if runtime.GOOS == "windows" { - bin = "github-release-test.exe" + bin += ".exe" } if err := os.Remove(bin); err != nil { panic(err) @@ -33,12 +51,12 @@ func TestUpdateCommand(t *testing.T) { } for _, slug := range []string{ - "rhysd-test/test-release-zip", - "rhysd-test/test-release-tar", - "rhysd-test/test-release-gzip", - "rhysd-test/test-release-tar-xz", - "rhysd-test/test-release-xz", - "rhysd-test/test-release-contain-version", + "MedzikUser-test/test-release-zip", + "MedzikUser-test/test-release-tar", + "MedzikUser-test/test-release-gzip", + "MedzikUser-test/test-release-tar-xz", + "MedzikUser-test/test-release-xz", + "MedzikUser-test/test-release-contain-version", } { t.Run(slug, func(t *testing.T) { setupTestBinary() @@ -64,6 +82,41 @@ func TestUpdateCommand(t *testing.T) { } } +func TestUpdateWithDifferentBinaryName(t *testing.T) { + setupTestBinary("gh-release-test") + defer teardownTestBinary("gh-release-test") + latest := semver.MustParse("1.2.3") + prev := semver.MustParse("1.2.2") + + _, err := UpdateCommand("gh-release-test", prev, "MedzikUser-test/test-release-zip") + if err == nil { + t.Fatal("Error should occur for broken package") + } + if !strings.Contains(err.Error(), "the command is not found") { + t.Fatal("Unexpected error:", err) + } + + up, err := NewUpdater(Config{BinaryName: "github-release-test", Filters: []string{"github-release-test"}}) + if err != nil { + t.Fatal(err) + } + rel, err := up.UpdateCommand("gh-release-test", prev, "MedzikUser-test/test-release-zip") + if err != nil { + t.Fatal(err) + } + if rel.Version.NE(latest) { + t.Error("Version is not latest", rel.Version) + } + bytes, err := exec.Command(filepath.FromSlash("./gh-release-test")).Output() + if err != nil { + t.Fatal("Failed to run test binary after update:", err) + } + out := string(bytes) + if out != "v1.2.3\n" { + t.Error("Output from test binary after update is unexpected:", out) + } +} + func TestUpdateViaSymlink(t *testing.T) { if testing.Short() { t.Skip("skip tests in short mode.") @@ -87,7 +140,7 @@ func TestUpdateViaSymlink(t *testing.T) { latest := semver.MustParse("1.2.3") prev := semver.MustParse("1.2.2") - rel, err := UpdateCommand(symPath, prev, "rhysd-test/test-release-zip") + rel, err := UpdateCommand(symPath, prev, "MedzikUser-test/test-release-zip") if err != nil { t.Fatal(err) } @@ -167,7 +220,7 @@ func TestNotExistingCommandPath(t *testing.T) { func TestNoReleaseFoundForUpdate(t *testing.T) { v := semver.MustParse("1.0.0") fake := filepath.FromSlash("./testdata/fake-executable") - rel, err := UpdateCommand(fake, v, "rhysd/misc") + rel, err := UpdateCommand(fake, v, "MedzikUser/misc") if err != nil { t.Fatal("No release should not make an error:", err) } @@ -193,7 +246,7 @@ func TestCurrentIsTheLatest(t *testing.T) { defer teardownTestBinary() v := semver.MustParse("1.2.3") - rel, err := UpdateCommand("github-release-test", v, "rhysd-test/test-release-zip") + rel, err := UpdateCommand("github-release-test", v, "MedzikUser-test/test-release-zip") if err != nil { t.Fatal(err) } @@ -217,7 +270,7 @@ func TestBrokenBinaryUpdate(t *testing.T) { } fake := filepath.FromSlash("./testdata/fake-executable") - _, err := UpdateCommand(fake, semver.MustParse("1.2.2"), "rhysd-test/test-incorrect-release") + _, err := UpdateCommand(fake, semver.MustParse("1.2.2"), "MedzikUser-test/test-incorrect-release") if err == nil { t.Fatal("Error should occur for broken package") } @@ -228,7 +281,7 @@ func TestBrokenBinaryUpdate(t *testing.T) { func TestInvalidSlugForUpdate(t *testing.T) { fake := filepath.FromSlash("./testdata/fake-executable") - _, err := UpdateCommand(fake, semver.MustParse("1.0.0"), "rhysd/") + _, err := UpdateCommand(fake, semver.MustParse("1.0.0"), "MedzikUser/") if err == nil { t.Fatal("Unknown repo should cause an error") } @@ -238,7 +291,7 @@ func TestInvalidSlugForUpdate(t *testing.T) { } func TestInvalidAssetURL(t *testing.T) { - err := UpdateTo("https://github.com/rhysd/non-existing-repo/releases/download/v1.2.3/foo.zip", "foo", "bar") + err := UpdateTo("https://github.com/MedzikUser/non-existing-repo/releases/download/v1.2.3/foo.zip", "foo") if err == nil { t.Fatal("Error should occur for URL not found") } @@ -248,8 +301,8 @@ func TestInvalidAssetURL(t *testing.T) { } func TestBrokenAsset(t *testing.T) { - asset := "https://github.com/rhysd-test/test-incorrect-release/releases/download/invalid/broken-zip.zip" - err := UpdateTo(asset, "foo", "bar") + asset := "https://github.com/MedzikUser-test/test-incorrect-release/releases/download/invalid/broken-zip.zip" + err := UpdateTo(asset, "foo") if err == nil { t.Fatal("Error should occur for URL not found") } @@ -263,7 +316,7 @@ func TestBrokenGitHubEnterpriseURL(t *testing.T) { if err != nil { t.Fatal(err) } - err = up.UpdateTo(&Release{AssetURL: "https://example.com"}, "foo", "") + err = up.UpdateTo(&Release{AssetURL: "https://example.com"}, "foo") if err == nil { t.Fatal("Invalid GitHub Enterprise base URL should raise an error") } @@ -332,7 +385,7 @@ func TestUpdateFromGitHubPrivateRepo(t *testing.T) { latest := semver.MustParse("1.2.3") prev := semver.MustParse("1.2.2") - rel, err := up.UpdateCommand("github-release-test", prev, "rhysd/private-release-test") + rel, err := up.UpdateCommand("github-release-test", prev, "MedzikUser/private-release-test") if err != nil { t.Fatal(err) } diff --git a/selfupdate/updater.go b/selfupdate/updater.go index 32cf5e0..15296ab 100644 --- a/selfupdate/updater.go +++ b/selfupdate/updater.go @@ -15,10 +15,11 @@ import ( // Updater is responsible for managing the context of self-update. // It contains GitHub client and its context. type Updater struct { - api *github.Client - apiCtx context.Context - validator Validator - filters []*regexp.Regexp + api *github.Client + apiCtx context.Context + validator Validator + filters []*regexp.Regexp + binaryName string } // Config represents the configuration of self-update. @@ -37,6 +38,10 @@ type Config struct { // An asset is selected if it matches any of those, in addition to the regular tag, os, arch, extensions. // Please make sure that your filter(s) uniquely match an asset. Filters []string + + // BinaryName represents the name of the binary extracted from the archive downloaded from GitHub. + // If unset, the current executable's name will be used to match. + BinaryName string } func newHTTPClient(ctx context.Context, token string) *http.Client { @@ -71,7 +76,7 @@ func NewUpdater(config Config) (*Updater, error) { if config.EnterpriseBaseURL == "" { client := github.NewClient(hc) - return &Updater{api: client, apiCtx: ctx, validator: config.Validator, filters: filtersRe}, nil + return &Updater{api: client, apiCtx: ctx, validator: config.Validator, filters: filtersRe, binaryName: config.BinaryName}, nil } u := config.EnterpriseUploadURL @@ -82,7 +87,8 @@ func NewUpdater(config Config) (*Updater, error) { if err != nil { return nil, err } - return &Updater{api: client, apiCtx: ctx, validator: config.Validator, filters: filtersRe}, nil + + return &Updater{api: client, apiCtx: ctx, validator: config.Validator, filters: filtersRe, binaryName: config.BinaryName}, nil } // DefaultUpdater creates a new updater instance with default configuration.