Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ DOCKER_BUILD_EXTRA_ARGS ?=
DOCKER_BUILDER := bufbuild-plugins
DOCKER_CACHE_DIR ?= $(TMP)/dockercache
GO ?= go
GOLANGCI_LINT_VERSION ?= v2.1.2
GOLANGCI_LINT_VERSION ?= v2.1.6
GOLANGCI_LINT := $(TMP)/golangici-lint-$(GOLANGCI_LINT_VERSION)

GO_TEST_FLAGS ?= -race -count=1
Expand Down
23 changes: 6 additions & 17 deletions cmd/download-plugins/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ func run() error {
return err
}
if !exists {
if err := downloadReleaseToDir(ctx, client.GitHub.Client(), pluginRelease, downloadDir); err != nil {
if err := downloadReleaseToDir(ctx, client.GitHub, pluginRelease, downloadDir); err != nil {
return err
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ func pluginExistsMatchingDigest(plugin release.PluginRelease, downloadDir string
return digest == plugin.PluginZipDigest, nil
}

func downloadReleaseToDir(ctx context.Context, client *http.Client, plugin release.PluginRelease, downloadDir string) error {
func downloadReleaseToDir(ctx context.Context, client *github.Client, plugin release.PluginRelease, downloadDir string) error {
expectedDigest, err := parseDigest(plugin.PluginZipDigest)
if err != nil {
return fmt.Errorf("failed to parse digest for plugin: %w", err)
Expand All @@ -184,27 +184,16 @@ func downloadReleaseToDir(ctx context.Context, client *http.Client, plugin relea
}
}()
log.Printf("downloading: %v", plugin.URL)
req, err := http.NewRequestWithContext(ctx, http.MethodGet, plugin.URL, nil)
req, err := client.NewRequest(http.MethodGet, plugin.URL, nil)
if err != nil {
return fmt.Errorf("failed to make HTTP request: %w", err)
}
resp, err := client.Do(req)
if err != nil {
return fmt.Errorf("failed to perform HTTP request: %w", err)
}
defer func() {
if err := resp.Body.Close(); err != nil {
log.Printf("failed to close response: %v", err)
}
}()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download %s: %s", plugin.URL, resp.Status)
}
digest := sha256.New()
w := io.MultiWriter(f, digest)
if _, err := io.Copy(w, resp.Body); err != nil {
return fmt.Errorf("failed to copy file: %w", err)
if _, err := client.Do(ctx, req, w); err != nil {
return fmt.Errorf("failed to perform HTTP request: %w", err)
}

sha256Digest := hex.EncodeToString(digest.Sum(nil))
if sha256Digest != expectedDigest {
return fmt.Errorf("checksum mismatch for %s: %q (expected) != %q (actual)", plugin.URL, expectedDigest, sha256Digest)
Expand Down