@@ -22,10 +22,7 @@ import (
2222 "bytes"
2323 "encoding/json"
2424 "fmt"
25- "github.com/elastic/go-elasticsearch/v8/internal/build/cmd"
26- "github.com/elastic/go-elasticsearch/v8/internal/build/utils"
27- "github.com/elastic/go-elasticsearch/v8/internal/version"
28- "github.com/spf13/cobra"
25+
2926 "io/ioutil"
3027 "log"
3128 "net/http"
@@ -34,6 +31,11 @@ import (
3431 "path/filepath"
3532 "strings"
3633 "time"
34+
35+ "github.com/elastic/go-elasticsearch/v8/internal/build/cmd"
36+ "github.com/elastic/go-elasticsearch/v8/internal/build/utils"
37+ "github.com/elastic/go-elasticsearch/v8/internal/version"
38+ "github.com/spf13/cobra"
3739)
3840
3941var (
@@ -91,15 +93,36 @@ func (c Command) Execute() (err error) {
9193
9294 res , err := http .Get (versionUrl )
9395 if err != nil {
94- log .Fatalf (err .Error ())
96+ log .Fatal (err .Error ())
9597 }
9698 defer res .Body .Close ()
9799
100+ if res .StatusCode == http .StatusNotFound {
101+ // Try with version without -SNAPSHOT (e.g., "9.1.0-SNAPSHOT" -> "9.1.0")
102+ fallbackVersion := esBuildVersion
103+ if strings .HasSuffix (esBuildVersion , "-SNAPSHOT" ) {
104+ fallbackVersion = strings .TrimSuffix (fallbackVersion , "-SNAPSHOT" )
105+ } else {
106+ log .Fatalf ("Version not found: %s returned 404" , esBuildVersion )
107+ }
108+
109+ fallbackUrl := strings .Join ([]string {artifactsUrl , fallbackVersion }, "/" )
110+ res , err = http .Get (fallbackUrl )
111+ if err != nil {
112+ log .Fatal (err .Error ())
113+ }
114+ defer res .Body .Close ()
115+
116+ if res .StatusCode == http .StatusNotFound {
117+ log .Fatalf ("Version not found: both %s and %s returned 404" , esBuildVersion , fallbackVersion )
118+ }
119+ }
120+
98121 var v Versions
99122 dec := json .NewDecoder (res .Body )
100123 err = dec .Decode (& v )
101124 if err != nil {
102- log .Fatalf (err .Error ())
125+ log .Fatal (err .Error ())
103126 }
104127
105128 if c .Debug {
@@ -124,14 +147,14 @@ func (c Command) Execute() (err error) {
124147 }
125148
126149 if err := c .extractZipToDest (data ); err != nil {
127- log .Fatalf (err .Error ())
150+ log .Fatal (err .Error ())
128151 }
129152
130153 d , _ := json .Marshal (build )
131154
132155 err = c .writeFileToDest ("elasticsearch.json" , d )
133156 if err != nil {
134- log .Fatalf (err .Error ())
157+ log .Fatal (err .Error ())
135158 }
136159
137160 return nil
0 commit comments