From e83741569a9c4d7bae2b050682ea8b314fbb06d7 Mon Sep 17 00:00:00 2001 From: Steven Powell Date: Tue, 22 Nov 2022 09:52:40 -0800 Subject: [PATCH] add workflow to update gh version --- .github/workflows/update-gh-version.yml | 50 +++++++++++++ .github/workflows/update-golint-version.yml | 2 +- .../workflows/update-gotestsum-version.yml | 2 +- Makefile | 5 ++ hack/jenkins/installers/check_install_gh.sh | 12 +-- .../cri_dockerd/update_cri_dockerd_version.go | 4 +- hack/update/gh_version/update_gh_version.go | 74 +++++++++++++++++++ .../golang_version/update_golang_version.go | 5 ++ .../golint_version/update_golint_version.go | 2 +- 9 files changed, 146 insertions(+), 10 deletions(-) create mode 100644 .github/workflows/update-gh-version.yml create mode 100644 hack/update/gh_version/update_gh_version.go diff --git a/.github/workflows/update-gh-version.yml b/.github/workflows/update-gh-version.yml new file mode 100644 index 0000000000..95f6d3a073 --- /dev/null +++ b/.github/workflows/update-gh-version.yml @@ -0,0 +1,50 @@ +name: "update-gh-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.19.3' +permissions: + contents: read + +jobs: + bump-gh-version: + runs-on: ubuntu-20.04 + steps: + - uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8 + - uses: actions/setup-go@c4a742cab115ed795e34d4513e2cf7d472deb55f + with: + go-version: ${{env.GO_VERSION}} + - name: Bump gh version + id: bumpGh + run: | + make update-gh-version + # The following is to support multiline with GITHUB_OUTPUT, see https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#multiline-strings + echo "changes<> $GITHUB_OUTPUT + echo "$(git status --porcelain)" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + - name: Create PR + if: ${{ steps.bumpGh.outputs.changes != '' }} + uses: peter-evans/create-pull-request@b4d51739f96fca8047ad065eccef63442d8e99f7 + with: + token: ${{ secrets.MINIKUBE_BOT_PAT }} + commit-message: bump gh versions + committer: minikube-bot + author: minikube-bot + branch: auto_bump_gh_version + push-to-fork: minikube-bot/minikube + base: master + delete-branch: true + title: 'bump gh version' + labels: ok-to-test + body: | + gh project released a [new version](https://github.com/cli/cli/releases), + + This PR was auto-generated by `make update-gh-version` using [update-gh-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-gh-version.yml) CI Workflow. + + + + diff --git a/.github/workflows/update-golint-version.yml b/.github/workflows/update-golint-version.yml index ea9b03c412..99eee203c9 100644 --- a/.github/workflows/update-golint-version.yml +++ b/.github/workflows/update-golint-version.yml @@ -41,7 +41,7 @@ jobs: title: 'bump golint version' labels: ok-to-test body: | - Golangci-lint Project release a [new version](https://github.com/golangci/golangci-lint/releases), + Golangci-lint Project released 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/.github/workflows/update-gotestsum-version.yml b/.github/workflows/update-gotestsum-version.yml index 8ef21b9fc5..7b9322f2ef 100644 --- a/.github/workflows/update-gotestsum-version.yml +++ b/.github/workflows/update-gotestsum-version.yml @@ -41,6 +41,6 @@ jobs: title: 'bump gotestsum version' labels: ok-to-test body: | - Gotestsum Project release a [new version](https://github.com/gotestyourself/gotestsum/releases), + Gotestsum Project released a [new version](https://github.com/gotestyourself/gotestsum/releases), This PR was auto-generated by `make update-gotestsum-version` using [update-gotestsum-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-gotestsum-version.yml) CI Workflow. diff --git a/Makefile b/Makefile index 26ed1ff092..1eefdceec9 100644 --- a/Makefile +++ b/Makefile @@ -1056,6 +1056,11 @@ update-gotestsum-version: (cd hack/update/gotestsum_version && \ go run update_gotestsum_version.go) +.PHONY: update-gh-version +update-gh-version: + (cd hack/update/gh_version && \ + go run update_gh_version.go) + .PHONY: generate-licenses generate-licenses: ./hack/generate_licenses.sh diff --git a/hack/jenkins/installers/check_install_gh.sh b/hack/jenkins/installers/check_install_gh.sh index 004f58b715..b24564e35a 100755 --- a/hack/jenkins/installers/check_install_gh.sh +++ b/hack/jenkins/installers/check_install_gh.sh @@ -16,12 +16,14 @@ set -eux -o pipefail +GH_VERSION="2.18.1" + echo "Installing latest version of gh" -curl -qLO "https://github.com/cli/cli/releases/download/v2.18.1/gh_2.18.1_linux_amd64.tar.gz" -tar -xf gh_2.18.1_linux_amd64.tar.gz && -sudo mv gh_2.18.1_linux_amd64/bin/gh /usr/local/bin/gh -rm gh_2.18.1_linux_amd64.tar.gz -rm -rf gh_2.18.1_linux_amd64 +curl -qLO "https://github.com/cli/cli/releases/download/v${GH_VERSION}/gh_${GH_VERSION}_linux_amd64.tar.gz" +tar -xf "gh_${GH_VERSION}_linux_amd64.tar.gz" && +sudo mv "gh_${GH_VERSION}_linux_amd64/bin/gh" /usr/local/bin/gh +rm "gh_${GH_VERSION}_linux_amd64.tar.gz" +rm -rf "gh_${GH_VERSION}_linux_amd64" echo "Authorizing bot with gh" echo "${access_token}" | gh auth login --with-token diff --git a/hack/update/cri_dockerd/update_cri_dockerd_version.go b/hack/update/cri_dockerd/update_cri_dockerd_version.go index a6f16c44bb..b626ebb77d 100644 --- a/hack/update/cri_dockerd/update_cri_dockerd_version.go +++ b/hack/update/cri_dockerd/update_cri_dockerd_version.go @@ -57,7 +57,7 @@ var ( } ) -// Data holds stable gotestsum version in semver format. +// Data holds stable cri-dockerd version in semver format. type Data struct { FullCommit string ShortCommit string @@ -76,7 +76,7 @@ func main() { update.Apply(schema, data) if out, err := exec.Command("./update_cri_dockerd.sh", commit, archs).CombinedOutput(); err != nil { - log.Fatalf("failed to build and upload cri-docker binaries: %s", string(out)) + log.Fatalf("failed to build and upload cri-dockerd binaries: %s", string(out)) } fmt.Println("Don't forget you still need to update the hash files!") diff --git a/hack/update/gh_version/update_gh_version.go b/hack/update/gh_version/update_gh_version.go new file mode 100644 index 0000000000..fbcdf31647 --- /dev/null +++ b/hack/update/gh_version/update_gh_version.go @@ -0,0 +1,74 @@ +/* +Copyright 2022 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. +*/ + +package main + +import ( + "context" + "strings" + "time" + + "golang.org/x/mod/semver" + "k8s.io/klog/v2" + + "k8s.io/minikube/hack/update" +) + +const ( + // default context timeout + cxTimeout = 5 * time.Minute +) + +var ( + schema = map[string]update.Item{ + "hack/jenkins/installers/check_install_gh.sh": { + Replace: map[string]string{ + `GH_VERSION=".*"`: `GH_VERSION="{{.StableVersion}}"`, + }, + }, + } +) + +// Data holds stable gh version in semver format. +type Data struct { + StableVersion string +} + +func main() { + // set a context with defined timeout + ctx, cancel := context.WithTimeout(context.Background(), cxTimeout) + defer cancel() + + // get gh stable version + stable, err := ghVersion(ctx, "cli", "cli") + if err != nil { + klog.Fatalf("Unable to get gh stable version: %v", err) + } + data := Data{StableVersion: stable} + klog.Infof("gh stable version: %s", data.StableVersion) + + update.Apply(schema, data) +} + +// ghVersion returns stable version in semver format. +func ghVersion(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 strings.TrimPrefix(stable, "v"), nil +} diff --git a/hack/update/golang_version/update_golang_version.go b/hack/update/golang_version/update_golang_version.go index d955949d48..18e66cc54d 100644 --- a/hack/update/golang_version/update_golang_version.go +++ b/hack/update/golang_version/update_golang_version.go @@ -93,6 +93,11 @@ var ( `GO_VERSION: .*`: `GO_VERSION: '{{.StableVersion}}'`, }, }, + ".github/workflows/update-gh-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 index b748e9edb9..47c848a915 100644 --- a/hack/update/golint_version/update_golint_version.go +++ b/hack/update/golint_version/update_golint_version.go @@ -41,7 +41,7 @@ var ( } ) -// Data holds stable gopogh version in semver format. +// Data holds stable golint version in semver format. type Data struct { StableVersion string }