Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: stable manifest #874

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 28 additions & 1 deletion integration/workflow_registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"
"testing"

"github.com/speakeasy-api/sdk-gen-config/workflow"
Expand Down Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}

Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions internal/reports/reports.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)
}
Expand Down
15 changes: 0 additions & 15 deletions internal/run/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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 {
Expand Down Expand Up @@ -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"))
Expand All @@ -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{
Expand Down
2 changes: 1 addition & 1 deletion internal/run/target.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
Loading