Compare commits
12 Commits
13766db3e1
...
5aea9fd5f3
Author | SHA1 | Date |
---|---|---|
Oskar | 5aea9fd5f3 | |
MedzikUser | e33f9e522e | |
MedzikUser | 542dc5db61 | |
MedzikUser | 4b201b07f5 | |
MedzikUser | c9e5fe26ca | |
MedzikUser | e8ecb189e5 | |
MedzikUser | a75b2492cb | |
MedzikUser | 8a2cf5e596 | |
Oskar | ec571e8c14 | |
MedzikUser | 9c76d66885 | |
MedzikUser | 9abefd0460 | |
Oskar | 8ab4b94ea1 |
|
@ -0,0 +1,26 @@
|
|||
name: Go
|
||||
|
||||
on:
|
||||
push:
|
||||
|
||||
pull_request:
|
||||
|
||||
jobs:
|
||||
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
- name: Set up Go
|
||||
uses: actions/setup-go@v2
|
||||
with:
|
||||
go-version: 1.17
|
||||
|
||||
- run: find . -type f -exec sed -i 's,MedzikUser/go-github-selfupdate,rhysd/go-github-selfupdate,g' {} +
|
||||
|
||||
- name: Build
|
||||
run: go build -v ./...
|
||||
|
||||
- name: Test
|
||||
run: go test -v ./...
|
16
CHANGELOG.md
16
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
|
||||
|
|
24
README.md
24
README.md
|
@ -38,7 +38,7 @@ And small wrapper CLIs are provided:
|
|||
|
||||
[Slide at GoCon 2018 Spring (Japanese)](https://speakerdeck.com/rhysd/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.
|
||||
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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/`.
|
||||
|
|
|
@ -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"
|
||||
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
|
5
go.sum
5
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=
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
{
|
||||
"extends": [
|
||||
"config:base"
|
||||
],
|
||||
"automergeType": "pr",
|
||||
"prCreation": "immediate",
|
||||
"packageRules": [
|
||||
{
|
||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
||||
"automerge": true
|
||||
}
|
||||
]
|
||||
}
|
|
@ -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.
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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)
|
||||
|
@ -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, "rhysd-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, "rhysd-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.")
|
||||
|
@ -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/rhysd/non-existing-repo/releases/download/v1.2.3/foo.zip", "foo")
|
||||
if err == nil {
|
||||
t.Fatal("Error should occur for URL not found")
|
||||
}
|
||||
|
@ -249,7 +302,7 @@ 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")
|
||||
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")
|
||||
}
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue