auto update Hugo

pull/15445/head
Steven Powell 2022-12-01 13:33:22 -08:00
parent 0f2edf59f2
commit b919252fd6
3 changed files with 124 additions and 0 deletions

View File

@ -0,0 +1,46 @@
name: "update-hugo-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-hugo-version:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@93ea575cb5d8a053eaa0ac8fa3b40d7e05a33cc8
- uses: actions/setup-go@c4a742cab115ed795e34d4513e2cf7d472deb55f
with:
go-version: ${{env.GO_VERSION}}
- name: Bump Hugo version
id: bumpHugo
run: |
make update-hugo-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<<EOF" >> $GITHUB_OUTPUT
echo "$(git status --porcelain)" >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create PR
if: ${{ steps.bumpHugo.outputs.changes != '' }}
uses: peter-evans/create-pull-request@2b011faafdcbc9ceb11414d64d0573f37c774b04
with:
token: ${{ secrets.MINIKUBE_BOT_PAT }}
commit-message: bump hugo version
committer: minikube-bot <minikube-bot@google.com>
author: minikube-bot <minikube-bot@google.com>
branch: auto_bump_hugo_version
push-to-fork: minikube-bot/minikube
base: master
delete-branch: true
title: 'bump hugo version'
labels: ok-to-test
body: |
Hugo project released a [new version](https://github.com/gohugoio/hugo/releases),
This PR was auto-generated by `make update-hugo-version` using [update-hugo-version.yml](https://github.com/kubernetes/minikube/tree/master/.github/workflows/update-hugo-version.yml) CI Workflow.

View File

@ -1066,6 +1066,11 @@ update-docsy-version:
(cd hack/update/docsy_version && \
go run update_docsy_version.go)
.Phony: update-hugo-version
update-hugo-version:
(cd hack/update/hugo_version && \
go run update_hugo_version.go)
.PHONY: generate-licenses
generate-licenses:
./hack/generate_licenses.sh

View File

@ -0,0 +1,73 @@
/*
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"
"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{
"netlify.toml": {
Replace: map[string]string{
`HUGO_VERSION = .*`: `HUGO_VERSION = "{{.StableVersion}}"`,
},
},
}
)
// Data holds stable Hugo 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 Hugo stable version
stable, err := hugoVersion(ctx, "gohugoio", "hugo")
if err != nil {
klog.Fatalf("Unable to get Hugo stable version: %v", err)
}
data := Data{StableVersion: stable}
klog.Infof("Hugo stable version: %s", stable)
update.Apply(schema, data)
}
// hugoVersion returns stable version in semver format.
func hugoVersion(ctx context.Context, owner, repo string) (stable string, err error) {
// get Hugo version from GitHub Releases
stable, _, _, err = update.GHReleases(ctx, owner, repo)
if err != nil || !semver.IsValid(stable) {
return "", err
}
return stable, nil
}