diff --git a/internal/actions/release.go b/internal/actions/release.go index 9ba72665..d461f778 100644 --- a/internal/actions/release.go +++ b/internal/actions/release.go @@ -28,17 +28,20 @@ func Release() error { dir := "." usingReleasesMd := false - // TODO: Maybe instead check for workflow dispatch event - providesExplicitTarget := environment.SpecifiedTarget() != "" - if providesExplicitTarget { + var providesExplicitTarget bool + if specificTarget := environment.SpecifiedTarget(); specificTarget != "" { workflow, err := configuration.GetWorkflowAndValidateLanguages(true) if err != nil { return err } - if target, ok := workflow.Targets[environment.SpecifiedTarget()]; ok && target.Output != nil { - dir = strings.TrimPrefix(*target.Output, "./") + if target, ok := workflow.Targets[specificTarget]; ok { + if target.Output != nil { + dir = strings.TrimPrefix(*target.Output, "./") + } + + providesExplicitTarget = true + dir = filepath.Join(environment.GetWorkingDirectory(), dir) } - dir = filepath.Join(environment.GetWorkingDirectory(), dir) } if !providesExplicitTarget { @@ -97,10 +100,8 @@ func Release() error { return err } - if environment.CreateGitRelease() { - if err := g.CreateRelease(*latestRelease, outputs); err != nil { - return err - } + if err := g.CreateRelease(*latestRelease, outputs); err != nil { + return err } if err = setOutputs(outputs); err != nil { diff --git a/internal/actions/runWorkflow.go b/internal/actions/runWorkflow.go index 00dd0a96..1992c497 100644 --- a/internal/actions/runWorkflow.go +++ b/internal/actions/runWorkflow.go @@ -102,11 +102,12 @@ func RunWorkflow() error { anythingRegenerated := false + var releaseInfo releases.ReleasesInfo if runRes.GenInfo != nil { docVersion := runRes.GenInfo.OpenAPIDocVersion speakeasyVersion := runRes.GenInfo.SpeakeasyVersion - releaseInfo := releases.ReleasesInfo{ + releaseInfo = releases.ReleasesInfo{ ReleaseTitle: environment.GetInvokeTime().Format("2006-01-02 15:04:05"), DocVersion: docVersion, SpeakeasyVersion: speakeasyVersion, @@ -182,6 +183,7 @@ func RunWorkflow() error { LintingReportURL: runRes.LintingReportURL, ChangesReportURL: runRes.ChangesReportURL, OpenAPIChangeSummary: runRes.OpenAPIChangeSummary, + currentRelease: &releaseInfo, }); err != nil { return err } @@ -206,6 +208,7 @@ type finalizeInputs struct { ChangesReportURL string OpenAPIChangeSummary string VersioningReport *versioning.MergedVersionReport + currentRelease *releases.ReleasesInfo } // Sets outputs and creates or adds releases info @@ -235,17 +238,9 @@ func finalize(inputs finalizeInputs) error { return err } - var releaseInfo *releases.ReleasesInfo - if !inputs.SourcesOnly { - releaseInfo, err = getReleasesInfo() - if err != nil { - return err - } - } - if err := inputs.Git.CreateOrUpdatePR(git.PRInfo{ BranchName: branchName, - ReleaseInfo: releaseInfo, + ReleaseInfo: inputs.currentRelease, PreviousGenVersion: inputs.Outputs["previous_gen_version"], PR: pr, SourceGeneration: inputs.SourcesOnly, @@ -259,9 +254,13 @@ func finalize(inputs finalizeInputs) error { case environment.ModeDirect: var releaseInfo *releases.ReleasesInfo if !inputs.SourcesOnly { - releaseInfo, err = getReleasesInfo() - if err != nil { - return err + releaseInfo = inputs.currentRelease + // We still read from releases info for terraform generations since they use the goreleaser + if inputs.Outputs["terraform_regenerated"] == "true" { + releaseInfo, err = getReleasesInfo() + if err != nil { + return err + } } } @@ -270,7 +269,7 @@ func finalize(inputs finalizeInputs) error { return err } - if !inputs.SourcesOnly && environment.CreateGitRelease() { + if !inputs.SourcesOnly { if err := inputs.Git.CreateRelease(*releaseInfo, inputs.Outputs); err != nil { return err } diff --git a/internal/environment/environment.go b/internal/environment/environment.go index 662025d2..636ff5cb 100644 --- a/internal/environment/environment.go +++ b/internal/environment/environment.go @@ -193,10 +193,6 @@ func IsDocsGeneration() bool { return strings.Contains(languages, "docs") } -func CreateGitRelease() bool { - return IsLanguagePublished("php") || IsLanguagePublished("terraform") || IsLanguagePublished("swift") -} - func GetAccessToken() string { return os.Getenv("INPUT_GITHUB_ACCESS_TOKEN") } @@ -209,14 +205,6 @@ func GetInvokeTime() time.Time { return invokeTime } -func IsLanguagePublished(lang string) bool { - if lang == "go" || lang == "swift" { - return true - } - - return os.Getenv(fmt.Sprintf("INPUT_PUBLISH_%s", strings.ToUpper(lang))) == "true" -} - func GetOpenAPIDocAuthHeader() string { return os.Getenv("INPUT_OPENAPI_DOC_AUTH_HEADER") } diff --git a/internal/git/releases.go b/internal/git/releases.go index 1572260c..317d904a 100644 --- a/internal/git/releases.go +++ b/internal/git/releases.go @@ -18,6 +18,8 @@ import ( //go:embed goreleaser.yml var tfGoReleaserConfig string +const PublishingCompletedString = "Publishing Completed" + func (g *Git) SetReleaseToPublished(version, directory string) error { if g.repo == nil { return fmt.Errorf("repo not cloned") @@ -33,8 +35,8 @@ func (g *Git) SetReleaseToPublished(version, directory string) error { } if release != nil && release.ID != nil { - if release.Body != nil && !strings.Contains(*release.Body, "Publishing Completed") { - body := *release.Body + "\n\nPublishing Completed" + if release.Body != nil && !strings.Contains(*release.Body, PublishingCompletedString) { + body := *release.Body + "\n\n" + PublishingCompletedString release.Body = &body } @@ -101,9 +103,9 @@ func (g *Git) CreateRelease(releaseInfo releases.ReleasesInfo, outputs map[strin if err != nil { if release, _, err := g.client.Repositories.GetReleaseByTag(context.Background(), os.Getenv("GITHUB_REPOSITORY_OWNER"), getRepo(), *tagName); err == nil && release != nil { - if release.Body != nil && strings.Contains(*release.Body, "Publishing Completed") { - fmt.Println(fmt.Sprintf("a github release with tag %s already existing ... skipping publishing", *tagName)) - fmt.Println(fmt.Sprintf("to publish this version again delete the github tag and release")) + if release.Body != nil && strings.Contains(*release.Body, PublishingCompletedString) { + fmt.Println(fmt.Sprintf("a github release with tag %s has already been published ... skipping publishing", *tagName)) + fmt.Println(fmt.Sprintf("to publish this version again please check with your package managed delete the github tag and release")) if _, ok := outputs[fmt.Sprintf("publish_%s", lang)]; ok { outputs[fmt.Sprintf("publish_%s", lang)] = "false" } diff --git a/pkg/releases/releases.go b/pkg/releases/releases.go index cb439711..64a4183b 100644 --- a/pkg/releases/releases.go +++ b/pkg/releases/releases.go @@ -6,7 +6,6 @@ import ( "path" "path/filepath" "regexp" - "slices" "strings" config "github.com/speakeasy-api/sdk-gen-config" @@ -185,12 +184,6 @@ func GetReleaseInfoFromGenerationFiles(path string) (*ReleasesInfo, error) { } for lang, info := range cfgFile.Languages { - packageName := utils.GetPackageName(lang, &info) - // swift and go expects specific package formatting when writing a github release - if path != "" && path != "." && slices.Contains([]string{"go", "swift"}, lang) { - packageName = fmt.Sprintf("%s/%s", packageName, strings.TrimPrefix(path, "./")) - } - releaseInfo.Languages[lang] = LanguageReleaseInfo{ PackageName: utils.GetPackageName(lang, &info), Version: lockFile.Management.ReleaseVersion,