diff --git a/.github/workflows/update-golang-version.yml b/.github/workflows/update-golang-version.yml index b4cf4cd549..18cc51b982 100644 --- a/.github/workflows/update-golang-version.yml +++ b/.github/workflows/update-golang-version.yml @@ -8,7 +8,7 @@ env: GOPROXY: https://proxy.golang.org GO_VERSION: '1.16.7' jobs: - bump-k8s-versions: + bump-golang-version: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/update-golint-version.yml b/.github/workflows/update-golint-version.yml new file mode 100644 index 0000000000..3b21d6da96 --- /dev/null +++ b/.github/workflows/update-golint-version.yml @@ -0,0 +1,45 @@ +name: "update-golint-version" +on: + workflow_dispatch: + schedule: + # every Monday at around 3 am pacific/10 am UTC + - cron: "0 10 * * 1" +env: + GOPROXY: https://proxy.golang.org + GO_VERSION: '1.16.7' +jobs: + bump-golint-version: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - uses: actions/setup-go@v2 + with: + go-version: ${{env.GO_VERSION}} + stable: true + - name: Bump Golint Versions + id: bumpGolint + run: | + make update-golint-version + echo "::set-output name=changes::$(git status --porcelain)" + - name: Create PR + if: ${{ steps.bumpGolint.outputs.changes != '' }} + uses: peter-evans/create-pull-request@v3 + with: + token: ${{ secrets.MINIKUBE_BOT_PAT }} + commit-message: bump golaint versions + committer: minikube-bot + author: minikube-bot + branch: auto_bump_golint_version + push-to-fork: minikube-bot/minikube + base: master + delete-branch: true + title: 'bump golint version' + labels: ok-to-test + body: | + Golangci-lint Project release a [new version](https://github.com/golangci/golangci-lint/releases), + + This PR was auto-generated by `make update-golint-version` using [update-golint-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-golint-version.yml) CI Workflow. + + + + diff --git a/Makefile b/Makefile index 50c60c69ba..3a7ba8d0a9 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -66,7 +67,8 @@ MINIKUBE_UPLOAD_LOCATION := gs://${MINIKUBE_BUCKET} MINIKUBE_RELEASES_URL=https://github.com/kubernetes/minikube/releases/download KERNEL_VERSION ?= 4.19.182 -# latest from https://github.com/golangci/golangci-lint/releases +# 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 diff --git a/hack/update/golang_version/update_golang_version.go b/hack/update/golang_version/update_golang_version.go index 62eeb23735..4978e46b2d 100644 --- a/hack/update/golang_version/update_golang_version.go +++ b/hack/update/golang_version/update_golang_version.go @@ -90,6 +90,12 @@ var ( `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, }, }, + ".github/workflows/update-golint-version.yml": { + Replace: map[string]string{ + `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, + }, + }, + ".github/workflows/time-to-k8s-public-chart.yml": { Replace: map[string]string{ `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, diff --git a/hack/update/golint_version/update_golint_version.go b/hack/update/golint_version/update_golint_version.go new file mode 100644 index 0000000000..db9261bc94 --- /dev/null +++ b/hack/update/golint_version/update_golint_version.go @@ -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=: 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=: 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 +}