diff --git a/examples/one-arch.yaml b/examples/one-arch.yaml new file mode 100644 index 000000000..653de707a --- /dev/null +++ b/examples/one-arch.yaml @@ -0,0 +1,39 @@ +package: + name: one-arch + version: 0.0.1 + epoch: 0 + description: "an example of how target-architecture works" + copyright: + - license: Not-Applicable + target-architecture: + - x86_64 + +environment: + contents: + repositories: + - https://packages.wolfi.dev/os + keyring: + - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub + packages: + - busybox + +pipeline: + - runs: echo hello package + +test: + environment: + contents: + repositories: + - https://packages.wolfi.dev/os + keyring: + - https://packages.wolfi.dev/os/wolfi-signing.rsa.pub + packages: + - busybox + pipeline: + - if: ${{targets.architecture == "x86_64"}} + runs: | + echo hello test + - if: ${{targets.architecture == "arm64"}} + runs: | + echo "BAD ARCHITECTURE" + exit 1 diff --git a/pkg/build/test.go b/pkg/build/test.go index 1ec06d2c3..1b3a4da63 100644 --- a/pkg/build/test.go +++ b/pkg/build/test.go @@ -27,6 +27,7 @@ import ( "strings" apko_build "chainguard.dev/apko/pkg/build" + "chainguard.dev/apko/pkg/build/types" apko_types "chainguard.dev/apko/pkg/build/types" "github.com/chainguard-dev/clog" apkofs "github.com/chainguard-dev/go-apk/pkg/fs" @@ -492,6 +493,18 @@ func (t *Test) TestPackage(ctx context.Context) error { Package: pkg, } + inarchs := false + for _, ta := range pkg.TargetArchitecture { + if types.ParseArchitecture(ta) == t.Arch { + inarchs = true + break + } + } + if !inarchs { + log.Warnf("skipping test for %s on %s", pkg.Name, t.Arch) + return nil + } + if t.GuestDir == "" { guestDir, err := os.MkdirTemp(t.Runner.TempDir(), "melange-guest-*") if err != nil { @@ -566,6 +579,7 @@ func (t *Test) TestPackage(ctx context.Context) error { if !t.IsTestless() { cfg.Arch = t.Arch + if err := t.Runner.StartPod(ctx, cfg); err != nil { return fmt.Errorf("unable to start pod: %w", err) }