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

test: skip when executing on an unsupported arch #976

Merged
merged 1 commit into from
Feb 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading