Skip to content

Commit

Permalink
Merge pull request #287 from jumppad-labs/f-fix-windows
Browse files Browse the repository at this point in the history
F fix windows
  • Loading branch information
nicholasjackson committed Apr 5, 2024
2 parents 0b13dc1 + c9a154f commit a1047e1
Show file tree
Hide file tree
Showing 9 changed files with 278 additions and 131 deletions.
12 changes: 6 additions & 6 deletions .dagger/dagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
"sdk": "go",
"dependencies": [
{
"name": "checksum",
"source": "github.com/jumppad-labs/daggerverse/checksum@49dff54b421df9844fec87766e3710138bc98914"
"name": "jumppad",
"source": "github.com/jumppad-labs/daggerverse/jumppad@b818a297c78f559e95190a1a19a30668abdd996f"
},
{
"name": "brew",
"source": "github.com/jumppad-labs/daggerverse/brew@0190848d9c2a55d275de79dd97fb4d25624bbcfd"
},
{
"name": "checksum",
"source": "github.com/jumppad-labs/daggerverse/checksum@49dff54b421df9844fec87766e3710138bc98914"
},
{
"name": "deb",
"source": "github.com/jumppad-labs/daggerverse/deb@1151c479411222d6540dc068ec10bb8231ac8158"
Expand All @@ -18,10 +22,6 @@
"name": "github",
"source": "github.com/jumppad-labs/daggerverse/github@0db72e1659d198fe446725bf1e895cd2b60b022b"
},
{
"name": "jumppad",
"source": "github.com/jumppad-labs/daggerverse/jumppad@862ddf584a73ef19dc14e3bedbfae56cb90b4e79"
},
{
"name": "notorize",
"source": "github.com/jumppad-labs/daggerverse/notorize@749e98349bb10c95aabcc4f7bea0c2bb203a89f2"
Expand Down
217 changes: 182 additions & 35 deletions .dagger/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ type JumppadCI struct {
dockerCacheVolume *CacheVolume
}

func (d *JumppadCI) WithGoCache(cache *CacheVolume) *JumppadCI {
d.goCacheVolume = cache
return d
}

func (d *JumppadCI) All(
ctx context.Context,
src *Directory,
Expand Down Expand Up @@ -88,7 +93,13 @@ func (d *JumppadCI) All(
return output, d.lastError
}

func (d *JumppadCI) Release(ctx context.Context, src *Directory, archives *Directory, githubToken *Secret, gemfuryToken *Secret) (string, error) {
func (d *JumppadCI) Release(
ctx context.Context,
src *Directory,
archives *Directory,
githubToken *Secret,
gemfuryToken *Secret,
) (string, error) {
// create a new github release
version, _ := d.GithubRelease(ctx, src, archives, githubToken)

Expand All @@ -104,7 +115,12 @@ func (d *JumppadCI) Release(ctx context.Context, src *Directory, archives *Direc
return version, d.lastError
}

func (d *JumppadCI) Build(ctx context.Context, src *Directory, version, sha string) (*Directory, error) {
func (d *JumppadCI) Build(
ctx context.Context,
src *Directory,
version,
sha string,
) (*Directory, error) {
if d.hasError() {
return nil, d.lastError
}
Expand Down Expand Up @@ -153,7 +169,11 @@ func (d *JumppadCI) Build(ctx context.Context, src *Directory, version, sha stri
return outputs, nil
}

func (d *JumppadCI) UnitTest(ctx context.Context, src *Directory, withRace bool) error {
func (d *JumppadCI) UnitTest(
ctx context.Context,
src *Directory,
withRace bool,
) error {
if d.hasError() {
return d.lastError
}
Expand All @@ -180,7 +200,11 @@ func (d *JumppadCI) UnitTest(ctx context.Context, src *Directory, withRace bool)
return err
}

func (d *JumppadCI) Package(ctx context.Context, binaries *Directory, version string) (*Directory, error) {
func (d *JumppadCI) Package(
ctx context.Context,
binaries *Directory,
version string,
) (*Directory, error) {
if d.hasError() {
return nil, d.lastError
}
Expand Down Expand Up @@ -224,7 +248,11 @@ var archives = []Archive{
}

// Archive creates zipped and tar archives of the binaries
func (d *JumppadCI) Archive(ctx context.Context, binaries *Directory, version string) (*Directory, error) {
func (d *JumppadCI) Archive(
ctx context.Context,
binaries *Directory,
version string,
) (*Directory, error) {
if d.hasError() {
return nil, d.lastError
}
Expand Down Expand Up @@ -283,7 +311,11 @@ func (d *JumppadCI) Archive(ctx context.Context, binaries *Directory, version st
return out, nil
}

func (d JumppadCI) GenerateChecksums(ctx context.Context, files *Directory, version string) (*Directory, error) {
func (d JumppadCI) GenerateChecksums(
ctx context.Context,
files *Directory,
version string,
) (*Directory, error) {
cli := dag.Pipeline("generate-checksums")
checksums := strings.Builder{}

Expand Down Expand Up @@ -314,7 +346,16 @@ var notorize = []Archive{
}

// SignAndNotorize signs and notorizes the osx binaries using the Apple notary service
func (d JumppadCI) SignAndNotorize(ctx context.Context, version string, archives *Directory, cert *File, password *Secret, key *File, keyId, keyIssuer string) (*Directory, error) {
func (d JumppadCI) SignAndNotorize(
ctx context.Context,
version string,
archives *Directory,
cert *File,
password *Secret,
key *File,
keyId,
keyIssuer string,
) (*Directory, error) {
if d.hasError() {
return nil, d.lastError
}
Expand Down Expand Up @@ -352,7 +393,12 @@ func (d JumppadCI) SignAndNotorize(ctx context.Context, version string, archives
return out, nil
}

func (d *JumppadCI) GithubRelease(ctx context.Context, src *Directory, archives *Directory, githubToken *Secret) (string, error) {
func (d *JumppadCI) GithubRelease(
ctx context.Context,
src *Directory,
archives *Directory,
githubToken *Secret,
) (string, error) {
if d.hasError() {
return "", d.lastError
}
Expand Down Expand Up @@ -382,7 +428,11 @@ func (d *JumppadCI) GithubRelease(ctx context.Context, src *Directory, archives
return version, err
}

func (d *JumppadCI) UpdateBrew(ctx context.Context, version string, githubToken *Secret) error {
func (d *JumppadCI) UpdateBrew(
ctx context.Context,
version string,
githubToken *Secret,
) error {
if d.hasError() {
return d.lastError
}
Expand Down Expand Up @@ -418,7 +468,12 @@ var gemFury = []Archive{
{Path: "/pkg/linux/arm64/jumppad.deb", Type: "copy", Output: "jumppad_%%VERSION%%_linux_arm64.deb"},
}

func (d *JumppadCI) UpdateGemFury(ctx context.Context, version string, gemFuryToken *Secret, archives *Directory) error {
func (d *JumppadCI) UpdateGemFury(
ctx context.Context,
version string,
gemFuryToken *Secret,
archives *Directory,
) error {
cli := dag.Pipeline("update-gem-fury")

tkn, _ := gemFuryToken.Plaintext(ctx)
Expand All @@ -442,7 +497,11 @@ func (d *JumppadCI) UpdateGemFury(ctx context.Context, version string, gemFuryTo
return nil
}

func (d *JumppadCI) UpdateWebsite(ctx context.Context, version string, githubToken *Secret) error {
func (d *JumppadCI) UpdateWebsite(
ctx context.Context,
version string,
githubToken *Secret,
) error {
cli := dag.Pipeline("update-website")

f := cli.Directory().WithNewFile("version", version).File("version")
Expand All @@ -466,11 +525,6 @@ func (d *JumppadCI) UpdateWebsite(ctx context.Context, version string, githubTok
return nil
}

func (d *JumppadCI) WithGoCache(cache *CacheVolume) *JumppadCI {
d.goCacheVolume = cache
return d
}

func (d *JumppadCI) getVersion(ctx context.Context, token *Secret, src *Directory) (string, string, error) {
if d.hasError() {
return "", "", d.lastError
Expand Down Expand Up @@ -579,39 +633,132 @@ func (d *JumppadCI) setArchLocalMachine(ctx context.Context) {
}

var functionalTests = []string{
// "/examples/build",
// "/examples/certificates",
// "/examples/container",
// "/examples/docs",
// "/examples/exec",
"/examples/multiple_k3s_clusters",
// "/examples/nomad",
// "/examples/single_file",
// "/examples/single_k3s_cluster",
// "/examples/terraform",
"/build",
"/certificates",
"/container",
"/docs",
"/exec",
"/multiple_k3s_clusters",
"/nomad",
"/single_file",
"/single_k3s_cluster",
"/terraform",
}

func (d *JumppadCI) FunctionalTestAll(ctx context.Context, jumppad *File, src *Directory, architecture, runtime string) error {
var runtimes = []string{"docker", "podman"}

func (d *JumppadCI) FunctionalTestAll(
ctx context.Context,
jumppad *File,
src *Directory,
) error {
if d.hasError() {
return d.lastError
}

for _, ft := range functionalTests {
testDir := src.Directory(ft)
cli := dag.Pipeline("functional-test-all")

// get the architecture of the current machine
platform, err := cli.DefaultPlatform(ctx)
if err != nil {
panic(err)
}

jobCount := len(functionalTests) * len(runtimes)
arch := strings.Split(string(platform), "/")[1]
jobs := make(chan job, jobCount)
errors := make(chan error, jobCount)

// start the workers
for w := 0; w < 1; w++ {
go startTestWorker(ctx, cli, jumppad, src, arch, jobs, errors)
}

// add the jobs
for _, runtime := range runtimes {
for _, ft := range functionalTests {
jobs <- job{workingDirectory: ft, runtime: runtime}
}
}
close(jobs)

for i := 0; i < jobCount; i++ {
err := <-errors
if err != nil {
d.lastError = err
return err
}
}

return nil
}

type job struct {
workingDirectory string
runtime string
}

_, err := dag.Jumppad().
WithCache(d.dockerCache()).
func startTestWorker(ctx context.Context, cli *Client, jumppad *File, src *Directory, arch string, jobs <-chan job, errors chan<- error) {
for j := range jobs {
wd := strings.TrimPrefix(j.workingDirectory, "/")
pl := cli.Pipeline("functional-test-" + wd + "-" + j.runtime)

_, err := pl.Jumppad().
TestBlueprintWithBinary(
ctx,
testDir,
src,
jumppad,
JumppadTestBlueprintWithBinaryOpts{Architecture: architecture, Runtime: runtime},
JumppadTestBlueprintWithBinaryOpts{WorkingDirectory: j.workingDirectory, Architecture: arch, Runtime: j.runtime, Cache: j.runtime},
)

if err != nil {
d.lastError = err
return err
errors <- err
}

errors <- nil
}
}

// FunctionalTest runs the functional tests for the jumppad binary
//
// example usage: dagger call functional-test --jumppad /path/to/jumppad --src /path/to/tests --working-directory /simple --runtime docker
func (d *JumppadCI) FunctionalTest(
ctx context.Context,
// path to the jumppad binary
jumppad *File,
// source directory containing the tests
src *Directory,
// working directory for the tests, relative to the source directory
WorkingDirectory,
// runtime to use for the tests, either docker or podman
Runtime string,
) error {
if d.hasError() {
return d.lastError
}

wd := strings.TrimPrefix(WorkingDirectory, "/")
pl := dag.Pipeline("functional-test-" + wd + "-" + Runtime)

// get the architecture of the current machine
platform, err := pl.DefaultPlatform(ctx)
if err != nil {
panic(err)
}

arch := strings.Split(string(platform), "/")[1]

_, err = pl.Jumppad().
TestBlueprintWithBinary(
ctx,
src,
jumppad,
JumppadTestBlueprintWithBinaryOpts{WorkingDirectory: WorkingDirectory, Architecture: arch, Runtime: Runtime, Cache: Runtime},
)

if err != nil {
d.lastError = err
return err
}

return nil
Expand Down

0 comments on commit a1047e1

Please sign in to comment.