Skip to content

Commit 7d00f14

Browse files
authored
Merge pull request #976 from imjasonh/one-arch-test
test: skip when executing on an unsupported arch
2 parents 9e4bb5b + f334c81 commit 7d00f14

2 files changed

Lines changed: 53 additions & 0 deletions

File tree

examples/one-arch.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package:
2+
name: one-arch
3+
version: 0.0.1
4+
epoch: 0
5+
description: "an example of how target-architecture works"
6+
copyright:
7+
- license: Not-Applicable
8+
target-architecture:
9+
- x86_64
10+
11+
environment:
12+
contents:
13+
repositories:
14+
- https://packages.wolfi.dev/os
15+
keyring:
16+
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
17+
packages:
18+
- busybox
19+
20+
pipeline:
21+
- runs: echo hello package
22+
23+
test:
24+
environment:
25+
contents:
26+
repositories:
27+
- https://packages.wolfi.dev/os
28+
keyring:
29+
- https://packages.wolfi.dev/os/wolfi-signing.rsa.pub
30+
packages:
31+
- busybox
32+
pipeline:
33+
- if: ${{targets.architecture == "x86_64"}}
34+
runs: |
35+
echo hello test
36+
- if: ${{targets.architecture == "arm64"}}
37+
runs: |
38+
echo "BAD ARCHITECTURE"
39+
exit 1

pkg/build/test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"strings"
2828

2929
apko_build "chainguard.dev/apko/pkg/build"
30+
"chainguard.dev/apko/pkg/build/types"
3031
apko_types "chainguard.dev/apko/pkg/build/types"
3132
"github.com/chainguard-dev/clog"
3233
apkofs "github.com/chainguard-dev/go-apk/pkg/fs"
@@ -492,6 +493,18 @@ func (t *Test) TestPackage(ctx context.Context) error {
492493
Package: pkg,
493494
}
494495

496+
inarchs := false
497+
for _, ta := range pkg.TargetArchitecture {
498+
if types.ParseArchitecture(ta) == t.Arch {
499+
inarchs = true
500+
break
501+
}
502+
}
503+
if !inarchs {
504+
log.Warnf("skipping test for %s on %s", pkg.Name, t.Arch)
505+
return nil
506+
}
507+
495508
if t.GuestDir == "" {
496509
guestDir, err := os.MkdirTemp(t.Runner.TempDir(), "melange-guest-*")
497510
if err != nil {
@@ -566,6 +579,7 @@ func (t *Test) TestPackage(ctx context.Context) error {
566579

567580
if !t.IsTestless() {
568581
cfg.Arch = t.Arch
582+
569583
if err := t.Runner.StartPod(ctx, cfg); err != nil {
570584
return fmt.Errorf("unable to start pod: %w", err)
571585
}

0 commit comments

Comments
 (0)