#Export goes to `/scratch` instead of relative host directory

1 messages · Page 1 of 1 (latest)

worldly hamlet
#

I have the following function

func (m *Blueprints) Test(ctx context.Context, source *dagger.Directory, coverageFile string) error {
    ctr, err := m.Bun(source).
        WithExec([]string{"sh", "-c", "bun test --coverage --coverage-reporter lcov; echo -n $? > /exit_code"}).Sync(ctx)

    if err != nil {
        return fmt.Errorf("error running tests: %w", err)
    }

    resp, err := ctr.File("./coverage/lcov.info").Export(ctx, coverageFile)
    if err != nil {
        return err
    }
    fmt.Println(resp) // /scratch/coverage/lcov.info

    exitCode, err := ctr.File("/exit_code").Contents(ctx)
    if err != nil {
        return fmt.Errorf("get exit code: %w", err)
    }

    if exitCode != "0" {
        return fmt.Errorf("tests failed, exit code %s", exitCode)
    }

    return nil
}

which I am running with dagger call test --source=. --coverage-file=./coverage/lcov.info, however no file is written to the host. I'd also expect to be able to write the path as coverage/lcov.info like I am able to when calling depend inline (i.e. dagger call test ... export --path). The file appears to be written to scratch directory?

lone orchid
worldly hamlet
#

But I also want to have the pipeline fail if the tests do. The cookbook example on that suggests calling the pipeline twice to achieve that so I figure I'd inline the export.

lone orchid
limber pike
# lone orchid I see...I don't think that's currently possible to have a function return an err...

I thought it did, that was the new pattern that solomon was talking about a few weeks ago for things like "test results as artifacts" right?

This use case seems similar to what we recently proposed for the goreleaser PR

https://github.com/kpenfound/goreleaser/blob/daggerize/dagger/test.go#L18

GitHub

Deliver Go binaries as fast and easily as possible - kpenfound/goreleaser

lone orchid
fresh raft
#

Hate to resurrect an old thread, but curious if theres anything new related to this or plans to add support for this in the future? This tripped me up as well (and i see other threads referencing this one too).

cerulean oar
#

@fresh raft Ive had to solve it with the following which potentially isnt ideal but not sure what else I could do in CI for circleci

            dagger call foo --src . outputs export --path output
            exit_code=$(dagger call foo --src .  exit-code)

            exit $(( exit_code ))
lone orchid