Skip to content

Commit

Permalink
feat: update with newest sdk gen config
Browse files Browse the repository at this point in the history
  • Loading branch information
ryan-timothy-albert committed Nov 18, 2024
1 parent 91f0374 commit d3cd3ed
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 15 deletions.
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
27 changes: 21 additions & 6 deletions internal/actions/release.go
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -169,23 +169,29 @@ 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
}

// 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 {
Expand All @@ -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)
}
}
Expand Down
23 changes: 17 additions & 6 deletions internal/actions/runWorkflow.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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
Expand All @@ -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 != "" {
Expand Down

0 comments on commit d3cd3ed

Please sign in to comment.