Skip to content

Commit 1a63b18

Browse files
authored
Merge pull request #160 from Clever/INFRANG-6802-update-warning-message
Updating goci warning message.
2 parents 38d886e + 026c7d1 commit 1a63b18

File tree

2 files changed

+34
-41
lines changed

2 files changed

+34
-41
lines changed

VERSION

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
v1.0.5
2-
- Supporting lazy loading of environment variables
1+
v1.0.6
2+
Updating goci warning message, including recent version release date
33

44
Previously:
5+
- Supporting lazy loading of environment variables
56
- updated parsing of go version from go.mod
67
- goci now supports validation of go version
78
- variable MASTER_COMPARE is now required for local dev

cmd/goci/main.go

Lines changed: 31 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ func validateRun() error {
155155
return &ValidationError{Message: fmt.Sprintf("branch name %s contains a `/` character, which is not supported by catapult", environment.Branch())}
156156
}
157157

158-
latestGoVersion, err := fetchLatestGoVersion()
158+
latestGoVersion, releaseDate, err := fetchLatestGoVersion()
159159
if err != nil {
160160
return fmt.Errorf("failed to fetch latest Go version: %v", err)
161161
}
@@ -200,48 +200,40 @@ func validateRun() error {
200200
return &ValidationError{Message: fmt.Sprintf("Your applications go version %v is no longer supported. Please upgrade to version %v.", repoVersion, newestGoVersion)}
201201
} else if repoVersion <= newestGoVersion-0.01 {
202202
// We'll give a PR comment to the Author to warn them about the need to upgrade
203-
fmt.Printf("Warning: This applications go version will be out of support by the next major release. You will have until the next release before you need to upgrade to version %v\n", newestGoVersion)
203+
fmt.Printf("A new Go version is out, released on (%v). After 6 months of release, Your current Go version (%v) will fail CI workflows if it is not upgraded.\n", releaseDate, f.Go.Version)
204204
}
205-
206205
return nil
207206
}
208207

209-
// fetchLatestGoVersion fetches the latest Go version from the official Go download page.
210-
func fetchLatestGoVersion() (string, error) {
211-
// official Go download page
212-
resp, err := http.Get("https://go.dev/dl/")
213-
if err != nil {
214-
return "", fmt.Errorf("failed to fetch Go download page: %v", err)
215-
}
216-
defer resp.Body.Close()
217-
218-
if resp.StatusCode != http.StatusOK {
219-
return "", fmt.Errorf("failed to fetch Go download page: status code %d", resp.StatusCode)
220-
}
221-
222-
bodyBytes, err := io.ReadAll(resp.Body)
223-
if err != nil {
224-
return "", fmt.Errorf("failed to read response body: %v", err)
225-
}
226-
body := string(bodyBytes)
227-
228-
// Extract the latest macOS (darwin) download URL
229-
re := regexp.MustCompile(`/dl/go[0-9]+\.[0-9]+\.[0-9]+\.darwin-arm64.pkg`)
230-
matches := re.FindStringSubmatch(body)
231-
if len(matches) == 0 {
232-
return "", fmt.Errorf("failed to find Go download URL")
233-
}
234-
goURL := "https://go.dev" + matches[0]
235-
236-
// Extract the Go version number from the URL
237-
reVersion := regexp.MustCompile(`[0-9]+\.[0-9]+\.[0-9]+`)
238-
versionMatches := reVersion.FindStringSubmatch(goURL)
239-
if len(versionMatches) == 0 {
240-
return "", fmt.Errorf("failed to find Go version in URL")
241-
}
242-
goVersion := versionMatches[0]
243-
244-
return goVersion, nil
208+
// fetchLatestGoVersion fetches the latest Go version and its release date from the official Go release notes page.
209+
func fetchLatestGoVersion() (string, string, error) {
210+
// Fetch the Go release notes page
211+
resp, err := http.Get("https://go.dev/doc/devel/release")
212+
if err != nil {
213+
return "", "", fmt.Errorf("failed to fetch Go release notes page: %v", err)
214+
}
215+
defer resp.Body.Close()
216+
217+
if resp.StatusCode != http.StatusOK {
218+
return "", "", fmt.Errorf("failed to fetch Go release notes page: status code %d", resp.StatusCode)
219+
}
220+
221+
bodyBytes, err := io.ReadAll(resp.Body)
222+
if err != nil {
223+
return "", "", fmt.Errorf("failed to read response body: %v", err)
224+
}
225+
body := string(bodyBytes)
226+
227+
// Extract the latest Go version and its release date
228+
re := regexp.MustCompile(`go([0-9]+\.[0-9]+\.[0-9]+) \(released ([0-9]{4}-[0-9]{2}-[0-9]{2})\)`)
229+
matches := re.FindStringSubmatch(body)
230+
if len(matches) < 3 {
231+
return "", "", fmt.Errorf("failed to find Go version and release date")
232+
}
233+
goVersion := matches[1]
234+
releaseDate := matches[2]
235+
236+
return goVersion, releaseDate, nil
245237
}
246238

247239
// allAppsBuilt returns an error if any apps are missing a build artifact.

0 commit comments

Comments
 (0)