Skip to content

Commit

Permalink
chore: merge main
Browse files Browse the repository at this point in the history
* main:
  feat(build): add mage dagger:run generate:screenshots (#1868)
  chore(deps-dev): bump eslint from 8.43.0 to 8.45.0 in /ui (#1878)
  chore(deps-dev): bump postcss from 8.4.24 to 8.4.26 in /ui (#1877)
  chore(deps-dev): bump @playwright/test from 1.35.1 to 1.36.1 in /ui (#1880)
  chore(deps-dev): bump tailwindcss from 3.3.2 to 3.3.3 in /ui (#1876)
  chore(deps-dev): bump eslint-config-airbnb-typescript in /ui (#1879)
  chore(deps): bump github.com/hashicorp/cap from 0.3.1 to 0.3.2 (#1875)
  chore(deps): bump github.com/go-chi/chi/v5 from 5.0.8 to 5.0.10 (#1874)
  chore: remove refs to deprecated io/ioutil (#1867)
  chore(deps-dev): bump @types/react-dom from 18.2.5 to 18.2.7 in /ui (#1864)
  chore(deps-dev): bump jest and @types/jest in /ui (#1851)
  chore(github): move all db unit tests to dagger (#1869)
  chore(deps): bump semver from 6.3.0 to 6.3.1 in /examples/nextjs (#1861)
  • Loading branch information
markphelps committed Jul 17, 2023
2 parents c33fba5 + 1647217 commit 29bd1ed
Show file tree
Hide file tree
Showing 28 changed files with 1,203 additions and 840 deletions.
28 changes: 6 additions & 22 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ jobs:
test:
name: "Tests (Go)"
runs-on: ubuntu-latest
strategy:
matrix:
database: ["mysql", "postgres", "cockroachdb", "sqlite"]
steps:
- uses: actions/checkout@v3

Expand All @@ -32,10 +35,11 @@ jobs:
cd /usr/local
curl -L https://dl.dagger.io/dagger/install.sh | sh
- uses: GeorgeMac/mage-action@gm/tools-add-path-debug
- name: Unit Test ${{ matrix.database }}
uses: GeorgeMac/mage-action@gm/tools-add-path-debug
with:
version: latest
args: dagger:run test:unit
args: dagger:run "test:database ${{ matrix.database }}"

- name: Upload Coverage
uses: codecov/codecov-action@v3.1.4
Expand Down Expand Up @@ -82,23 +86,3 @@ jobs:

- name: Upload Coverage
uses: codecov/codecov-action@v3.1.4

database:
name: Database Test
runs-on: ubuntu-latest
strategy:
matrix:
database: ["mysql", "postgres", "cockroachdb"]
steps:
- uses: actions/checkout@v3

- uses: actions/setup-go@v4
with:
go-version: "1.20"
check-latest: true
cache: true

- name: Unit Test ${{ matrix.database }}
env:
FLIPT_TEST_DATABASE_PROTOCOL: ${{ matrix.database }}
run: go test -count=1 -v ./...
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,4 @@ Brewfile.lock.json
.build/
examples/cockroachdb/data
playwright-report/
screenshots/
20 changes: 9 additions & 11 deletions build/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.20

require (
code.gitea.io/sdk/gitea v0.15.1
dagger.io/dagger v0.7.0
dagger.io/dagger v0.7.3
github.com/containerd/containerd v1.6.19
github.com/docker/docker v23.0.3+incompatible
github.com/go-git/go-billy/v5 v5.4.1
Expand All @@ -17,15 +17,16 @@ require (
github.com/stretchr/testify v1.8.2
go.flipt.io/flipt v1.19.1
go.flipt.io/flipt/sdk/go v0.0.0-00010101000000-000000000000
golang.org/x/mod v0.10.0
golang.org/x/sync v0.2.0
golang.org/x/mod v0.12.0
golang.org/x/sync v0.3.0
google.golang.org/grpc v1.55.0
google.golang.org/protobuf v1.31.0
gopkg.in/yaml.v2 v2.4.0
sigs.k8s.io/kind v0.17.0
)

require (
github.com/99designs/gqlgen v0.17.34 // indirect
github.com/BurntSushi/toml v1.2.1 // indirect
github.com/Khan/genqlient v0.6.0 // indirect
github.com/Microsoft/go-winio v0.6.0 // indirect
Expand All @@ -50,37 +51,34 @@ require (
github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
github.com/grpc-ecosystem/grpc-gateway/v2 v2.15.2 // indirect
github.com/hashicorp/go-version v1.2.1 // indirect
github.com/iancoleman/strcase v0.2.0 // indirect
github.com/iancoleman/strcase v0.3.0 // indirect
github.com/imdario/mergo v0.3.13 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect
github.com/kevinburke/ssh_config v1.2.0 // indirect
github.com/kr/pretty v0.3.1 // indirect
github.com/matryer/is v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.17 // indirect
github.com/mattn/go-isatty v0.0.19 // indirect
github.com/moby/term v0.0.0-20221205130635-1aeaba878587 // indirect
github.com/opencontainers/go-digest v1.0.0 // indirect
github.com/pelletier/go-toml v1.9.5 // indirect
github.com/pjbgf/sha1cd v0.3.0 // indirect
github.com/pkg/errors v0.9.1 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.10.0 // indirect
github.com/sergi/go-diff v1.1.0 // indirect
github.com/sergi/go-diff v1.3.1 // indirect
github.com/sirupsen/logrus v1.9.0 // indirect
github.com/skeema/knownhosts v1.1.0 // indirect
github.com/spf13/cobra v1.7.0 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/vektah/gqlparser/v2 v2.5.1 // indirect
github.com/vektah/gqlparser/v2 v2.5.6 // indirect
github.com/xanzy/ssh-agent v0.3.3 // indirect
golang.org/x/crypto v0.11.0 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/oauth2 v0.10.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/term v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
golang.org/x/time v0.3.0 // indirect
golang.org/x/tools v0.9.1 // indirect
google.golang.org/appengine v1.6.7 // indirect
golang.org/x/tools v0.11.0 // indirect
google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
Expand Down
90 changes: 78 additions & 12 deletions build/go.sum

Large diffs are not rendered by default.

15 changes: 14 additions & 1 deletion build/magefile.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,12 @@ func (t Test) Database(ctx context.Context, db string) error {
return err
}

return testing.Unit(testing.All[db](ctx, client, base))
test, ok := testing.All[db]
if !ok {
return fmt.Errorf("unexpected database name: %q", db)
}

return testing.Unit(test(ctx, client, base))
})
}

Expand Down Expand Up @@ -150,6 +155,14 @@ func (t Test) Migration(ctx context.Context) error {
})
}

type Generate mg.Namespace

func (g Generate) Screenshots(ctx context.Context) error {
return daggerBuild(ctx, func(client *dagger.Client, req internal.FliptRequest, base, flipt *dagger.Container) error {
return testing.Screenshots(ctx, client, flipt)
})
}

type Release mg.Namespace

func (r Release) Next(ctx context.Context, module, versionParts string) error {
Expand Down
8 changes: 4 additions & 4 deletions build/testing/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ func Unit(ctx context.Context, client *dagger.Client, flipt *dagger.Container) e
}

var All = map[string]Wrapper{
"sqlite": WithSQLite,
"postgres": WithPostgres,
"mysql": WithMySQL,
"cockroach": WithCockroach,
"sqlite": WithSQLite,
"postgres": WithPostgres,
"mysql": WithMySQL,
"cockroachdb": WithCockroach,
}

type Wrapper func(context.Context, *dagger.Client, *dagger.Container) (context.Context, *dagger.Client, *dagger.Container)
Expand Down
136 changes: 125 additions & 11 deletions build/testing/ui.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,144 @@ package testing

import (
"context"
"crypto/sha256"
"fmt"
"os"
"path"
"time"

"dagger.io/dagger"
"golang.org/x/sync/errgroup"
)

func UI(ctx context.Context, client *dagger.Client, ui, flipt *dagger.Container) error {
test := ui.
test, err := buildUI(ctx, ui, flipt)
if err != nil {
return err
}

_, err = test.
WithExec([]string{"npx", "playwright", "install", "chromium", "--with-deps"}).
WithServiceBinding("flipt", flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_AUTHENTICATION_METHODS_TOKEN_ENABLED", "true").
WithEnvVariable("UNIQUE", time.Now().String()).
WithExec(nil)).
WithEnvVariable("FLIPT_ADDRESS", "http://flipt:8080").
WithExec([]string{"npx", "playwright", "test"})
_, err := test.ExitCode(ctx)
WithExec([]string{"npx", "playwright", "test"}).
Sync(ctx)
if err != nil {
return err
}

test.
Directory("playwright-report").
_, _ = test.Directory("playwright-report").
Export(ctx, "playwright-report")

return nil
}

func Screenshots(ctx context.Context, client *dagger.Client, flipt *dagger.Container) error {
src := client.Host().Directory("./ui/", dagger.HostDirectoryOpts{
Include: []string{
"./package.json",
"./package-lock.json",
"./playwright.config.ts",
"/screenshots/",
},
})

contents, err := src.File("package-lock.json").Contents(ctx)
if err != nil {
return err
}

cache := client.CacheVolume(fmt.Sprintf("node-modules-screenshot-%x", sha256.Sum256([]byte(contents))))

ui, err := client.Container().From("node:18-bullseye").
WithMountedDirectory("/src", src).WithWorkdir("/src").
WithMountedCache("/src/node_modules", cache).
WithExec([]string{"npm", "install"}).
WithExec([]string{"npx", "playwright", "install", "chromium", "--with-deps"}).
Sync(ctx)
if err != nil {
return err
}

src = client.Host().Directory("./ui/", dagger.HostDirectoryOpts{
Exclude: []string{
"./dist/",
"./node_modules/",
},
})

// remount entire directory with module cache
ui, err = ui.WithMountedDirectory("/src", src).
WithMountedCache("/src/node_modules", cache).
WithExec([]string{"npm", "install"}).
Sync(ctx)
if err != nil {
return err
}

entries, err := ui.Directory("screenshot").Entries(ctx)
if err != nil {
return err
}

var (
g errgroup.Group
containers = make(chan *dagger.Container, 0)
)

go func() {
g.Wait()
close(containers)
}()

for _, entry := range entries {
entry := entry
g.Go(func() error {
test, err := buildUI(ctx, ui, flipt)
if err != nil {
return err
}

if ext := path.Ext(entry); ext != ".js" {
return nil
}

c, err := test.WithExec([]string{"node", path.Join("screenshot", entry)}).Sync(ctx)
if err != nil {
return err
}

containers <- c

return err
})
}

for c := range containers {
if _, err := c.Directory("screenshots").
Export(ctx, "screenshots"); err != nil {
return err
}
}

return g.Wait()
}

func buildUI(ctx context.Context, ui, flipt *dagger.Container) (_ *dagger.Container, err error) {
flipt, err = flipt.Sync(ctx)
if err != nil {
return nil, err
}

ui, err = ui.Sync(ctx)
if err != nil {
return nil, err
}

return ui.
WithServiceBinding("flipt", flipt.
WithEnvVariable("CI", os.Getenv("CI")).
WithEnvVariable("FLIPT_AUTHENTICATION_METHODS_TOKEN_ENABLED", "true").
WithEnvVariable("UNIQUE", time.Now().String()).
WithExec(nil)).
WithFile("/usr/bin/flipt", flipt.File("/flipt")).
WithEnvVariable("FLIPT_ADDRESS", "http://flipt:8080"), nil
}
Loading

0 comments on commit 29bd1ed

Please sign in to comment.