Skip to content

Commit 79c4f50

Browse files
feat: sdk changelog (#1495)
Add new changelogs
1 parent 711ddbb commit 79c4f50

File tree

8 files changed

+179
-23
lines changed

8 files changed

+179
-23
lines changed

go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ require (
3636
github.com/sethvargo/go-githubactions v1.1.0
3737
github.com/speakeasy-api/huh v1.1.2
3838
github.com/speakeasy-api/openapi v0.2.4
39-
github.com/speakeasy-api/openapi-generation/v2 v2.673.1
39+
github.com/speakeasy-api/openapi-generation/v2 v2.673.2
4040
github.com/speakeasy-api/openapi-overlay v0.10.3
41-
github.com/speakeasy-api/sdk-gen-config v1.31.2
41+
github.com/speakeasy-api/sdk-gen-config v1.31.3
4242
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.26.7
4343
github.com/speakeasy-api/speakeasy-core v0.20.4
4444
github.com/speakeasy-api/speakeasy-proxy v0.0.2
45-
github.com/speakeasy-api/versioning-reports v0.6.0
45+
github.com/speakeasy-api/versioning-reports v0.6.1
4646
github.com/spf13/cobra v1.9.1
4747
github.com/spf13/pflag v1.0.6
4848
github.com/spf13/viper v1.19.0

go.sum

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,12 @@ github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE
228228
github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI=
229229
github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg=
230230
github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU=
231+
github.com/gkampitakis/ciinfo v0.3.2 h1:JcuOPk8ZU7nZQjdUhctuhQofk7BGHuIy0c9Ez8BNhXs=
232+
github.com/gkampitakis/ciinfo v0.3.2/go.mod h1:1NIwaOcFChN4fa/B0hEBdAb6npDlFL8Bwx4dfRLRqAo=
233+
github.com/gkampitakis/go-diff v1.3.2 h1:Qyn0J9XJSDTgnsgHRdz9Zp24RaJeKMUHg2+PDZZdC4M=
234+
github.com/gkampitakis/go-diff v1.3.2/go.mod h1:LLgOrpqleQe26cte8s36HTWcTmMEur6OPYerdAAS9tk=
235+
github.com/gkampitakis/go-snaps v0.5.13 h1:Hhjmvv1WboSCxkR9iU2mj5PQ8tsz/y8ECGrIbjjPF8Q=
236+
github.com/gkampitakis/go-snaps v0.5.13/go.mod h1:HNpx/9GoKisdhw9AFOBT1N7DBs9DiHo/hGheFGBZ+mc=
231237
github.com/gliderlabs/ssh v0.3.7 h1:iV3Bqi942d9huXnzEF2Mt+CY9gLu8DNM4Obd+8bODRE=
232238
github.com/gliderlabs/ssh v0.3.7/go.mod h1:zpHEXBstFnQYtGnB8k8kQLol82umzn/2/snG7alWVD8=
233239
github.com/go-chi/chi/v5 v5.0.7 h1:rDTPXLDHGATaeHvVlLcR4Qe0zftYethFucbjVQ1PxU8=
@@ -266,6 +272,8 @@ github.com/go-test/deep v1.0.8 h1:TDsG77qcSprGbC6vTN8OuXp5g+J+b5Pcguhf7Zt61VM=
266272
github.com/go-test/deep v1.0.8/go.mod h1:5C2ZWiW0ErCdrYzpqxLbTX7MG14M9iiw8DgHncVwcsE=
267273
github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
268274
github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
275+
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
276+
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
269277
github.com/gofrs/flock v0.12.1 h1:MTLVXXHf8ekldpJk3AKicLij9MdwOWkZ+a/jHHZby9E=
270278
github.com/gofrs/flock v0.12.1/go.mod h1:9zxTsyu5xtJ9DK+1tFZyibEV7y3uwDxPPfbxeeHCoD0=
271279
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
@@ -402,6 +410,8 @@ github.com/magiconair/properties v1.8.9 h1:nWcCbLq1N2v/cpNsy5WvQ37Fb+YElfq20WJ/a
402410
github.com/magiconair/properties v1.8.9/go.mod h1:Dhd985XPs7jluiymwWYZ0G4Z61jb3vdS329zhj2hYo0=
403411
github.com/mailru/easyjson v0.9.0 h1:PrnmzHw7262yW8sTBwxi1PdJA3Iw/EKBa8psRf7d9a4=
404412
github.com/mailru/easyjson v0.9.0/go.mod h1:1+xMtQp2MRNVL/V1bOzuP3aP8VNwRW55fQUto+XFtTU=
413+
github.com/maruel/natural v1.1.1 h1:Hja7XhhmvEFhcByqDoHz9QZbkWey+COd9xWfCfn1ioo=
414+
github.com/maruel/natural v1.1.1/go.mod h1:v+Rfd79xlw1AgVBjbO0BEQmptqb5HvL/k9GRHB7ZKEg=
405415
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
406416
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
407417
github.com/mattn/go-colorable v0.1.11/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4=
@@ -591,12 +601,12 @@ github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed h1:PL/kpBY5vkBm
591601
github.com/speakeasy-api/libopenapi v0.21.9-fixhiddencomps-fixed/go.mod h1:Gc8oQkjr2InxwumK0zOBtKN9gIlv9L2VmSVIUk2YxcU=
592602
github.com/speakeasy-api/openapi v0.2.4 h1:XfIiVafDfq2Q3YtpjJPxjXBG9qUdXc/fKjEu4E5TyZQ=
593603
github.com/speakeasy-api/openapi v0.2.4/go.mod h1:vqBYh4eIgL9mVqrtdbuttji0ggR3/4xqU1ief4rjzY4=
594-
github.com/speakeasy-api/openapi-generation/v2 v2.673.1 h1:xMrm1BqP4rYjBK3khyJ9z7B0hLUvtJ0QLAgLz0ZjB2I=
595-
github.com/speakeasy-api/openapi-generation/v2 v2.673.1/go.mod h1:OWCJvRiASJRaTJFhWG6QfO1qGpjiO1KVmNVqcL3Oc+o=
604+
github.com/speakeasy-api/openapi-generation/v2 v2.673.2 h1:vyNe7czUBjYePtnnfpnvwSGE4oYFUrwdcaaQfCkDXk8=
605+
github.com/speakeasy-api/openapi-generation/v2 v2.673.2/go.mod h1:eO9cNLEsEpwH3l34GSGMijJvVUn92eeFh2SPJ6iNzgw=
596606
github.com/speakeasy-api/openapi-overlay v0.10.3 h1:70een4vwHyslIp796vM+ox6VISClhtXsCjrQNhxwvWs=
597607
github.com/speakeasy-api/openapi-overlay v0.10.3/go.mod h1:RJjV0jbUHqXLS0/Mxv5XE7LAnJHqHw+01RDdpoGqiyY=
598-
github.com/speakeasy-api/sdk-gen-config v1.31.2 h1:5xquHCkMr/IVt/EUfU0wsu8pj5EFFm3Q7/398kZOCWI=
599-
github.com/speakeasy-api/sdk-gen-config v1.31.2/go.mod h1:e9PjnCRHGa4K4EFKVU+kKmihOZjJ2V4utcU+274+bnQ=
608+
github.com/speakeasy-api/sdk-gen-config v1.31.3 h1:RDFVcOMzb9rysPhXLFOGEKlX70cjQzRnlyXP5NnL/iY=
609+
github.com/speakeasy-api/sdk-gen-config v1.31.3/go.mod h1:e9PjnCRHGa4K4EFKVU+kKmihOZjJ2V4utcU+274+bnQ=
600610
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.26.7 h1:SoWZkRlpFlv8qibCfXWrBZay1JeLS9uqJ+1cu+DFgXo=
601611
github.com/speakeasy-api/speakeasy-client-sdk-go/v3 v3.26.7/go.mod h1:k9JD6Rj0+Iizc5COoLZHyRIOGGITpKZ2qBuFFO8SqNI=
602612
github.com/speakeasy-api/speakeasy-core v0.20.4 h1:NItl2OHCHMdZcyhYGfOEZkvTxLYxnlJUAPGSoFBzMIw=
@@ -607,8 +617,8 @@ github.com/speakeasy-api/speakeasy-proxy v0.0.2 h1:u4rQ8lXvuYRCSxiLQGb5JxkZRwNID
607617
github.com/speakeasy-api/speakeasy-proxy v0.0.2/go.mod h1:cvMxdIEPYAvXS5mpYMU6CuJRPQnhq4gRXKE7xeCP/V0=
608618
github.com/speakeasy-api/speakeasy-schemas v1.3.0 h1:7Arm2d0/K9owEBQPmNon1KPERmf58g0Eg/NmPgXaEY0=
609619
github.com/speakeasy-api/speakeasy-schemas v1.3.0/go.mod h1:g6NfrOjYLCJZp81ZLY2ksF7afC9BW9bL4Bg1V1oAFlw=
610-
github.com/speakeasy-api/versioning-reports v0.6.0 h1:oLokEQ7xnDXqWAQk60Sk+ifwYaRbq3BrLX2KyT8gWxE=
611-
github.com/speakeasy-api/versioning-reports v0.6.0/go.mod h1:LW5FABrvi5SBbeiD3HJYw0JZYe6Rw2Xna59pFJ2BmLI=
620+
github.com/speakeasy-api/versioning-reports v0.6.1 h1:pvuvA1IFO7PVlpdFh7J2Y3hENDzhISFdNy0NVg/Cxb4=
621+
github.com/speakeasy-api/versioning-reports v0.6.1/go.mod h1:LW5FABrvi5SBbeiD3HJYw0JZYe6Rw2Xna59pFJ2BmLI=
612622
github.com/spewerspew/spew v0.0.0-20230513223542-89b69fbbe2bd h1:csraKifkLpqDClUIbFTetjtraueL1KUhKBm6okL+ug4=
613623
github.com/spewerspew/spew v0.0.0-20230513223542-89b69fbbe2bd/go.mod h1:cyGycBxnlCATLUv5jtPwaHnkiYomNWzXQougLmaCTzU=
614624
github.com/spf13/afero v1.11.0 h1:WJQKhtpdm3v2IzqG8VMqrr6Rf3UYpEF239Jy9wNepM8=
@@ -647,6 +657,14 @@ github.com/testcontainers/testcontainers-go v0.34.0 h1:5fbgF0vIN5u+nD3IWabQwRybu
647657
github.com/testcontainers/testcontainers-go v0.34.0/go.mod h1:6P/kMkQe8yqPHfPWNulFGdFHTD8HB2vLq/231xY2iPQ=
648658
github.com/tetratelabs/wazero v1.8.2 h1:yIgLR/b2bN31bjxwXHD8a3d+BogigR952csSDdLYEv4=
649659
github.com/tetratelabs/wazero v1.8.2/go.mod h1:yAI0XTsMBhREkM/YDAK/zNou3GoiAce1P6+rp/wQhjs=
660+
github.com/tidwall/gjson v1.18.0 h1:FIDeeyB800efLX89e5a8Y0BNH+LOngJyGrIWxG2FKQY=
661+
github.com/tidwall/gjson v1.18.0/go.mod h1:/wbyibRr2FHMks5tjHJ5F8dMZh3AcwJEMf5vlfC0lxk=
662+
github.com/tidwall/match v1.1.1 h1:+Ho715JplO36QYgwN9PGYNhgZvoUSc9X2c80KVTi+GA=
663+
github.com/tidwall/match v1.1.1/go.mod h1:eRSPERbgtNPcGhD8UCthc6PmLEQXEWd3PRB5JTxsfmM=
664+
github.com/tidwall/pretty v1.2.1 h1:qjsOFOWWQl+N3RsoF5/ssm1pHmJJwhjlSbZ51I6wMl4=
665+
github.com/tidwall/pretty v1.2.1/go.mod h1:ITEVvHYasfjBbM0u2Pg8T2nJnzm8xPwvNhhsoaGGjNU=
666+
github.com/tidwall/sjson v1.2.5 h1:kLy8mja+1c9jlljvWTlSazM7cKDRfJuR/bOJhcY5NcY=
667+
github.com/tidwall/sjson v1.2.5/go.mod h1:Fvgq9kS/6ociJEDnK0Fk1cpYF4FIW6ZF7LAe+6jwd28=
650668
github.com/tinylib/msgp v1.1.6 h1:i+SbKraHhnrf9M5MYmvQhFnbLhAXSDWF8WWsuyRdocw=
651669
github.com/tinylib/msgp v1.1.6/go.mod h1:75BAfg2hauQhs3qedfdDZmWAPcFMAvJE5b9rGOMufyw=
652670
github.com/tklauser/go-sysconf v0.3.12 h1:0QaGUFOdQaIVdPgfITYzaTegZvdCjmYO52cSFAEVmqU=

internal/github/github.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,9 +130,9 @@ func GenerateChangesSummary(ctx context.Context, url string, summary changes.Sum
130130
}
131131
prMD := ""
132132
if len(summary.Text) > 0 {
133-
prMD = "## OpenAPI Change Summary\n" + summary.Text + "\n"
133+
prMD = "<details>\n<summary>## OpenAPI Change Summary</summary>\n" + summary.Text + "\n" + "</details>"
134134
} else {
135-
prMD = "## OpenAPI Change Summary\nNo specification changes\n"
135+
prMD = "<details open>\n<summary>## OpenAPI Change Summary</summary>\nNo specification changes\n" + "</details>"
136136
}
137137

138138
// New form -- the above form is deprecated.

internal/run/source.go

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ type SourceResult struct {
5858
MergeResult MergeResult
5959
CLIVersion string
6060
// The path to the output OAS spec
61-
OutputPath string
61+
OutputPath string
62+
oldSpecPath string
63+
newSpecPath string
6264
}
6365

6466
type LintingError struct {
@@ -194,11 +196,14 @@ func (w *Workflow) RunSource(ctx context.Context, parentStep *workflowTracking.W
194196
// If the source has a previous tracked revision, compute changes against it
195197
if w.lockfileOld != nil && !w.SkipChangeReport {
196198
if targetLockOld, ok := w.lockfileOld.Targets[targetID]; ok && !utils.IsZeroTelemetryOrganization(ctx) {
197-
sourceRes.ChangeReport, err = w.computeChanges(ctx, rootStep, targetLockOld, currentDocument)
199+
changesComputed, err := w.computeChanges(ctx, rootStep, targetLockOld, currentDocument)
198200
if err != nil {
199201
// Don't fail the whole workflow if this fails
200202
logger.Warnf("failed to compute OpenAPI changes: %s", err.Error())
201203
}
204+
sourceRes.ChangeReport = changesComputed.report
205+
sourceRes.newSpecPath = currentDocument
206+
sourceRes.oldSpecPath = changesComputed.oldSpecPath
202207
}
203208
}
204209

internal/run/sourceTracking.go

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ import (
2929
"github.com/speakeasy-api/speakeasy/registry"
3030
)
3131

32+
type changesComputed struct {
33+
report *reports.ReportResult
34+
oldSpecPath string
35+
newSpecPath string
36+
}
37+
3238
// embedSourceConfig implements bundler.EmbedSourceConfig interface
3339
type embedSourceConfig struct {
3440
originalSource *workflow.Source
@@ -72,11 +78,16 @@ func createLocalizedSource(originalSource workflow.Source, sourceResult *SourceR
7278
return &localizedSource
7379
}
7480

75-
func (w *Workflow) computeChanges(ctx context.Context, rootStep *workflowTracking.WorkflowStep, targetLock workflow.TargetLock, newDocPath string) (r *reports.ReportResult, err error) {
81+
func (w *Workflow) computeChanges(ctx context.Context, rootStep *workflowTracking.WorkflowStep, targetLock workflow.TargetLock, newDocPath string) (changesComputed, error) {
7682
changesStep := rootStep.NewSubstep("Computing Document Changes")
83+
var err error = nil
84+
var r *reports.ReportResult = nil
85+
var computedChanges changesComputed = changesComputed{
86+
report: r,
87+
}
7788
if !registry.IsRegistryEnabled(ctx) {
7889
changesStep.Skip("API Registry not enabled")
79-
return
90+
return computedChanges, err
8091
}
8192

8293
defer func() {
@@ -99,36 +110,39 @@ func (w *Workflow) computeChanges(ctx context.Context, rootStep *workflowTrackin
99110
} else {
100111
changesStep.Skip("no previous revision found")
101112

102-
return
113+
return computedChanges, err
103114
}
104115

105116
changesStep.NewSubstep("Downloading prior revision")
106117

107118
d := workflow.Document{Location: workflow.LocationString(oldRegistryLocation)}
108119
oldDocPath, err := registry.ResolveSpeakeasyRegistryBundle(ctx, d, workflow.GetTempDir())
109120
if err != nil {
110-
return
121+
return computedChanges, err
111122
}
112123

124+
computedChanges.oldSpecPath = oldDocPath.LocalFilePath
125+
113126
changesStep.NewSubstep("Computing changes")
114127

115128
c, err := changes.GetChanges(ctx, oldDocPath.LocalFilePath, newDocPath)
129+
116130
if err != nil {
117-
return r, fmt.Errorf("error computing changes: %w", err)
131+
return computedChanges, fmt.Errorf("error computing changes: %w", err)
118132
}
119133

120134
changesStep.NewSubstep("Uploading changes report")
121135
report, err := reports.UploadReport(ctx, c.GetHTMLReport(), shared.TypeChanges)
122136
if err != nil {
123-
return r, fmt.Errorf("failed to persist report: %w", err)
137+
return computedChanges, fmt.Errorf("failed to persist report: %w", err)
124138
}
125-
r = &report
139+
computedChanges.report = &report
126140

127-
log.From(ctx).Info(r.Message)
141+
log.From(ctx).Info(computedChanges.report.Message)
128142

129143
summary, err := c.GetSummary()
130144
if err != nil || summary == nil {
131-
return r, fmt.Errorf("failed to get report summary: %w", err)
145+
return computedChanges, fmt.Errorf("failed to get report summary: %w", err)
132146
}
133147

134148
// Do not write github action changes if we have already processed this source
@@ -140,7 +154,7 @@ func (w *Workflow) computeChanges(ctx context.Context, rootStep *workflowTrackin
140154
w.computedChanges[targetLock.Source] = true
141155

142156
changesStep.SucceedWorkflow()
143-
return
157+
return computedChanges, err
144158
}
145159

146160
func (w *Workflow) snapshotSource(ctx context.Context, parentStep *workflowTracking.WorkflowStep, sourceID string, source workflow.Source, sourceResult *SourceResult) (err error) {

internal/run/target.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package run
33
import (
44
"context"
55
"fmt"
6+
"os"
67
"path/filepath"
78
"strings"
89

@@ -21,6 +22,7 @@ import (
2122
"github.com/speakeasy-api/speakeasy/internal/git"
2223
"github.com/speakeasy-api/speakeasy/internal/links"
2324
"github.com/speakeasy-api/speakeasy/internal/log"
25+
"github.com/speakeasy-api/speakeasy/internal/sdkchangelog"
2426
"github.com/speakeasy-api/speakeasy/internal/sdkgen"
2527
"github.com/speakeasy-api/speakeasy/internal/utils"
2628
"github.com/speakeasy-api/speakeasy/internal/validation"
@@ -171,6 +173,25 @@ func (w *Workflow) runTarget(ctx context.Context, target string) (*SourceResult,
171173
}()
172174
}
173175

176+
changelogContent := ""
177+
if os.Getenv("SDK_CHANGELOG_JULY_2025") == "true" {
178+
// Old & new spec and other details are updated in RunSource method
179+
log.From(ctx).Infof("Calculating changelog for SDK %s SDK", utils.CapitalizeFirst(t.Target))
180+
changelogContent, err = sdkchangelog.ComputeAndStoreSDKChangelog(ctx, sdkchangelog.Requirements{
181+
OldSpecPath: w.SourceResults[t.Source].oldSpecPath,
182+
NewSpecPath: w.SourceResults[t.Source].newSpecPath,
183+
OutDir: outDir,
184+
Lang: t.Target,
185+
Verbose: w.Verbose,
186+
Target: target,
187+
})
188+
if err != nil {
189+
// Dont error out so that we don't block generation
190+
log.From(ctx).Warnf("Error computing SDK changelog: %s", err.Error())
191+
}
192+
log.From(ctx).Infof("Calculating changelog for SDK %s SDK succeeded", utils.CapitalizeFirst(t.Target))
193+
}
194+
174195
genStep := rootStep.NewSubstep(fmt.Sprintf("Generating %s SDK", utils.CapitalizeFirst(t.Target)))
175196
go genStep.ListenForSubsteps(logListener)
176197

@@ -198,6 +219,7 @@ func (w *Workflow) runTarget(ctx context.Context, target string) (*SourceResult,
198219
SkipVersioning: w.SkipVersioning,
199220
CancellableGeneration: w.CancellableGeneration,
200221
StreamableGeneration: w.StreamableGeneration,
222+
ReleaseNotes: changelogContent,
201223
},
202224
)
203225
if err != nil {
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package sdkchangelog
2+
3+
import (
4+
"context"
5+
"fmt"
6+
7+
changes "github.com/speakeasy-api/openapi-generation/v2/pkg/changes"
8+
"github.com/speakeasy-api/speakeasy/internal/log"
9+
"github.com/speakeasy-api/versioning-reports/versioning"
10+
)
11+
12+
type Requirements struct {
13+
OldSpecPath string
14+
NewSpecPath string
15+
OutDir string
16+
Lang string
17+
Verbose bool
18+
Target string
19+
}
20+
21+
func ComputeAndStoreSDKChangelog(ctx context.Context, changelogRequirements Requirements) (string, error) {
22+
// Check if we have valid spec paths before proceeding
23+
if changelogRequirements.OldSpecPath == "" || changelogRequirements.NewSpecPath == "" {
24+
// If we don't have valid spec paths, skip changelog generation
25+
log.From(ctx).Infof("Skipping SDK changelog generation - missing spec paths (old: %s, new: %s)",
26+
changelogRequirements.OldSpecPath, changelogRequirements.NewSpecPath)
27+
return "", nil
28+
}
29+
30+
oldConfig, newConfig := changes.CreateConfigsFromSpecPaths(changes.SpecComparison{
31+
OldSpecPath: changelogRequirements.OldSpecPath,
32+
NewSpecPath: changelogRequirements.NewSpecPath,
33+
OutputDir: changelogRequirements.OutDir,
34+
Lang: changelogRequirements.Lang,
35+
Verbose: changelogRequirements.Verbose,
36+
Logger: log.From(ctx),
37+
})
38+
39+
diff := changes.Changes(oldConfig, newConfig)
40+
changelogContent, err := storeSDKChangelogForPullRequestDescription(ctx, changelogRequirements.Target, diff)
41+
if err != nil {
42+
// Swallow error so that we dont block generation
43+
log.From(ctx).Warnf("Error generating new changelog: %s", err.Error())
44+
return "", err
45+
}
46+
return changelogContent, nil
47+
}
48+
49+
// target refers to workflow target name
50+
// The version reports written here are read in sdk-generation-action to generate commit message
51+
// and PR description. PR description comes from PRReport and Commit message comes from CommitReport
52+
func storeSDKChangelogForPullRequestDescription(ctx context.Context, target string, diff changes.SDKDiff) (string, error) {
53+
// Add Release message
54+
changelogContent := changes.ToMarkdown(diff)
55+
err := storeKeyValueForPullRequestDescription(ctx, fmt.Sprintf("SDK_CHANGELOG_%s", target), changelogContent, "pr_report")
56+
if err != nil {
57+
log.From(ctx).Warnf("error computing changes: %s", err.Error())
58+
return "", err
59+
}
60+
61+
// Add Commit message
62+
err = storeKeyValueForPullRequestDescription(ctx, fmt.Sprintf("COMMIT_MESSAGE_%s", target), changelogContent, "commit_report")
63+
if err != nil {
64+
log.From(ctx).Warnf("error computing changes: %s", err.Error())
65+
return "", err
66+
}
67+
return changelogContent, nil
68+
}
69+
70+
// A bit of a hack for being able to set and get arbitrary keys in a temp file for populating PR description
71+
// Using version-report machinery
72+
func storeKeyValueForPullRequestDescription(ctx context.Context, key string, report string, reportType string) error {
73+
if reportType != "pr_report" && reportType != "commit_report" {
74+
return fmt.Errorf("unknown report type passed -> %s", reportType)
75+
}
76+
versionReport := versioning.VersionReport{
77+
Key: key,
78+
// Lowest priority
79+
Priority: 1,
80+
MustGenerate: false,
81+
BumpType: versioning.BumpNone,
82+
NewVersion: "",
83+
}
84+
if reportType == "pr_report" {
85+
versionReport.PRReport += report
86+
} else if reportType == "commit_report" {
87+
versionReport.CommitReport += report
88+
}
89+
err := versioning.AddVersionReport(ctx, versionReport)
90+
if err != nil {
91+
log.From(ctx).Warnf("failed to add version report. key: %s, report: %s, error: %s", key, report, err)
92+
return err
93+
}
94+
return nil
95+
}

internal/sdkgen/sdkgen.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ type GenerateOptions struct {
7070

7171
CancellableGeneration *CancellableGeneration
7272
StreamableGeneration *StreamableGeneration
73+
ReleaseNotes string
7374
}
7475

7576
func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, error) {
@@ -145,6 +146,7 @@ func Generate(ctx context.Context, opts GenerateOptions) (*GenerationAccess, err
145146
generate.WithRepoDetails(opts.Repo, opts.RepoSubDir),
146147
generate.WithCLIVersion(opts.CLIVersion),
147148
generate.WithForceGeneration(),
149+
generate.WithChangelogReleaseNotes(opts.ReleaseNotes),
148150
}
149151

150152
if opts.Verbose {

0 commit comments

Comments
 (0)