From d3cd3ed4d667b6d0ef8e5f74068a802f63f3b4ac Mon Sep 17 00:00:00 2001 From: Ryan Albert Date: Mon, 18 Nov 2024 14:58:48 -0800 Subject: [PATCH] feat: update with newest sdk gen config --- go.mod | 3 ++- go.sum | 4 ++-- internal/actions/release.go | 27 +++++++++++++++++++++------ internal/actions/runWorkflow.go | 23 +++++++++++++++++------ 4 files changed, 42 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 2e8b807..fcdd3be 100644 --- a/go.mod +++ b/go.mod @@ -10,8 +10,9 @@ require ( github.com/hashicorp/go-version v1.6.0 github.com/joho/godotenv v1.5.1 github.com/pb33f/libopenapi v0.15.14 + github.com/pkg/errors v0.9.1 github.com/speakeasy-api/git-diff-parser v0.0.3 - github.com/speakeasy-api/sdk-gen-config v1.7.4 + github.com/speakeasy-api/sdk-gen-config v1.28.0 github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.15.4 github.com/speakeasy-api/versioning-reports v0.6.0 github.com/stretchr/testify v1.9.0 diff --git a/go.sum b/go.sum index 0c20b2a..b995eeb 100644 --- a/go.sum +++ b/go.sum @@ -138,8 +138,8 @@ github.com/skeema/knownhosts v1.2.1 h1:SHWdIUa82uGZz+F+47k8SY4QhhI291cXCpopT1lK2 github.com/skeema/knownhosts v1.2.1/go.mod h1:xYbVRSPxqBZFrdmDyMmsOs+uX1UZC3nTN3ThzgDxUwo= github.com/speakeasy-api/git-diff-parser v0.0.3 h1:LL12d+HMtSyj6O/hQqIn/lgDPYI6ci/DEhk0la/xA+0= github.com/speakeasy-api/git-diff-parser v0.0.3/go.mod h1:P46HmmVVmwA9P8h2wa0fDpmRM8/grbVQ+uKhWDtpkIY= -github.com/speakeasy-api/sdk-gen-config v1.7.4 h1:hk3GaKiL6zxx3SulnxdunvU2V7bUSQ4YviXtIiUmWuo= -github.com/speakeasy-api/sdk-gen-config v1.7.4/go.mod h1:4R+8FTyM6UdLHltOVAigIoR5D2UfPsGMmEFzPOP1yCs= +github.com/speakeasy-api/sdk-gen-config v1.28.0 h1:Gm3WqJCxs7ExEJcRVhMsUq2mC7S23m18zpvtFaPEuys= +github.com/speakeasy-api/sdk-gen-config v1.28.0/go.mod h1:e9PjnCRHGa4K4EFKVU+kKmihOZjJ2V4utcU+274+bnQ= github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.15.4 h1:lPVNakwHrrRWRaNIdIHE6BK7RI6B/jpdwbtvI/xPEYo= github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.15.4/go.mod h1:b4fiZ1Wid0JHwwiYqhaPifDwjmC15uiN7A8Cmid+9kw= github.com/speakeasy-api/versioning-reports v0.6.0 h1:oLokEQ7xnDXqWAQk60Sk+ifwYaRbq3BrLX2KyT8gWxE= diff --git a/internal/actions/release.go b/internal/actions/release.go index fced4d2..d4d5868 100644 --- a/internal/actions/release.go +++ b/internal/actions/release.go @@ -1,12 +1,12 @@ package actions import ( - "errors" "fmt" "os" "path/filepath" "strings" + "github.com/pkg/errors" "github.com/speakeasy-api/sdk-generation-action/internal/cli" "github.com/speakeasy-api/sdk-generation-action/internal/configuration" "github.com/speakeasy-api/sdk-generation-action/internal/environment" @@ -95,7 +95,7 @@ func Release() error { if os.Getenv("SPEAKEASY_API_KEY") != "" { if err = addCurrentBranchTagging(g, latestRelease.Languages); err != nil { - logging.Debug("failed to tag registry images: %v", err) + return errors.Wrap(err, "failed to tag registry images") } } @@ -169,14 +169,21 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu return err } + // the tagging library treats targets synonymously with code samples if specificTarget := environment.SpecifiedTarget(); specificTarget != "" { if target, ok := workflow.Targets[specificTarget]; ok { - sources = append(sources, target.Source) - targets = append(targets, specificTarget) + if source, ok := workflow.Sources[target.Source]; ok && source.Registry != nil { + sources = append(sources, target.Source) + } + + if target.CodeSamples != nil && target.CodeSamples.Registry != nil { + targets = append(targets, specificTarget) + } } } else { for name, target := range workflow.Targets { if releaseInfo, ok := latestRelease[target.Target]; ok { + var targetIsMatched bool releasePath, err := filepath.Rel(".", releaseInfo.Path) if err != nil { return err @@ -184,8 +191,7 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu // check for no SDK output path if (releasePath == "" || releasePath == ".") && target.Output == nil { - sources = append(sources, target.Source) - targets = append(targets, name) + targetIsMatched = true } if target.Output != nil { @@ -195,7 +201,16 @@ func addCurrentBranchTagging(g *git.Git, latestRelease map[string]releases.Langu } outputPath = filepath.Join(environment.GetWorkingDirectory(), outputPath) if outputPath == releasePath { + targetIsMatched = true + } + } + + if targetIsMatched { + if source, ok := workflow.Sources[target.Source]; ok && source.Registry != nil { sources = append(sources, target.Source) + } + + if target.CodeSamples != nil && target.CodeSamples.Registry != nil { targets = append(targets, name) } } diff --git a/internal/actions/runWorkflow.go b/internal/actions/runWorkflow.go index 72fef9d..d6ae506 100644 --- a/internal/actions/runWorkflow.go +++ b/internal/actions/runWorkflow.go @@ -6,6 +6,7 @@ import ( "strings" "github.com/google/go-github/v63/github" + "github.com/pkg/errors" "github.com/speakeasy-api/sdk-generation-action/internal/versionbumps" "github.com/speakeasy-api/versioning-reports/versioning" @@ -284,7 +285,7 @@ func finalize(inputs finalizeInputs) error { // add merging branch registry tag if err = addDirectModeBranchTagging(); err != nil { - logging.Debug("failed to tag registry images: %v", err) + return errors.Wrap(err, "failed to tag registry images") } inputs.Outputs["commit_hash"] = commitHash @@ -303,14 +304,24 @@ func addDirectModeBranchTagging() error { var sources, targets []string if specificTarget := environment.SpecifiedTarget(); specificTarget != "" { - if target, ok := wf.Targets[environment.SpecifiedTarget()]; ok { - sources = append(sources, target.Source) - targets = append(targets, specificTarget) + if target, ok := wf.Targets[specificTarget]; ok { + if source, ok := wf.Sources[target.Source]; ok && source.Registry != nil { + sources = append(sources, target.Source) + } + + if target.CodeSamples != nil && target.CodeSamples.Registry != nil { + targets = append(targets, specificTarget) + } } } else { for name, target := range wf.Targets { - sources = append(sources, target.Source) - targets = append(targets, name) + if source, ok := wf.Sources[target.Source]; ok && source.Registry != nil { + sources = append(sources, target.Source) + } + + if target.CodeSamples != nil && target.CodeSamples.Registry != nil { + targets = append(targets, name) + } } } if len(sources) > 0 && len(targets) > 0 && branch != "" {