@@ -38,14 +38,14 @@ type asset struct {
3838// InstallOptions controls the greyproxy installation behavior.
3939type InstallOptions struct {
4040 Output io.Writer // progress output (typically os.Stderr)
41- Tag string // specific tag to install; if empty, uses latest stable
42- Beta bool // if Tag is empty and Beta is true, fetches latest pre-release tag
4341}
4442
4543// IsOlderVersion returns true if current is strictly older than latest,
4644// or if current is not a valid semver string (e.g. "dev").
47- // Both strings should be in "major.minor.patch" format (no "v" prefix ).
45+ // Accepts strings with or without a "v" prefix (e.g. "v1.2.3" or "1.2.3" ).
4846func IsOlderVersion (current , latest string ) bool {
47+ current = strings .TrimPrefix (current , "v" )
48+ latest = strings .TrimPrefix (latest , "v" )
4949 cp := strings .SplitN (current , "." , 3 )
5050 lp := strings .SplitN (latest , "." , 3 )
5151 if len (lp ) != 3 {
@@ -85,21 +85,7 @@ func Install(opts InstallOptions) error {
8585 opts .Output = os .Stderr
8686 }
8787
88- // Resolve which tag to install
89- var rel * release
90- var err error
91- switch {
92- case opts .Tag != "" :
93- rel , err = fetchReleaseFor (nil , "" , githubOwner , githubRepo , opts .Tag )
94- case opts .Beta :
95- tag , tagErr := fetchLatestPreReleaseTagFor (nil , "" , githubOwner , githubRepo )
96- if tagErr != nil {
97- return fmt .Errorf ("failed to fetch latest pre-release: %w" , tagErr )
98- }
99- rel , err = fetchReleaseFor (nil , "" , githubOwner , githubRepo , tag )
100- default :
101- rel , err = fetchLatestRelease ()
102- }
88+ rel , err := fetchLatestRelease ()
10389 if err != nil {
10490 return fmt .Errorf ("failed to fetch release: %w" , err )
10591 }
@@ -155,26 +141,16 @@ func Install(opts InstallOptions) error {
155141}
156142
157143// CheckLatestTag returns the latest greyproxy release tag (with "v" prefix).
158- // If beta is true, returns the latest pre-release tag.
159- func CheckLatestTag (beta bool ) (string , error ) {
160- return CheckLatestTagFor (githubOwner , githubRepo , beta )
161- }
162-
163- // CheckLatestTagFor returns the latest release tag for any GitHub repo.
164- // If beta is true, returns the latest pre-release tag; otherwise returns the latest stable tag.
165- func CheckLatestTagFor (owner , repo string , beta bool ) (string , error ) {
166- return checkLatestTagFor (nil , "" , owner , repo , beta )
144+ func CheckLatestTag () (string , error ) {
145+ return checkLatestTag (nil , "" )
167146}
168147
169- func checkLatestTagFor (client * http.Client , apiBase , owner , repo string , beta bool ) (string , error ) {
170- if ! beta {
171- rel , err := fetchReleaseFor (client , apiBase , owner , repo , "latest" )
172- if err != nil {
173- return "" , err
174- }
175- return rel .TagName , nil
148+ func checkLatestTag (client * http.Client , apiBase string ) (string , error ) {
149+ rel , err := fetchReleaseFor (client , apiBase , githubOwner , githubRepo , "latest" )
150+ if err != nil {
151+ return "" , err
176152 }
177- return fetchLatestPreReleaseTagFor ( client , apiBase , owner , repo )
153+ return rel . TagName , nil
178154}
179155
180156// fetchLatestRelease queries the GitHub API for the latest greyproxy release.
@@ -337,50 +313,3 @@ func fetchReleaseFor(client *http.Client, apiBase, owner, repo, endpoint string)
337313 }
338314 return & rel , nil
339315}
340-
341- // fetchLatestPreReleaseTagFor returns the most recent pre-release tag for the given repo.
342- // client and apiBase are optional; nil/empty use production defaults.
343- func fetchLatestPreReleaseTagFor (client * http.Client , apiBase , owner , repo string ) (string , error ) {
344- if client == nil {
345- client = & http.Client {Timeout : apiTimeout }
346- }
347- if apiBase == "" {
348- apiBase = "https://api.github.com"
349- }
350- apiURL := fmt .Sprintf ("%s/repos/%s/%s/releases?per_page=20" , apiBase , owner , repo )
351-
352- ctx , cancel := context .WithTimeout (context .Background (), apiTimeout )
353- defer cancel ()
354-
355- req , err := http .NewRequestWithContext (ctx , http .MethodGet , apiURL , nil )
356- if err != nil {
357- return "" , err
358- }
359- req .Header .Set ("Accept" , "application/vnd.github+json" )
360- req .Header .Set ("User-Agent" , "greywall-setup" )
361-
362- resp , err := client .Do (req ) //nolint:gosec // apiURL is built from controlled inputs
363- if err != nil {
364- return "" , fmt .Errorf ("GitHub API request failed: %w" , err )
365- }
366- defer func () { _ = resp .Body .Close () }()
367-
368- if resp .StatusCode != http .StatusOK {
369- return "" , fmt .Errorf ("GitHub API returned status %d" , resp .StatusCode )
370- }
371-
372- var releases []struct {
373- TagName string `json:"tag_name"`
374- PreRelease bool `json:"prerelease"`
375- }
376- if err := json .NewDecoder (resp .Body ).Decode (& releases ); err != nil {
377- return "" , fmt .Errorf ("failed to parse releases response: %w" , err )
378- }
379-
380- for _ , r := range releases {
381- if r .PreRelease {
382- return r .TagName , nil
383- }
384- }
385- return "" , fmt .Errorf ("no pre-release found for %s/%s" , owner , repo )
386- }
0 commit comments