Skip to content

Commit 3806130

Browse files
authored
chore: migrate to new artifact api (#1077)
1 parent d224538 commit 3806130

31 files changed

+2494
-392
lines changed

Makefile

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,22 +150,27 @@ lint: ## Run lint on the package
150150
}
151151

152152

153-
apidiff: ## Display API incompabilities
153+
apidiff: ## Display API incompabilities (base=main to change base branch)
154154
@if ! command -v apidiff > /dev/null; then \
155155
printf "\033[31;1mERROR: apidiff not installed\033[0m\n"; \
156-
printf "go get -u github.com/go-modules-by-example/apidiff\n"; \
157-
printf "\033[2m→ https://github.com/go-modules-by-example/index/blob/master/019_apidiff/README.md\033[0m\n\n"; \
156+
printf "go install golang.org/x/exp/cmd/apidiff@latest\n"; \
157+
printf "\033[2m→ https://pkg.go.dev/golang.org/x/exp/cmd/apidiff\033[0m\n\n"; \
158158
false; \
159159
fi;
160-
@rm -rf tmp/apidiff-OLD tmp/apidiff-NEW
161-
@git clone --quiet --local .git/ tmp/apidiff-OLD
160+
$(eval base ?= main)
161+
@rm -rf tmp/apidiff-OLD tmp/apidiff-NEW tmp/apidiff-OLD.export 2>/dev/null || true
162+
@git clone --quiet --local --branch $(base) .git/ tmp/apidiff-OLD
162163
@mkdir -p tmp/apidiff-NEW
163164
@tar -c --exclude .git --exclude tmp --exclude cmd . | tar -x -C tmp/apidiff-NEW
164165
@printf "\033[2m→ Running apidiff...\033[0m\n"
165-
@pritnf "tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi\n"
166+
@printf "Comparing OLD ($(base)) esapi NEW (working tree) esapi\n"
166167
@{ \
167168
set -e ; \
168-
output=$$(apidiff tmp/apidiff-OLD/esapi tmp/apidiff-NEW/esapi); \
169+
cd tmp/apidiff-OLD && apidiff -w $(PWD)/tmp/apidiff-OLD.export github.com/elastic/go-elasticsearch/v9/esapi; \
170+
}
171+
@{ \
172+
set -e ; \
173+
output=$$(apidiff $(PWD)/tmp/apidiff-OLD.export ./esapi); \
169174
printf "\n$$output\n\n"; \
170175
if echo $$output | grep -i -e 'incompatible' - > /dev/null 2>&1; then \
171176
printf "\n\033[31;1mFAILURE\033[0m\n\n"; \

internal/build/cmd/generate/commands/genexamples/model.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ func init() {
3030
}
3131

3232
// EnabledFiles contains a list of files where documentation should be generated.
33-
//
3433
var EnabledFiles = []string{
3534
"aggregations/bucket/datehistogram-aggregation.asciidoc",
3635
"aggregations/bucket/filter-aggregation.asciidoc",
@@ -103,7 +102,6 @@ var (
103102
// Example represents the code example in documentation.
104103
//
105104
// See: https://github.com/elastic/built-docs/blob/master/raw/en/elasticsearch/reference/master/alternatives_report.json
106-
//
107105
type Example struct {
108106
SourceLocation struct {
109107
File string
@@ -115,7 +113,6 @@ type Example struct {
115113
}
116114

117115
// IsEnabled returns true when the example should be processed.
118-
//
119116
func (e Example) IsEnabled() bool {
120117
// TODO(karmi): Use "filepatch.Match()" to support glob patterns
121118

@@ -129,38 +126,32 @@ func (e Example) IsEnabled() bool {
129126
}
130127

131128
// IsExecutable returns true when the example contains a request.
132-
//
133129
func (e Example) IsExecutable() bool {
134130
return reHTTPMethod.MatchString(e.Source)
135131
}
136132

137133
// IsTranslated returns true when the example can be converted to Go source code.
138-
//
139134
func (e Example) IsTranslated() bool {
140135
return Translator{Example: e}.IsTranslated()
141136
}
142137

143138
// ID returns example identifier.
144-
//
145139
func (e Example) ID() string {
146140
return fmt.Sprintf("%s:%d", e.SourceLocation.File, e.SourceLocation.Line)
147141
}
148142

149143
// Chapter returns the example chapter.
150-
//
151144
func (e Example) Chapter() string {
152145
r := strings.NewReplacer("/", "_", "-", "_", ".asciidoc", "")
153146
return r.Replace(e.SourceLocation.File)
154147
}
155148

156149
// GithubURL returns a link for the example source.
157-
//
158150
func (e Example) GithubURL() string {
159151
return fmt.Sprintf("https://github.com/elastic/elasticsearch/blob/master/docs/reference/%s#L%d", e.SourceLocation.File, e.SourceLocation.Line)
160152
}
161153

162154
// Commands returns the list of commands from source.
163-
//
164155
func (e Example) Commands() ([]string, error) {
165156
var (
166157
buf strings.Builder
@@ -200,7 +191,6 @@ func (e Example) Commands() ([]string, error) {
200191
}
201192

202193
// Translated returns the code translated from Console to Go.
203-
//
204194
func (e Example) Translated() (string, error) {
205195
return Translator{Example: e}.Translate()
206196
}

internal/build/cmd/generate/commands/genexamples/translator.go

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ var ConsoleToGo = []TranslateRule{
8282
if err != nil {
8383
return "", fmt.Errorf("error converting params to arguments: %s", err)
8484
}
85-
fmt.Fprintf(&src, args)
85+
fmt.Fprint(&src, args)
8686
}
8787

8888
src.WriteString(")")
@@ -115,7 +115,7 @@ var ConsoleToGo = []TranslateRule{
115115
if err != nil {
116116
return "", fmt.Errorf("error converting params to arguments: %s", err)
117117
}
118-
fmt.Fprintf(&src, args)
118+
fmt.Fprint(&src, args)
119119
}
120120

121121
src.WriteString(")")
@@ -148,7 +148,7 @@ var ConsoleToGo = []TranslateRule{
148148
if err != nil {
149149
return "", fmt.Errorf("error converting params to arguments: %s", err)
150150
}
151-
fmt.Fprintf(&src, args)
151+
fmt.Fprint(&src, args)
152152
}
153153

154154
src.WriteString(")")
@@ -182,7 +182,7 @@ var ConsoleToGo = []TranslateRule{
182182
if err != nil {
183183
return "", fmt.Errorf("error converting params to arguments: %s", err)
184184
}
185-
fmt.Fprintf(&src, args)
185+
fmt.Fprint(&src, args)
186186
}
187187

188188
src.WriteString(")")
@@ -227,7 +227,7 @@ var ConsoleToGo = []TranslateRule{
227227
if err != nil {
228228
return "", fmt.Errorf("error converting params to arguments: %s", err)
229229
}
230-
fmt.Fprintf(&src, args)
230+
fmt.Fprint(&src, args)
231231
}
232232

233233
src.WriteString(")")
@@ -267,7 +267,7 @@ var ConsoleToGo = []TranslateRule{
267267
if err != nil {
268268
return "", fmt.Errorf("error converting params to arguments: %s", err)
269269
}
270-
fmt.Fprintf(&src, args)
270+
fmt.Fprint(&src, args)
271271
}
272272

273273
src.WriteString("\t)")
@@ -411,7 +411,7 @@ var ConsoleToGo = []TranslateRule{
411411
if err != nil {
412412
return "", fmt.Errorf("error converting params to arguments: %s", err)
413413
}
414-
fmt.Fprintf(&src, args)
414+
fmt.Fprint(&src, args)
415415
}
416416

417417
src.WriteString("\tes." + apiName + ".WithPretty(),\n")
@@ -445,7 +445,7 @@ var ConsoleToGo = []TranslateRule{
445445
if err != nil {
446446
return "", fmt.Errorf("error converting params to arguments: %s", err)
447447
}
448-
fmt.Fprintf(&src, args)
448+
fmt.Fprint(&src, args)
449449
}
450450

451451
src.WriteString(")")
@@ -601,7 +601,7 @@ var ConsoleToGo = []TranslateRule{
601601
if err != nil {
602602
return "", fmt.Errorf("error converting params to arguments: %s", err)
603603
}
604-
fmt.Fprintf(&src, args)
604+
fmt.Fprint(&src, args)
605605
}
606606
}
607607

@@ -634,7 +634,7 @@ var ConsoleToGo = []TranslateRule{
634634
if err != nil {
635635
return "", fmt.Errorf("error converting params to arguments: %s", err)
636636
}
637-
fmt.Fprintf(&src, args)
637+
fmt.Fprint(&src, args)
638638
}
639639

640640
src.WriteString(")")
@@ -673,7 +673,7 @@ var ConsoleToGo = []TranslateRule{
673673
if err != nil {
674674
return "", fmt.Errorf("error converting params to arguments: %s", err)
675675
}
676-
fmt.Fprintf(&src, args)
676+
fmt.Fprint(&src, args)
677677
}
678678
} else {
679679
fmt.Fprintf(&src, "%q", matches[1])
@@ -792,7 +792,7 @@ var ConsoleToGo = []TranslateRule{
792792
if err != nil {
793793
return "", fmt.Errorf("error converting params to arguments: %s", err)
794794
}
795-
fmt.Fprintf(&src, args)
795+
fmt.Fprint(&src, args)
796796
} else {
797797
fmt.Fprintf(&src, "[]string{%q}", matches[1])
798798
}
@@ -895,7 +895,7 @@ var ConsoleToGo = []TranslateRule{
895895
if err != nil {
896896
return "", fmt.Errorf("error converting params to arguments: %s", err)
897897
}
898-
fmt.Fprintf(&src, args)
898+
fmt.Fprint(&src, args)
899899
}
900900

901901
src.WriteString(")")
@@ -928,7 +928,7 @@ var ConsoleToGo = []TranslateRule{
928928
if err != nil {
929929
return "", fmt.Errorf("error converting params to arguments: %s", err)
930930
}
931-
fmt.Fprintf(&src, args)
931+
fmt.Fprint(&src, args)
932932
}
933933

934934
src.WriteString(")")
@@ -969,7 +969,7 @@ var ConsoleToGo = []TranslateRule{
969969
if err != nil {
970970
return "", fmt.Errorf("error converting params to arguments: %s", err)
971971
}
972-
fmt.Fprintf(&src, args)
972+
fmt.Fprint(&src, args)
973973

974974
src.WriteString("\tes." + apiName + ".WithPretty(),\n")
975975
}
@@ -1012,7 +1012,7 @@ var ConsoleToGo = []TranslateRule{
10121012
if err != nil {
10131013
return "", fmt.Errorf("error converting params to arguments: %s", err)
10141014
}
1015-
fmt.Fprintf(&src, args)
1015+
fmt.Fprint(&src, args)
10161016

10171017
src.WriteString("\tes." + apiName + ".WithPretty(),\n")
10181018
}
@@ -1194,7 +1194,7 @@ var ConsoleToGo = []TranslateRule{
11941194
if err != nil {
11951195
return "", fmt.Errorf("error converting params to arguments: %s", err)
11961196
}
1197-
fmt.Fprintf(&src, args)
1197+
fmt.Fprint(&src, args)
11981198
}
11991199

12001200
src.WriteString("\t)")
@@ -1277,7 +1277,7 @@ var ConsoleToGo = []TranslateRule{
12771277
if err != nil {
12781278
return "", fmt.Errorf("error converting params to arguments: %s", err)
12791279
}
1280-
fmt.Fprintf(&src, args)
1280+
fmt.Fprint(&src, args)
12811281
}
12821282

12831283
src.WriteString("\t)")
@@ -1316,7 +1316,7 @@ var ConsoleToGo = []TranslateRule{
13161316
if err != nil {
13171317
return "", fmt.Errorf("error converting params to arguments: %s", err)
13181318
}
1319-
fmt.Fprintf(&src, args)
1319+
fmt.Fprint(&src, args)
13201320
}
13211321

13221322
src.WriteString("\t)")
@@ -1388,7 +1388,7 @@ var ConsoleToGo = []TranslateRule{
13881388
if err != nil {
13891389
return "", fmt.Errorf("error converting params to arguments: %s", err)
13901390
}
1391-
fmt.Fprintf(&src, args)
1391+
fmt.Fprint(&src, args)
13921392
}
13931393

13941394
src.WriteString("\t)")
@@ -1419,7 +1419,7 @@ var ConsoleToGo = []TranslateRule{
14191419
if err != nil {
14201420
return "", fmt.Errorf("error converting params to arguments: %s", err)
14211421
}
1422-
fmt.Fprintf(&src, args)
1422+
fmt.Fprint(&src, args)
14231423
}
14241424

14251425
src.WriteString("\t)")
@@ -1453,7 +1453,7 @@ var ConsoleToGo = []TranslateRule{
14531453
if err != nil {
14541454
return "", fmt.Errorf("error converting params to arguments: %s", err)
14551455
}
1456-
fmt.Fprintf(&src, args)
1456+
fmt.Fprint(&src, args)
14571457
}
14581458

14591459
src.WriteString("\t)")
@@ -1484,7 +1484,7 @@ var ConsoleToGo = []TranslateRule{
14841484
if err != nil {
14851485
return "", fmt.Errorf("error converting params to arguments: %s", err)
14861486
}
1487-
fmt.Fprintf(&src, args)
1487+
fmt.Fprint(&src, args)
14881488
} else {
14891489
fmt.Fprintf(&src, "[]string{%q}", matches[1])
14901490
}

internal/build/cmd/generate/commands/gensource/command.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,14 @@ package gensource
2020
import (
2121
"bytes"
2222
"fmt"
23-
"github.com/elastic/go-elasticsearch/v9/internal/build/cmd"
2423
"io"
2524
"os"
2625
"path/filepath"
2726
"strings"
2827
"time"
2928

29+
"github.com/elastic/go-elasticsearch/v9/internal/build/cmd"
30+
3031
"github.com/spf13/cobra"
3132

3233
"github.com/elastic/go-elasticsearch/v9/internal/build/utils"
@@ -220,7 +221,7 @@ func (cmd *Command) processFile(f *os.File) (err error) {
220221
if utils.IsTTY() {
221222
fmt.Fprint(os.Stderr, "\x1b[2m")
222223
}
223-
fmt.Fprintf(os.Stderr, gen.Endpoint.DebugInfo())
224+
fmt.Fprint(os.Stderr, gen.Endpoint.DebugInfo())
224225
if utils.IsTTY() {
225226
fmt.Fprint(os.Stderr, "\x1b[0m")
226227
}

internal/build/cmd/generate/commands/gensource/debug.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func (e *Endpoint) DebugInfo() string {
3939
fmt.Fprintln(&out, "Paths:")
4040
for _, path := range e.URL.Paths {
4141
fmt.Fprintf(w, "%6s\t%s", path.Methods[0], path.Path)
42-
if path.Deprecated.Version != "" {
42+
if path.Deprecated.Version != "" && path.Deprecated.Version < EsVersion {
4343
fmt.Fprintf(w, "\t*deprecated*")
4444
}
4545
fmt.Fprintf(w, "\n")
@@ -64,7 +64,7 @@ func (e *Endpoint) DebugInfo() string {
6464
if part.Default != nil {
6565
fmt.Fprintf(w, ", default: %s", part.Default)
6666
}
67-
if part.Deprecated {
67+
if part.Deprecated.Version != "" && part.Deprecated.Version < EsVersion {
6868
fmt.Fprint(w, ", *deprecated*")
6969
}
7070
fmt.Fprint(w, "\n")

internal/build/cmd/generate/commands/gensource/generator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ type ` + g.Endpoint.MethodWithNamespace() + `Request struct {`)
243243
}
244244
}
245245
// Skip type only for selected APIs at this point
246-
if p.Name == "type" && p.Deprecated {
246+
if p.Name == "type" && p.Deprecated.Version != "" && p.Deprecated.Version < EsVersion {
247247
if g.Endpoint.Name == "bulk" ||
248248
g.Endpoint.Name == "create" ||
249249
g.Endpoint.Name == "delete" ||
@@ -660,7 +660,7 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(providedCtx context.
660660
pathContent.WriteString(`if instrument, ok := r.Instrument.(Instrumentation); ok {
661661
instrument.RecordPathPart(ctx, "` + a.Name + `", strconv.Itoa(*r.` + p + `))
662662
}` + "\n")
663-
case "string":
663+
case "string", "enum":
664664
pathGrow.WriteString(`len(r.` + p + `) + `)
665665
pathContent.WriteString(` path.WriteString(r.` + p + `)` + "\n")
666666
pathContent.WriteString(`if instrument, ok := r.Instrument.(Instrumentation); ok {
@@ -695,7 +695,7 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(providedCtx context.
695695
p = a.GoName()
696696

697697
switch a.Type {
698-
case "string":
698+
case "string", "enum":
699699
pathGrow.WriteString(`1 + len(r.` + p + `) + `)
700700
pathContent.WriteString(` if r.` + p + ` != "" {` + "\n")
701701
pathContent.WriteString(` path.WriteString("/")` + "\n")
@@ -740,7 +740,7 @@ func (r ` + g.Endpoint.MethodWithNamespace() + `Request) Do(providedCtx context.
740740
pathGrow.WriteString("1 +")
741741
pathContent.WriteString(` path.WriteString("/")` + "\n")
742742
switch a.Type {
743-
case "string":
743+
case "string", "enum":
744744
pathGrow.WriteString(`len(r.` + p + `)`)
745745
pathContent.WriteString(` path.WriteString(r.` + p + `)` + "\n")
746746
case "list":

0 commit comments

Comments
 (0)