Skip to content

Commit

Permalink
ci: Split integration tests into separate jobs
Browse files Browse the repository at this point in the history
Signed-off-by: Brian Goff <[email protected]>
  • Loading branch information
cpuguy83 committed Dec 21, 2024
1 parent fb56bc9 commit aea08b9
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 32 deletions.
37 changes: 34 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,25 @@ jobs:
exit 1
fi
integration:
runs-on: ubuntu-22.04
strategy:
matrix:
suite:
- Mariner2
- Azlinux3
- Bookworm
- Bullseye
- Bionic
- Focal
- Jammy
- Noble
- Windows
- ""
include:
- filter: ""
skip: Mariner2|Azlinux3|Bookworm|Bullseye|Bionic|FOcal|Jammy|Noble|Windows

# TODO: support diff/merge
# Right now this is handled by the e2e suite, but we can migrate that here.
steps:
Expand Down Expand Up @@ -110,8 +126,23 @@ jobs:
- name: download deps
run: go mod download
- name: pre-cache worker image
run: go run ./cmd/ci-build-workers ${TEST_SUITE}
env:
TEST_SUITE: ${{ matrix.suite }}
- name: Run integration tests
run: go test -v -json --parallel 128 ./test | go run ./cmd/test2json2gha --slow 5s
run: |
set -ex
if [ -n "${TEST_SUITE}" ]; then
run="-run ${TEST_SUITE}"
fi
if [ -n "${TEST_SKIP}" ]; then
skip="-skip \"${TEST_SKIP}\""
fi
go test -v -json --parallel 128 ${run} ${skip} ./test | go run ./cmd/test2json2gha --slow 5s
env:
TEST_SUITE: ${{ matrix.suite }}
TEST_SKIP: ${{ matrix.skip }}
- name: dump logs
if: failure()
run: sudo journalctl -u docker
Expand All @@ -127,7 +158,7 @@ jobs:
if: always()
uses: actions/upload-artifact@v4
with:
name: integration-test-reports
name: integration-test-reports-${{matrix.include}}
path: /tmp/reports/*
retention-days: 1

Expand Down
66 changes: 37 additions & 29 deletions cmd/ci-build-workers/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ package main
import (
"bytes"
"context"
"flag"
"fmt"
"os"
"os/signal"
"path"
"strings"
"sync"
"syscall"
"time"
Expand All @@ -27,6 +29,22 @@ import (
)

func main() {
flag.Parse()
targets := flag.Args()
if len(targets) == 0 {
targets = []string{
"mariner2",
"azlinux3",
"bionic",
"focal",
"jammy",
"noble",
"bullseye",
"bookworm",
"windowscross",
}
}

buildx := testenv.New()

ctx, cancel := context.WithCancel(context.Background())
Expand Down Expand Up @@ -57,13 +75,13 @@ func main() {
panic(err)
}

if err := do(ctx, client); err != nil {
if err := do(ctx, client, targets); err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}

func do(ctx context.Context, c *client.Client) (retErr error) {
func do(ctx context.Context, c *client.Client, targets []string) (retErr error) {
ch := make(chan *client.SolveStatus)
so := client.SolveOpt{}

Expand Down Expand Up @@ -99,39 +117,29 @@ func do(ctx context.Context, c *client.Client) (retErr error) {
}
}()

_, err = c.Build(ctx, so, "", build, ch)
_, err = c.Build(ctx, so, "", build(targets), ch)
return err
}

func build(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) {
targets := []string{
"mariner2",
"azlinux3",
"bionic",
"focal",
"jammy",
"noble",
"bullseye",
"bookworm",
"windowscross",
}
func build(targets []string) gwclient.BuildFunc {
return func(ctx context.Context, client gwclient.Client) (*gwclient.Result, error) {
eg, ctx := errgroup.WithContext(ctx)

eg, ctx := errgroup.WithContext(ctx)
bctx, err := llb.Scratch().File(llb.Mkfile("Dockerfile", 0o644, []byte("null"))).Marshal(ctx)
if err != nil {
return nil, errors.Wrap(err, "creating build context")
}
for _, t := range targets {
t := strings.ToLower(t)
eg.Go(func() error {
f := buildWorker(t, bctx.ToPB())
_, err := f(ctx, client)
return errors.Wrap(err, t)
})
}

bctx, err := llb.Scratch().File(llb.Mkfile("Dockerfile", 0o644, []byte("null"))).Marshal(ctx)
if err != nil {
return nil, errors.Wrap(err, "creating build context")
return gwclient.NewResult(), eg.Wait()
}
for _, t := range targets {
t := t
eg.Go(func() error {
f := buildWorker(t, bctx.ToPB())
_, err := f(ctx, client)
return errors.Wrap(err, t)
})
}

return gwclient.NewResult(), eg.Wait()
}

func buildWorker(t string, bctx *pb.Definition) gwclient.BuildFunc {
Expand Down

0 comments on commit aea08b9

Please sign in to comment.