@@ -22,10 +22,6 @@ import (
2222 "bytes"
2323 "encoding/json"
2424 "fmt"
25- "github.com/elastic/go-elasticsearch/v9/internal/build/cmd"
26- "github.com/elastic/go-elasticsearch/v9/internal/build/utils"
27- "github.com/elastic/go-elasticsearch/v9/internal/version"
28- "github.com/spf13/cobra"
2925 "io/ioutil"
3026 "log"
3127 "net/http"
@@ -34,6 +30,11 @@ import (
3430 "path/filepath"
3531 "strings"
3632 "time"
33+
34+ "github.com/elastic/go-elasticsearch/v9/internal/build/cmd"
35+ "github.com/elastic/go-elasticsearch/v9/internal/build/utils"
36+ "github.com/elastic/go-elasticsearch/v9/internal/version"
37+ "github.com/spf13/cobra"
3738)
3839
3940var (
@@ -91,15 +92,36 @@ func (c Command) Execute() (err error) {
9192
9293 res , err := http .Get (versionUrl )
9394 if err != nil {
94- log .Fatalf (err .Error ())
95+ log .Fatal (err .Error ())
9596 }
9697 defer res .Body .Close ()
9798
99+ if res .StatusCode == http .StatusNotFound {
100+ // Try with version without -SNAPSHOT (e.g., "9.1.0-SNAPSHOT" -> "9.1.0")
101+ fallbackVersion := esBuildVersion
102+ if strings .HasSuffix (esBuildVersion , "-SNAPSHOT" ) {
103+ fallbackVersion = strings .TrimSuffix (fallbackVersion , "-SNAPSHOT" )
104+ } else {
105+ log .Fatalf ("Version not found: %s returned 404" , esBuildVersion )
106+ }
107+
108+ fallbackUrl := strings .Join ([]string {artifactsUrl , fallbackVersion }, "/" )
109+ res , err = http .Get (fallbackUrl )
110+ if err != nil {
111+ log .Fatal (err .Error ())
112+ }
113+ defer res .Body .Close ()
114+
115+ if res .StatusCode == http .StatusNotFound {
116+ log .Fatalf ("Version not found: both %s and %s returned 404" , esBuildVersion , fallbackVersion )
117+ }
118+ }
119+
98120 var v Versions
99121 dec := json .NewDecoder (res .Body )
100122 err = dec .Decode (& v )
101123 if err != nil {
102- log .Fatalf (err .Error ())
124+ log .Fatal (err .Error ())
103125 }
104126
105127 if c .Debug {
@@ -124,14 +146,14 @@ func (c Command) Execute() (err error) {
124146 }
125147
126148 if err := c .extractZipToDest (data ); err != nil {
127- log .Fatalf (err .Error ())
149+ log .Fatal (err .Error ())
128150 }
129151
130152 d , _ := json .Marshal (build )
131153
132154 err = c .writeFileToDest ("elasticsearch.json" , d )
133155 if err != nil {
134- log .Fatalf (err .Error ())
156+ log .Fatal (err .Error ())
135157 }
136158
137159 return nil
0 commit comments