Skip to content

fix: inject version via -ldflags so releases stop drifting (#1081)#1124

Open
ChrisJr404 wants to merge 732 commits into
owasp-amass:masterfrom
ChrisJr404:version-via-ldflags
Open

fix: inject version via -ldflags so releases stop drifting (#1081)#1124
ChrisJr404 wants to merge 732 commits into
owasp-amass:masterfrom
ChrisJr404:version-via-ldflags

Conversation

@ChrisJr404

Copy link
Copy Markdown

Closes #1081.

Background

The Amass version string is hard-coded as a const in internal/afmt/print.go:

const (
    Version = "v5.1.1"
    ...
)

This relies on every release remembering to bump the constant by hand. Per @lc's report on #1081, v5.0.1 was tagged with the constant still set to "v5.0.0", so the binary self-identified as v5.0.0 at runtime. That's a release-process bug rather than a code bug, but a tiny code change makes it impossible for it to recur.

Change

  1. Convert Version from const to var so the linker can rewrite it. The other afmt constants (Author, Description, DiscordInvitation) stay const since they don't drift between releases.

  2. Add an -ldflags injection in .goreleaser.yaml that sets Version to the actual git tag at release time:

    ldflags:
      - -s -w
      - -X github.com/owasp-amass/amass/v5/internal/afmt.Version=v{{ .Version }}
  3. Keep the source-level value as the fallback for go install-style builds that don't go through goreleaser.

Verification

$ go build -ldflags "-X github.com/owasp-amass/amass/v5/internal/afmt.Version=v9.9.9-test" -o amass ./cmd/amass
$ ./amass --help 2>&1 | grep "v[0-9]"
                                                                 v9.9.9-test       # ✓ ldflags applied

$ go build -o amass ./cmd/amass
$ ./amass --help 2>&1 | grep "v[0-9]"
                                                                      v5.1.1       # ✓ source fallback

The -s -w flags strip the symbol/debug tables (standard for release binaries — saves ~25% of the binary size for amass) and are conventional alongside -X. Happy to drop them if that's a stylistic preference.

Notes

  • Diff is +10 / -3 lines across two files.
  • Goreleaser's template variable {{ .Version }} is the tag with the v prefix stripped, so I prepend v in the -X flag — that matches the existing "v5.1.1" style and what users see at runtime today.
  • This is independent of the per-release "remember to bump the constant" workflow — that workflow can be retired entirely once this is in (or kept as an extra belt-and-suspenders, since the source fallback won't be wrong if releases are still bumped).

caffix and others added 30 commits December 29, 2025 17:20
- Add processing of config.ProvidedNames in makeAssets() to convert
  them into FQDN assets
- Add blacklist field to Scope struct with mutex for thread safety
- Process config.Scope.Blacklist entries in CreateFromConfigScope()
- Add AddBlacklist() and IsBlacklisted() methods with subdomain
  matching support
- Modify IsAssetInScope() to check blacklist before processing
- Add unit tests for blacklist and ProvidedNames functionality

Fixes owasp-amass#1086
…lf-flags

fix: process ProvidedNames and Blacklist flags (-nf, -blf)
caffix and others added 30 commits March 1, 2026 11:26
…ss#1081)

The hard-coded `Version = "v5.1.1"` const in `internal/afmt/print.go`
relies on every release remembering to bump the string by hand. v5.0.1
was tagged with the constant still set to v5.0.0 (the issue's report),
so the binary self-identified as v5.0.0 at runtime.

Convert `Version` from `const` to `var` (so the linker can rewrite it)
and add a -ldflags injection in `.goreleaser.yaml` that sets it to the
actual git tag at release time:

    -X github.com/owasp-amass/amass/v5/internal/afmt.Version=v{{ .Version }}

The source-level value is kept (still `v5.1.1` for now) as the
fallback for `go install`-style builds that don't go through
goreleaser.

The other afmt constants (Author, Description, DiscordInvitation)
remain `const` since they don't drift between releases.

Closes owasp-amass#1081.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants