Skip to content

Commit d1a3784

Browse files
upgrade packages & fix lint issues
1 parent e15540b commit d1a3784

File tree

12 files changed

+76
-52
lines changed

12 files changed

+76
-52
lines changed

.golangci.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,8 @@ linters:
2020
- unconvert
2121
- unparam
2222
- usestdlibvars
23+
24+
linters-settings:
25+
gosec:
26+
excludes:
27+
- G101 # Potential hardcoded credentials

cmd/detect-latest-release/update.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
)
1111

1212
// keep this function here, this is the example from the README
13+
//
14+
//nolint:unused
1315
func update(version string) error {
1416
latest, found, err := selfupdate.DetectLatest(context.Background(), selfupdate.ParseSlug("creativeprojects/resticprofile"))
1517
if err != nil {

cmd/get-release/main.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,15 @@ func main() {
5454
os.Exit(1)
5555
}
5656

57+
ctx := context.Background()
5758
updater, err := selfupdate.NewUpdater(selfupdate.Config{
5859
Source: source,
5960
})
6061
if err != nil {
6162
fmt.Fprintln(os.Stderr, err)
6263
os.Exit(1)
6364
}
64-
latest, found, err := updater.DetectLatest(context.Background(), selfupdate.ParseSlug(slug))
65+
latest, found, err := updater.DetectLatest(ctx, selfupdate.ParseSlug(slug))
6566
if err != nil {
6667
fmt.Fprintln(os.Stderr, "Error while detecting the latest version:", err)
6768
os.Exit(1)
@@ -75,12 +76,12 @@ func main() {
7576
cmdPath := filepath.Join(build.Default.GOPATH, "bin", cmd)
7677
if _, err := os.Stat(cmdPath); err != nil {
7778
// When executable is not existing yet
78-
if err := installFrom(latest.AssetURL, cmd, cmdPath); err != nil {
79+
if err := installFrom(ctx, latest.AssetURL, cmd, cmdPath); err != nil {
7980
fmt.Fprintf(os.Stderr, "Error while installing the release binary from %s: %s\n", latest.AssetURL, err)
8081
os.Exit(1)
8182
}
8283
} else {
83-
if err := updater.UpdateTo(context.Background(), latest, cmdPath); err != nil {
84+
if err := updater.UpdateTo(ctx, latest, cmdPath); err != nil {
8485
fmt.Fprintf(os.Stderr, "Error while replacing the binary with %s: %s\n", latest.AssetURL, err)
8586
os.Exit(1)
8687
}
@@ -105,20 +106,22 @@ Flags:`)
105106
}
106107

107108
func getCommand(pkg string) string {
108-
if strings.HasSuffix(pkg, "/") {
109-
pkg = strings.TrimSuffix(pkg, "/")
110-
}
109+
pkg = strings.TrimSuffix(pkg, "/")
111110
_, cmd := filepath.Split(pkg)
112111
return cmd
113112
}
114113

115-
func installFrom(url, cmd, path string) error {
116-
res, err := http.Get(url)
114+
func installFrom(ctx context.Context, url, cmd, path string) error {
115+
req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, http.NoBody)
116+
if err != nil {
117+
return fmt.Errorf("failed to create request to download release binary from %s: %s", url, err)
118+
}
119+
res, err := http.DefaultClient.Do(req)
117120
if err != nil {
118121
return fmt.Errorf("failed to download release binary from %s: %s", url, err)
119122
}
120123
defer res.Body.Close()
121-
if res.StatusCode != 200 {
124+
if res.StatusCode != http.StatusOK {
122125
return fmt.Errorf("failed to download release binary from %s: Invalid response ", url)
123126
}
124127
executable, err := selfupdate.DecompressCommand(res.Body, url, cmd, runtime.GOOS, runtime.GOARCH)

gitea_source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ func (s *GiteaSource) ListReleases(ctx context.Context, repository Repository) (
6868
s.api.SetContext(ctx)
6969
rels, res, err := s.api.ListReleases(owner, repo, gitea.ListReleasesOptions{})
7070
if err != nil {
71-
if res != nil && res.StatusCode == 404 {
72-
// 404 means repository not found or release not found. It's not an error here.
71+
if res != nil && res.StatusCode == http.StatusNotFound {
72+
// repository not found or release not found. It's not an error here.
7373
log.Print("Repository or release not found")
7474
return nil, nil
7575
}

github_source.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ func (s *GitHubSource) ListReleases(ctx context.Context, repository Repository)
7272
}
7373
rels, res, err := s.api.Repositories.ListReleases(ctx, owner, repo, nil)
7474
if err != nil {
75-
if res != nil && res.StatusCode == 404 {
76-
// 404 means repository not found or release not found. It's not an error here.
75+
if res != nil && res.StatusCode == http.StatusNotFound {
76+
// repository not found or release not found. It's not an error here.
7777
log.Print("Repository or release not found")
7878
return nil, nil
7979
}

go.mod

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
module github.com/creativeprojects/go-selfupdate
22

3-
go 1.18
3+
go 1.21
44

55
require (
6-
code.gitea.io/sdk/gitea v0.18.0
7-
github.com/Masterminds/semver/v3 v3.2.1
6+
code.gitea.io/sdk/gitea v0.19.0
7+
github.com/Masterminds/semver/v3 v3.3.0
88
github.com/google/go-github/v30 v30.1.0
99
github.com/stretchr/testify v1.9.0
1010
github.com/ulikunitz/xz v0.5.12
11-
github.com/xanzy/go-gitlab v0.106.0
12-
golang.org/x/crypto v0.24.0
13-
golang.org/x/oauth2 v0.21.0
11+
github.com/xanzy/go-gitlab v0.112.0
12+
golang.org/x/crypto v0.28.0
13+
golang.org/x/oauth2 v0.23.0
14+
gopkg.in/yaml.v3 v3.0.1
1415
)
1516

1617
require (
@@ -22,7 +23,6 @@ require (
2223
github.com/hashicorp/go-retryablehttp v0.7.7 // indirect
2324
github.com/hashicorp/go-version v1.7.0 // indirect
2425
github.com/pmezard/go-difflib v1.0.0 // indirect
25-
golang.org/x/sys v0.21.0 // indirect
26-
golang.org/x/time v0.5.0 // indirect
27-
gopkg.in/yaml.v3 v3.0.1 // indirect
26+
golang.org/x/sys v0.26.0 // indirect
27+
golang.org/x/time v0.7.0 // indirect
2828
)

go.sum

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1-
code.gitea.io/sdk/gitea v0.18.0 h1:+zZrwVmujIrgobt6wVBWCqITz6bn1aBjnCUHmpZrerI=
2-
code.gitea.io/sdk/gitea v0.18.0/go.mod h1:IG9xZJoltDNeDSW0qiF2Vqx5orMWa7OhVWrjvrd5NpI=
3-
github.com/Masterminds/semver/v3 v3.2.1 h1:RN9w6+7QoMeJVGyfmbcgs28Br8cvmnucEXnY0rYXWg0=
4-
github.com/Masterminds/semver/v3 v3.2.1/go.mod h1:qvl/7zhW3nngYb5+80sSMF+FG2BjYrf8m9wsX0PNOMQ=
1+
code.gitea.io/sdk/gitea v0.19.0 h1:8I6s1s4RHgzxiPHhOQdgim1RWIRcr0LVMbHBjBFXq4Y=
2+
code.gitea.io/sdk/gitea v0.19.0/go.mod h1:IG9xZJoltDNeDSW0qiF2Vqx5orMWa7OhVWrjvrd5NpI=
3+
github.com/Masterminds/semver/v3 v3.3.0 h1:B8LGeaivUe71a5qox1ICM/JLl0NqZSW5CHyL+hmvYS0=
4+
github.com/Masterminds/semver/v3 v3.3.0/go.mod h1:4V+yj/TJE1HU9XfppCwVMZq3I84lprf4nC11bSS5beM=
55
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
66
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
77
github.com/davidmz/go-pageant v1.0.2 h1:bPblRCh5jGU+Uptpz6LgMZGD5hJoOt7otgT454WvHn0=
88
github.com/davidmz/go-pageant v1.0.2/go.mod h1:P2EDDnMqIwG5Rrp05dTRITj9z2zpGcD9efWSkTNKLIE=
99
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
10+
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
1011
github.com/go-fed/httpsig v1.1.0 h1:9M+hb0jkEICD8/cAiNqEB66R87tTINszBRTjwjQzWcI=
1112
github.com/go-fed/httpsig v1.1.0/go.mod h1:RCMrTZvN1bJYtofsG4rd5NaO5obxQ5xBkdiS7xsT7bM=
1213
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
1314
github.com/google/go-cmp v0.5.2/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
1415
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
16+
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
1517
github.com/google/go-github/v30 v30.1.0 h1:VLDx+UolQICEOKu2m4uAoMti1SxuEBAl7RSEG16L+Oo=
1618
github.com/google/go-github/v30 v30.1.0/go.mod h1:n8jBpHl45a/rlBUtRJMOG4GhNADUQFEufcolZ95JfU8=
1719
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
@@ -20,42 +22,46 @@ github.com/google/go-querystring v1.1.0/go.mod h1:Kcdr2DB4koayq7X8pmAG4sNG59So17
2022
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
2123
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
2224
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
25+
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
2326
github.com/hashicorp/go-retryablehttp v0.7.7 h1:C8hUCYzor8PIfXHa4UrZkU4VvK8o9ISHxT2Q8+VepXU=
2427
github.com/hashicorp/go-retryablehttp v0.7.7/go.mod h1:pkQpWZeYWskR+D1tR2O5OcBFOxfA7DoAO6xtkuQnHTk=
2528
github.com/hashicorp/go-version v1.7.0 h1:5tqGy27NaOTB8yJKUZELlFAS/LTKJkrmONwQKeRZfjY=
2629
github.com/hashicorp/go-version v1.7.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA=
2730
github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
31+
github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
2832
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
33+
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
2934
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
3035
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
3136
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
3237
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
3338
github.com/ulikunitz/xz v0.5.12 h1:37Nm15o69RwBkXM0J6A5OlE67RZTfzUxTj8fB3dfcsc=
3439
github.com/ulikunitz/xz v0.5.12/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
35-
github.com/xanzy/go-gitlab v0.106.0 h1:EDfD03K74cIlQo2EducfiupVrip+Oj02bq9ofw5F8sA=
36-
github.com/xanzy/go-gitlab v0.106.0/go.mod h1:ETg8tcj4OhrB84UEgeE8dSuV/0h4BBL1uOV/qK0vlyI=
40+
github.com/xanzy/go-gitlab v0.112.0 h1:6Z0cqEooCvBMfBIHw+CgO4AKGRV8na/9781xOb0+DKw=
41+
github.com/xanzy/go-gitlab v0.112.0/go.mod h1:wKNKh3GkYDMOsGmnfuX+ITCmDuSDWFO0G+C4AygL9RY=
3742
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
3843
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
3944
golang.org/x/crypto v0.0.0-20210513164829-c07d793c2f9a/go.mod h1:P+XmwS30IXTQdn5tA2iutPOUgjI07+tq3H3K9MVA1s8=
40-
golang.org/x/crypto v0.24.0 h1:mnl8DM0o513X8fdIkmyFE/5hTYxbwYOjDS/+rK6qpRI=
41-
golang.org/x/crypto v0.24.0/go.mod h1:Z1PMYSOR5nyMcyAVAIQSKCDwalqy85Aqn1x3Ws4L5DM=
45+
golang.org/x/crypto v0.28.0 h1:GBDwsMXVQi34v5CCYUm2jkJvu4cbtru2U4TN2PSyQnw=
46+
golang.org/x/crypto v0.28.0/go.mod h1:rmgy+3RHxRZMyY0jjAJShp2zgEdOqj2AO7U0pYmeQ7U=
4247
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4348
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
4449
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
4550
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
46-
golang.org/x/oauth2 v0.21.0 h1:tsimM75w1tF/uws5rbeHzIWxEqElMehnc+iW793zsZs=
47-
golang.org/x/oauth2 v0.21.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
51+
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
52+
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
4853
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
4954
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
5055
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
51-
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
52-
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
56+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
57+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5358
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
54-
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
59+
golang.org/x/term v0.25.0 h1:WtHI/ltw4NvSUig5KARz9h521QvRC8RmF/cuYqifU24=
60+
golang.org/x/term v0.25.0/go.mod h1:RPyXicDX+6vLxogjjRxjgD2TKtmAO6NZBsBRfrOLu7M=
5561
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
5662
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
57-
golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk=
58-
golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
63+
golang.org/x/time v0.7.0 h1:ntUhktv3OPE6TgYxXWv9vKvUSJyIFJlyohwbkEwPrKQ=
64+
golang.org/x/time v0.7.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM=
5965
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
6066
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
6167
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=

package.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@ import (
1010
// DetectLatest detects the latest release from the repository.
1111
// This function is a shortcut version of updater.DetectLatest with the DefaultUpdater.
1212
func DetectLatest(ctx context.Context, repository Repository) (*Release, bool, error) {
13+
//nolint:contextcheck
1314
return DefaultUpdater().DetectLatest(ctx, repository)
1415
}
1516

1617
// DetectVersion detects the given release from the repository.
1718
func DetectVersion(ctx context.Context, repository Repository, version string) (*Release, bool, error) {
19+
//nolint:contextcheck
1820
return DefaultUpdater().DetectVersion(ctx, repository, version)
1921
}
2022

@@ -23,6 +25,7 @@ func DetectVersion(ctx context.Context, repository Repository, version string) (
2325
// this function is not available to update a release for private repositories.
2426
// cmdPath is a file path to command executable.
2527
func UpdateTo(ctx context.Context, assetURL, assetFileName, cmdPath string) error {
28+
//nolint:contextcheck
2629
up := DefaultUpdater()
2730
src, err := downloadReleaseAssetFromURL(ctx, assetURL)
2831
if err != nil {
@@ -35,18 +38,20 @@ func UpdateTo(ctx context.Context, assetURL, assetFileName, cmdPath string) erro
3538
// UpdateCommand updates a given command binary to the latest version.
3639
// This function is a shortcut version of updater.UpdateCommand using a DefaultUpdater()
3740
func UpdateCommand(ctx context.Context, cmdPath string, current string, repository Repository) (*Release, error) {
41+
//nolint:contextcheck
3842
return DefaultUpdater().UpdateCommand(ctx, cmdPath, current, repository)
3943
}
4044

4145
// UpdateSelf updates the running executable itself to the latest version.
4246
// This function is a shortcut version of updater.UpdateSelf using a DefaultUpdater()
4347
func UpdateSelf(ctx context.Context, current string, repository Repository) (*Release, error) {
48+
//nolint:contextcheck
4449
return DefaultUpdater().UpdateSelf(ctx, current, repository)
4550
}
4651

4752
func downloadReleaseAssetFromURL(ctx context.Context, url string) (rc io.ReadCloser, err error) {
4853
client := http.DefaultClient
49-
req, err := http.NewRequest("GET", url, nil)
54+
req, err := http.NewRequest(http.MethodGet, url, nil)
5055
if err != nil {
5156
return nil, err
5257
}

update/hide_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ func TestHideFile(t *testing.T) {
1212
t.Parallel()
1313

1414
tempFile := filepath.Join(t.TempDir(), t.Name())
15-
err := os.WriteFile(tempFile, []byte("test"), 0o644)
15+
err := os.WriteFile(tempFile, []byte("test"), 0o600)
1616
assert.NoError(t, err)
1717

1818
err = hideFile(tempFile)

update_test.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@ func TestUpdateCommandWithWrongVersion(t *testing.T) {
2222
}
2323

2424
func TestUpdateCommand(t *testing.T) {
25-
current := "0.14.0"
26-
new := "1.0.0"
25+
currentVersion := "0.14.0"
26+
newVersion := "1.0.0"
2727
source := mockSourceRepository(t)
2828
updater, err := NewUpdater(Config{Source: source})
2929
require.NoError(t, err)
3030

3131
filename := setupCurrentVersion(t)
3232

33-
rel, err := updater.UpdateCommand(context.Background(), filename, current, ParseSlug("creativeprojects/new_version"))
33+
rel, err := updater.UpdateCommand(context.Background(), filename, currentVersion, ParseSlug("creativeprojects/new_version"))
3434
require.NoError(t, err)
35-
assert.Equal(t, new, rel.Version())
35+
assert.Equal(t, newVersion, rel.Version())
3636

3737
assertNewVersion(t, filename)
3838
}
@@ -42,8 +42,8 @@ func TestUpdateViaSymlink(t *testing.T) {
4242
t.Skip("skipping because creating symlink on windows requires admin privilege")
4343
}
4444

45-
current := "0.14.0"
46-
new := "1.0.0"
45+
currentVersion := "0.14.0"
46+
newVersion := "1.0.0"
4747
source := mockSourceRepository(t)
4848
updater, err := NewUpdater(Config{Source: source})
4949
require.NoError(t, err)
@@ -54,9 +54,9 @@ func TestUpdateViaSymlink(t *testing.T) {
5454
err = os.Symlink(exePath, symPath)
5555
require.NoError(t, err)
5656

57-
rel, err := updater.UpdateCommand(context.Background(), symPath, current, ParseSlug("creativeprojects/new_version"))
57+
rel, err := updater.UpdateCommand(context.Background(), symPath, currentVersion, ParseSlug("creativeprojects/new_version"))
5858
require.NoError(t, err)
59-
assert.Equal(t, new, rel.Version())
59+
assert.Equal(t, newVersion, rel.Version())
6060

6161
// check actual file (not symlink)
6262
assertNewVersion(t, exePath)
@@ -478,7 +478,7 @@ func setupCurrentVersion(t *testing.T) string {
478478
filename += ".exe"
479479
}
480480

481-
err := os.WriteFile(filename, []byte("old version"), 0o777)
481+
err := os.WriteFile(filename, []byte("old version"), 0o600)
482482
require.NoError(t, err)
483483

484484
return filename

validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func (v *SHAValidator) Validate(filename string, release, asset []byte) error {
152152
return ErrIncorrectChecksumFile
153153
}
154154

155-
hash := fmt.Sprintf("%s", asset[:sha256.BlockSize])
155+
hash := string(asset[:sha256.BlockSize])
156156
calculatedHash := fmt.Sprintf("%x", sha256.Sum256(release))
157157

158158
if equal, err := hexStringEquals(sha256.Size, calculatedHash, hash); !equal {

validate_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@ import (
77
"encoding/hex"
88
"encoding/pem"
99
"fmt"
10-
"golang.org/x/crypto/openpgp"
11-
"golang.org/x/crypto/openpgp/armor"
10+
"io"
1211
"os"
1312
"testing"
1413

1514
"github.com/stretchr/testify/assert"
1615
"github.com/stretchr/testify/require"
16+
"golang.org/x/crypto/openpgp"
17+
"golang.org/x/crypto/openpgp/armor"
1718
)
1819

1920
func TestValidatorAssetNames(t *testing.T) {
@@ -321,10 +322,12 @@ func TestPGPValidatorWithArmoredKeyRing(t *testing.T) {
321322

322323
func getTestPGPKeyRing(t *testing.T) (PGPKeyRing []byte, entity *openpgp.Entity) {
323324
var err error
325+
var armoredWriter io.WriteCloser
324326
entity, err = openpgp.NewEntity("go-selfupdate", "", "info@go-selfupdate.local", nil)
327+
require.NoError(t, err)
325328

326329
buffer := &bytes.Buffer{}
327-
if armoredWriter, err := armor.Encode(buffer, openpgp.PublicKeyType, nil); err == nil {
330+
if armoredWriter, err = armor.Encode(buffer, openpgp.PublicKeyType, nil); err == nil {
328331
if err = entity.Serialize(armoredWriter); err == nil {
329332
err = armoredWriter.Close()
330333
}

0 commit comments

Comments
 (0)