Skip to content

Commit

Permalink
Merge pull request #976 from imjasonh/one-arch-test
Browse files Browse the repository at this point in the history
test: skip when executing on an unsupported arch
  • Loading branch information
imjasonh committed Feb 3, 2024
2 parents 9e4bb5b + f334c81 commit 7d00f14
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
39 changes: 39 additions & 0 deletions examples/one-arch.yaml
Original file line number Diff line number Diff line change
@@ -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
14 changes: 14 additions & 0 deletions pkg/build/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}
Expand Down

0 comments on commit 7d00f14

Please sign in to comment.