Skip to content
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

Unexpected build --single-target behavior #4369

Closed
3 of 4 tasks
kzantow opened this issue Oct 13, 2023 · 0 comments · Fixed by #4370
Closed
3 of 4 tasks

Unexpected build --single-target behavior #4369

kzantow opened this issue Oct 13, 2023 · 0 comments · Fixed by #4370
Assignees
Labels
bug Something isn't working

Comments

@kzantow
Copy link

kzantow commented Oct 13, 2023

What happened?

The build command's --single-target flag appears to be executing multiple steps of the build process for targets other than the single specified target.

Using this goreleaser config, run:

$ goreleaser build --clean --snapshot --single-target --config .goreleaser.yaml
  • starting build...
  • loading                                          path=.goreleaser.yaml
  • building only for darwin/amd64                   reason=single target is enabled
  • skipping validate...
  • loading environment variables
  • getting and validating git state
    • git state                                      commit=2fc2588030d0e71e491cf9527164a49e86209f01 branch=chore/build-syft-for-cli-tests current_tag=v0.93.0 previous_tag=v0.92.0 dirty=false
    • pipe skipped                                   reason=disabled during snapshot mode
  • parsing tag
  • setting defaults
    • DEPRECATED:  brews.tap  should not be used anymore, check https://goreleaser.com/deprecations#brewstap for more info
  • snapshotting
    • building snapshot...                           version=0.93.0-SNAPSHOT-2fc25880
  • checking distribution directory
    • cleaning dist
  • loading go mod information
  • build prerequisites
  • writing effective config file
    • writing                                        config=dist/config.yaml
  • building binaries
    • building                                       binary=dist/windows-build_darwin_amd64_v1/syft
    • building                                       binary=dist/linux-build_darwin_amd64_v1/syft
    • building                                       binary=dist/darwin-build_darwin_amd64_v1/syft
    • running hook                                   hook=.tmp/quill sign-and-notarize "/syft/dist/darwin-build_darwin_amd64_v1/syft" --dry-run=true --ad-hoc=true -vv
    • took: 3s
  • storing release metadata
    • writing                                        file=dist/artifacts.json
    • writing                                        file=dist/metadata.json
  • you are using deprecated options, check the output above for details
  • build succeeded after 3s
  • thanks for using goreleaser!

You can see that the flag identified the correct platform/architecture to use ("building only for darwin/amd64 reason=single target is enabled") but then the building binaries section indicates it's building 3 binaries, 2 of which are for incorrect platforms. It also executed the hook which is specified only for darwin builds (which was correct, in this case).

BUT after this runs, it turns out it only actually built the darwin binary, but it put it in all 3 of those locations, and for some reason it was built twice (note the md5 hashes):

$ echo "$(for f in $(find dist); do if [[ -f $f ]]; then echo $f $(md5sum $f | awk '{print $1}'); else echo $f; fi; done)" | column -t 
dist
dist/linux-build_darwin_amd64_v1
dist/linux-build_darwin_amd64_v1/syft    95f83a28adfbf9dfb52e5b890748f544
dist/metadata.json                       02ac778f6cfd61371d8c9fd9cd7544a7
dist/config.yaml                         32eeb7282574cd4a51450e9a3b35c093
dist/darwin-build_darwin_amd64_v1
dist/darwin-build_darwin_amd64_v1/syft   c7bac673d85a1816d7363e6867a85a8b
dist/windows-build_darwin_amd64_v1
dist/windows-build_darwin_amd64_v1/syft  95f83a28adfbf9dfb52e5b890748f544
dist/artifacts.json                      1f943b691953f1d012e56079d5ca0efe

$ dist/darwin-build_darwin_amd64_v1/syft version
Application:     syft
Version:         0.93.0-SNAPSHOT-2fc25880
BuildDate:       2023-10-13T15:58:44Z
GitCommit:       2fc2588030d0e71e491cf9527164a49e86209f01
GitDescription:  v0.93.0-17-g2fc25880
Platform:        darwin/amd64
GoVersion:       go1.21.1
Compiler:        gc

$ dist/windows-build_darwin_amd64_v1/syft version
Application:     syft
Version:         0.93.0-SNAPSHOT-2fc25880
BuildDate:       2023-10-13T15:58:44Z
GitCommit:       2fc2588030d0e71e491cf9527164a49e86209f01
GitDescription:  v0.93.0-17-g2fc25880
Platform:        darwin/amd64
GoVersion:       go1.21.1
Compiler:        gc

$ dist/linux-build_darwin_amd64_v1/syft version
Application:     syft
Version:         0.93.0-SNAPSHOT-2fc25880
BuildDate:       2023-10-13T15:58:44Z
GitCommit:       2fc2588030d0e71e491cf9527164a49e86209f01
GitDescription:  v0.93.0-17-g2fc25880
Platform:        darwin/amd64
GoVersion:       go1.21.1
Compiler:        gc

So these are all darwin/amd64 binaries, but they are in directories for linux and windows, albeit with darwin as a part of the matrix. I would expect only the dist/darwin-build_darwin_amd64_v1/syft to be created. Another oddity is that of the 3 binaries, 2 are identical and the expected one is not.

The same problem occurs on Linux, as can be seen in this workflow output. You'll also see that the output indicates it's attempting to build a similar set of 3 artifacts and attempts to run the darwin hook (presumably because the darwin target seems to be running), even though it indicates "building only for linux/amd64 reason=single target is enabled". I'm assuming the darwin hook then fails because instead of having a macho binary, it's a linux ELF binary that's a duplicate of the linux build.

Am I misunderstanding what the --single-target flag is supposed to do? I think the expected behavior here is that only the build configuration that matches the GOOS and GOARCH specified should run.

How can we reproduce this?

git clone https://github.com/anchore/syft.git
pushd syft
make bootstrap
goreleaser build --clean --snapshot --single-target --config .goreleaser.yaml

goreleaser version

GitVersion:    1.21.2
GitCommit:     26fed97a0defe4e73e3094cb903225d5445e5f0d
GitTreeState:  false
BuildDate:     2023-09-26T11:20:15Z
BuiltBy:       goreleaser
GoVersion:     go1.21.1
Compiler:      gc
ModuleSum:     h1:dgYtIS7aZlQuRMUMLCjDCOs4lWss85Oh60RDSO0rbWU=
Platform:      darwin/amd64

GoReleaser Check

  • goreleaser check shows no errors

Search

  • I did search for other open and closed issues before opening this

Supporter

Code of Conduct

  • I agree to follow this project's Code of Conduct

Additional context

No response

@kzantow kzantow added bug Something isn't working triage Issue pending triage by one of the maintainers labels Oct 13, 2023
@kzantow kzantow changed the title Unexpected --single-target behavior Unexpected build --single-target behavior Oct 13, 2023
caarlos0 added a commit that referenced this issue Oct 13, 2023
caarlos0 added a commit that referenced this issue Oct 14, 2023
@caarlos0 caarlos0 removed the triage Issue pending triage by one of the maintainers label Oct 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants