diff --git a/integration/workflow_registry_test.go b/integration/workflow_registry_test.go index 747089522..2f26baf3c 100644 --- a/integration/workflow_registry_test.go +++ b/integration/workflow_registry_test.go @@ -5,6 +5,7 @@ import ( "fmt" "os" "path/filepath" + "strings" "testing" "github.com/speakeasy-api/sdk-gen-config/workflow" @@ -48,12 +49,25 @@ func TestStability(t *testing.T) { initialChecksums, err = calculateChecksums(temp) require.NoError(t, err) + // Let's move our temporary directory around. We should be resilient to moves + newTemp := setupTestDir(t) + require.NoError(t, os.RemoveAll(newTemp)) + require.NoError(t, os.Rename(temp, newTemp)) + temp = newTemp + // Re-run the generation. We should have stable digests. cmdErr = execute(t, temp, initialArgs...).Run() require.NoError(t, cmdErr) + rerunChecksums, err := calculateChecksums(temp) require.NoError(t, err) require.Equal(t, initialChecksums, rerunChecksums, "Generated files should be identical when using --frozen-workflow-lock") + // Once more, just to be sure. This now has a change report so it could in theory change. + cmdErr = execute(t, temp, initialArgs...).Run() + require.NoError(t, cmdErr) + rerunChecksums, err = calculateChecksums(temp) + require.NoError(t, err) + require.Equal(t, initialChecksums, rerunChecksums, "Generated files should be identical when using --frozen-workflow-lock") // Modify the workflow file to simulate a change // Shouldn't do anything; we'll validate that later. workflowFile.Sources["test-source"].Inputs[0].Location = "https://raw.githubusercontent.com/OAI/OpenAPI-Specification/main/examples/v3.1/petstore.yaml" @@ -113,7 +127,7 @@ func TestRegistryFlow(t *testing.T) { require.NoError(t, workflow.Save(temp, workflowFile)) // Re-run the generation. It should work. - cmdErr = executeI(t, temp, initialArgs...).Run() + cmdErr = execute(t, temp, initialArgs...).Run() require.NoError(t, cmdErr) } @@ -123,6 +137,19 @@ func calculateChecksums(dir string) (map[string]string, error) { if err != nil { return err } + + // Skip .git + if strings.Contains(path, ".git") { + return nil + } + + // skip gen.lock. In particular, this currently varies between runs if the OAS is reformatted which occurs during bundling + // however we validate stability through the workflow lock file + // TODO: once https://github.com/pb33f/libopenapi/issues/321 is closed, use this to power document checksums and drop this block + if strings.Contains(path, "gen.lock") { + return nil + } + if !info.IsDir() { data, err := os.ReadFile(path) if err != nil { diff --git a/internal/reports/reports.go b/internal/reports/reports.go index 45ccad00b..d032a6701 100644 --- a/internal/reports/reports.go +++ b/internal/reports/reports.go @@ -7,10 +7,10 @@ import ( "fmt" "github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/operations" "github.com/speakeasy-api/speakeasy-client-sdk-go/v3/pkg/models/shared" + "github.com/speakeasy-api/speakeasy-core/auth" "github.com/speakeasy-api/speakeasy-core/events" "github.com/speakeasy-api/speakeasy/internal/links" "github.com/speakeasy-api/speakeasy/internal/log" - "github.com/speakeasy-api/speakeasy/internal/sdk" "github.com/stoewer/go-strcase" "os" "path/filepath" @@ -31,7 +31,7 @@ func UploadReport(ctx context.Context, reportBytes []byte, reportType shared.Typ } digest := hex.EncodeToString(md5Hasher.Sum(nil)) - s, err := sdk.InitSDK() + s, err := auth.GetSDKFromContext(ctx) if err != nil { return writeLocally(digest, reportBytes, reportType) } diff --git a/internal/run/source.go b/internal/run/source.go index af99faddc..e308936b0 100644 --- a/internal/run/source.go +++ b/internal/run/source.go @@ -30,7 +30,6 @@ import ( "github.com/speakeasy-api/speakeasy/internal/config" "github.com/speakeasy-api/speakeasy/internal/defaultcodesamples" "github.com/speakeasy-api/speakeasy/internal/env" - "github.com/speakeasy-api/speakeasy/internal/git" "github.com/speakeasy-api/speakeasy/internal/github" "github.com/speakeasy-api/speakeasy/internal/log" "github.com/speakeasy-api/speakeasy/internal/overlay" @@ -42,7 +41,6 @@ import ( "github.com/speakeasy-api/speakeasy/internal/workflowTracking" "github.com/speakeasy-api/speakeasy/pkg/merge" "github.com/speakeasy-api/speakeasy/registry" - "go.uber.org/zap" ) type SourceResult struct { @@ -423,11 +421,6 @@ func (w *Workflow) snapshotSource(ctx context.Context, parentStep *workflowTrack return fmt.Errorf("error localizing openapi document: %w", err) } - gitRepo, err := git.NewLocalRepository(w.ProjectDir) - if err != nil { - log.From(ctx).Debug("error sniffing git repository", zap.Error(err)) - } - rootDocument, err := memfs.Open(filepath.Join(bundler.BundleRoot.String(), "openapi.yaml")) if errors.Is(err, fs.ErrNotExist) { rootDocument, err = memfs.Open(filepath.Join(bundler.BundleRoot.String(), "openapi.json")) @@ -441,14 +434,6 @@ func (w *Workflow) snapshotSource(ctx context.Context, parentStep *workflowTrack return fmt.Errorf("error extracting annotations from openapi document: %w", err) } - revision := "" - if gitRepo != nil { - revision, err = gitRepo.HeadHash() - if err != nil { - log.From(ctx).Debug("error sniffing head commit hash", zap.Error(err)) - } - } - annotations.Revision = revision annotations.BundleRoot = strings.TrimPrefix(rootDocumentPath, string(os.PathSeparator)) err = pl.BuildOCIImage(ctx, bundler.NewReadWriteFS(memfs, memfs), &bundler.OCIBuildOptions{ diff --git a/internal/run/target.go b/internal/run/target.go index b9625b6a2..e3dfd991d 100644 --- a/internal/run/target.go +++ b/internal/run/target.go @@ -99,7 +99,7 @@ func (w *Workflow) runTarget(ctx context.Context, target string) (*SourceResult, if t.Output != nil { outDir = *t.Output } else { - outDir = w.ProjectDir + outDir = "." } targetLock.OutLocation = outDir