update golang version

pull/12248/head
Medya Gh 2021-08-12 15:50:11 -07:00
parent 5360e1296a
commit e6d2371518
2 changed files with 97 additions and 1 deletions

View File

@ -32,6 +32,7 @@ RPM_VERSION ?= $(DEB_VERSION)
RPM_REVISION ?= 0
# used by hack/jenkins/release_build_and_upload.sh and KVM_BUILD_IMAGE, see also BUILD_IMAGE below
# update this only by running `make update-golang-version`
GO_VERSION ?= 1.16.7
# replace "x.y.0" => "x.y". kube-cross and golang.org/dl use different formats for x.y.0 go versions
@ -67,6 +68,7 @@ MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download
KERNEL_VERSION ?= 4.19.182
# latest from https://github.com/golangci/golangci-lint/releases
# update this only by running `make update-golint-version`
GOLINT_VERSION ?= v1.39.0
# Limit number of default jobs, to avoid the CI builds running out of memory
GOLINT_JOBS ?= 4
@ -973,6 +975,12 @@ update-kubernetes-version:
(cd hack/update/kubernetes_version && \
go run update_kubernetes_version.go)
.PHONY: update-golint-version
update-golint-version:
(cd hack/update/golint_version && \
go run update_golint_version.go)
.PHONY: update-kubernetes-version-pr
update-kubernetes-version-pr:
ifndef GITHUB_TOKEN

View File

@ -0,0 +1,88 @@
/*
Copyright 2020 The Kubernetes Authors All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Script expects the following env variables:
- UPDATE_TARGET=<string>: optional - if unset/absent, default option is "fs"; valid options are:
- "fs" - update only local filesystem repo files [default]
- "gh" - update only remote GitHub repo files and create PR (if one does not exist already)
- "all" - update local and remote repo files and create PR (if one does not exist already)
- GITHUB_TOKEN=<string>: GitHub [personal] access token
- note: GITHUB_TOKEN is required if UPDATE_TARGET is "gh" or "all"
*/
package main
import (
"context"
"time"
"golang.org/x/mod/semver"
"k8s.io/klog/v2"
"k8s.io/minikube/hack/update"
)
const (
// default context timeout
cxTimeout = 300 * time.Second
)
var (
schema = map[string]update.Item{
"Makefile": {
Replace: map[string]string{
`GOLINT_VERSION \?= v1.*`: `GOLINT_VERSION ?= {{.StableVersion}}`,
},
},
}
// PR data
prBranchPrefix = "update-golint-version_" // will be appended with first 7 characters of the PR commit SHA
prTitle = `update go lint version: {stable: "{{.StableVersion}}"}`
)
// Data holds stable gopogh version in semver format.
type Data struct {
StableVersion string `json:"stableVersion"`
}
func main() {
// set a context with defined timeout
ctx, cancel := context.WithTimeout(context.Background(), cxTimeout)
defer cancel()
// get Golang stable version
stable, err := golintVersion(ctx, "golangci", "golangci-lint")
if err != nil {
klog.Fatalf("Unable to get Golang stable version: %v", err)
}
data := Data{StableVersion: stable}
klog.Infof("Golang stable version: %s", data.StableVersion)
update.Apply(ctx, schema, data, prBranchPrefix, prTitle, 12247)
}
//
// golintVersions returns stable version in semver format.
func golintVersion(ctx context.Context, owner, repo string) (stable string, err error) {
// get Kubernetes versions from GitHub Releases
stable, _, err = update.GHReleases(ctx, owner, repo)
if err != nil || !semver.IsValid(stable) {
return "", err
}
return stable, nil
}