Skip to content

Commit

Permalink
chore: handle artifacts correctly with multiple platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
jmgilman committed Sep 6, 2024
1 parent 6bbf892 commit 1f9bec4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
6 changes: 5 additions & 1 deletion forge/cli/pkg/earthly/earthly.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"log/slog"
"os"
"path"
"regexp"
"runtime"
"strconv"
Expand Down Expand Up @@ -118,7 +119,10 @@ func (e *EarthlyExecutor) buildArguments(platform string) []string {

earthlyArgs = append(earthlyArgs, e.earthlyArgs...)

if e.opts.artifact != "" {
// If we have an artifact path and multiple platforms, we need to append the platform to the artifact path to avoid conflicts.
if e.opts.artifact != "" && len(e.opts.platforms) > 1 {
earthlyArgs = append(earthlyArgs, "--artifact", fmt.Sprintf("%s+%s/*", e.earthfile, e.target), path.Join(e.opts.artifact, platform)+"/")
} else if e.opts.artifact != "" && len(e.opts.platforms) <= 1 {
earthlyArgs = append(earthlyArgs, "--artifact", fmt.Sprintf("%s+%s/*", e.earthfile, e.target), e.opts.artifact)
} else {
earthlyArgs = append(earthlyArgs, fmt.Sprintf("%s+%s", e.earthfile, e.target))
Expand Down
10 changes: 10 additions & 0 deletions forge/cli/pkg/earthly/earthly_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ func TestEarthlyExecutor_buildArguments(t *testing.T) {
platform: getNativePlatform(),
expect: []string{"--artifact", "/test/dir+foo/*", "test/"},
},
{
name: "with artifact and platforms",
e: NewEarthlyExecutor("/test/dir", "foo", nil, secrets.SecretStore{},
testutils.NewNoopLogger(),
WithPlatforms("foo", "bar"),
WithArtifact("test"),
),
platform: "foo",
expect: []string{"--platform", "foo", "--artifact", "/test/dir+foo/*", "test/foo/"},
},
{
name: "with ci",
e: NewEarthlyExecutor("/test/dir", "foo", nil, secrets.SecretStore{},
Expand Down

0 comments on commit 1f9bec4

Please sign in to comment.