Skip to content

fix(nix): snapshot builds can now hash files as well #5894

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 13, 2025
Merged

Conversation

caarlos0
Copy link
Member

@caarlos0 caarlos0 commented Jul 9, 2025

Historically, we used to use nix-prefetch-url, so it could only calculate the hashes after the artifacts were pushed, so when using --snapshot, hashes would always be 0000....

Rather recently, we've changed it to use nix-hash instead, so we could also have changed it so it uses real hashes all the time.

This PR does that.

Discussion: https://github.com/orgs/goreleaser/discussions/5893

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
@caarlos0 caarlos0 self-assigned this Jul 9, 2025
@caarlos0 caarlos0 requested a review from Copilot July 9, 2025 17:57
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2025
@caarlos0 caarlos0 added bug Something isn't working and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 9, 2025
@pull-request-size pull-request-size bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 9, 2025
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors the Nix integration to always use real file hashing (via nix-hash) instead of the previous zero-only hasher, consolidates two constructors into one, and updates all usages and tests accordingly.

  • Consolidate NewBuild and NewPublish into a single New function that always uses realHasher.
  • Remove the alwaysZeroHasher and zeroHash from production code and adjust tests to match the new behavior.
  • Update all pipeline, publish, and healthcheck references to call nix.New() and revise tests in nix_test.go.

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
pkg/healthcheck/healthcheck.go Replaced nix.NewPublish() with nix.New()
internal/pipeline/pipeline.go Replaced nix.NewBuild() with nix.New()
internal/pipe/publish/publish.go Replaced nix.NewPublish() with nix.New()
internal/pipe/nix/nix.go Removed zero-only hasher, consolidated constructors into New
internal/pipe/nix/nix_test.go Updated tests to use New(), removed zero-hasher tests
Comments suppressed due to low confidence (1)

internal/pipe/nix/nix.go:53

  • The comment refers only to the publish phase, but New now handles both build and publish. Consider updating it to something like // New returns a Nix hashing pipe used in both build and publish phases.
// New returns a pipe to be used in the publish phase.

Comment on lines 681 to 685
type unavailableHasher struct{}

func (m unavailableHasher) Hash(string) (string, error) {
return "", errors.New("unavailable hasher")
}
func (m unavailableHasher) Available() bool { return false }
func (m unavailableHasher) Hash(string) (string, error) { return "", errors.New("unavailable hasher") }
func (m unavailableHasher) Available() bool { return false }

Copy link
Preview

Copilot AI Jul 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unavailableHasher type is defined but never used in any test. You can remove this dead code to keep the test file focused.

Copilot uses AI. Check for mistakes.

Copy link

codecov bot commented Jul 9, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.68%. Comparing base (0ace5c6) to head (c11cd29).
Report is 8 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #5894      +/-   ##
==========================================
- Coverage   82.68%   82.68%   -0.01%     
==========================================
  Files         165      165              
  Lines       16520    16516       -4     
==========================================
- Hits        13660    13656       -4     
  Misses       2268     2268              
  Partials      592      592              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@caarlos0 caarlos0 merged commit 9e1f87f into main Jul 13, 2025
17 checks passed
@caarlos0 caarlos0 deleted the nix-hash branch July 13, 2025 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant