Skip to content

Commit 98e060a

Browse files
committed
new file, fix, more updates
Signed-off-by: David Fridrich <fridrich.david19@gmail.com>
1 parent 976f4b1 commit 98e060a

File tree

4 files changed

+43
-67
lines changed

4 files changed

+43
-67
lines changed

.github/workflows/update-knative-hack.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@ permissions:
1010
jobs:
1111
update:
1212
name: Update to latest
13-
runs-on: ubuntu
13+
runs-on: ubuntu-latest
1414
steps:
1515
- uses: actions/checkout@v4
16-
- uses: actions/setup-go@v4
16+
- uses: actions/setup-go@v5
1717
with:
1818
go-version: 1.23.4
1919
- name: Run script

hack/allocate.sh

Lines changed: 2 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,8 @@ set -o nounset
2121
set -o pipefail
2222

2323
source "$(dirname "$(realpath "$0")")/common.sh"
24-
25-
26-
set_versions() {
27-
# Note: Kubernetes Version node image per Kind releases (full hash is suggested):
28-
# https://github.com/kubernetes-sigs/kind/releases
29-
kind_node_version=v1.32.0@sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027
30-
# Updated programatically via 'hack/update-knative-hack.go'
31-
knative_serving_version="v1.16.0"
32-
knative_eventing_versio="v1.16.0"
33-
contour_version="v1.16.0"
34-
}
24+
# this is where versions of common components are (like knative)
25+
source "$(dirname "$(realpath "$0")")/components-versions.sh"
3526

3627
main() {
3728
echo "${blue}Allocating${reset}"
@@ -63,46 +54,6 @@ main() {
6354
echo -e "\n${green}🎉 DONE${reset}\n"
6455
}
6556

66-
# Retrieve latest version from given Knative repository tags
67-
# On 'main' branch the latest released version is returned
68-
# On 'release-x.y' branch the latest patch version for 'x.y.*' is returned
69-
# Similar to hack/library.sh get_latest_knative_yaml_source()
70-
function get_latest_release_version() {
71-
local org_name="$1"
72-
local repo_name="$2"
73-
local major_minor=""
74-
if is_release_branch; then
75-
local branch_name
76-
branch_name="$(current_branch)"
77-
major_minor="${branch_name##release-}"
78-
fi
79-
local version
80-
version="$(git ls-remote --tags --ref https://github.com/"${org_name}"/"${repo_name}".git \
81-
| grep "${major_minor}" \
82-
| cut -d '-' -f2 \
83-
| cut -d 'v' -f2 \
84-
| sort -Vr \
85-
| head -n 1)"
86-
echo "${version}"
87-
}
88-
89-
# Returns whether the current branch is a release branch.
90-
function is_release_branch() {
91-
[[ $(current_branch) =~ ^release-[0-9\.]+$ ]]
92-
}
93-
94-
# Returns the current branch.
95-
# Taken from knative/hack. The function covers Knative CI use cases and local variant.
96-
function current_branch() {
97-
local branch_name=""
98-
# Get the branch name from Prow's env var, see https://github.com/kubernetes/test-infra/blob/master/prow/jobs.md.
99-
# Otherwise, try getting the current branch from git.
100-
(( ${IS_PROW:-} )) && branch_name="${PULL_BASE_REF:-}"
101-
[[ -z "${branch_name}" ]] && branch_name="${GITHUB_BASE_REF:-}"
102-
[[ -z "${branch_name}" ]] && branch_name="$(git rev-parse --abbrev-ref HEAD)"
103-
echo "${branch_name}"
104-
}
105-
10657
kubernetes() {
10758
cat <<EOF | $KIND create cluster --name=func --kubeconfig="${KUBECONFIG}" --wait=60s --config=-
10859
kind: Cluster

hack/component-versions.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/usr/bin/env bash
2+
3+
set_versions() {
4+
# Note: Kubernetes Version node image per Kind releases (full hash is suggested):
5+
# https://github.com/kubernetes-sigs/kind/releases
6+
kind_node_version=v1.32.0@sha256:c48c62eac5da28cdadcf560d1d8616cfa6783b58f0d94cf63ad1bf49600cb027
7+
8+
# Can be updated programatically
9+
knative_serving_version="v1.16.0"
10+
knative_eventing_versio="v1.16.0"
11+
contour_version="v1.16.0"
12+
}

hack/update-knative-components.go

Lines changed: 27 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,22 @@ var (
1616
knSrvPrefix = "knative_serving_version="
1717
knEvtPrefix = "knative_eventing_version="
1818
knCtrPrefix = "contour_version="
19+
20+
file = "hack/component-versions.sh"
1921
)
2022

23+
// if running on branch "release-*" return the current branch version
24+
// (for possible fixups) otherwise, return latest as standard
25+
// func getLatestOrReleaseVersion() (v string, err error) {
26+
// cmd := exec.Command("git", "rev-parse", "--abbrev-ref", "HEAD")
27+
// o, err := cmd.Output()
28+
// if err != nil {
29+
// return "", fmt.Errorf("error running git rev-parse: %v", err)
30+
// }
31+
// fmt.Printf("out: %s\n", string(o))
32+
// return string(o), nil
33+
// }
34+
2135
// get latest version of owner/repo via GH API
2236
func getLatestVersion(ctx context.Context, client *github.Client, owner string, repo string) (v string, err error) {
2337
fmt.Printf("get latest repo %s/%s\n", owner, repo)
@@ -45,15 +59,13 @@ func getVersionsFromFile() (srv string, evt string, ctr string, err error) {
4559
evt = "" //eventing
4660
ctr = "" //net-contour (knative-extensions)
4761

48-
var f = "hack/allocate.sh"
49-
50-
file, err := os.OpenFile(f, os.O_RDWR, 0600)
62+
f, err := os.OpenFile(file, os.O_RDWR, 0600)
5163
if err != nil {
52-
err = fmt.Errorf("cant open file '%s': %v", f, err)
64+
err = fmt.Errorf("cant open file '%s': %v", file, err)
5365
}
54-
defer file.Close()
66+
defer f.Close()
5567
// read file line by line
56-
fs := bufio.NewScanner(file)
68+
fs := bufio.NewScanner(f)
5769
fs.Split(bufio.ScanLines)
5870
for fs.Scan() {
5971
// Look for a prefix in a trimmed line.
@@ -83,10 +95,10 @@ func getVersionsFromFile() (srv string, evt string, ctr string, err error) {
8395
return
8496
}
8597

86-
// Update version in file if new releases of eventing/serving/net-concour exist
87-
// if applicable.
98+
// Update version in file if new releases of any component exist
8899
func tryUpdateFile(upstreams []struct{ owner, repo, version string }) (updated bool, err error) {
89-
file := "hack/allocate.sh"
100+
quoteWrap := func(s string) string { return "\"" + s + "\"" }
101+
file := "hack/component-versions.sh"
90102
updated = false
91103

92104
// get current versions used. Get all together to limit opening/closing
@@ -98,25 +110,26 @@ func tryUpdateFile(upstreams []struct{ owner, repo, version string }) (updated b
98110

99111
// update files to latest release where applicable
100112
for _, upstream := range upstreams {
113+
uv := quoteWrap(upstream.version)
101114
var cmd *exec.Cmd
102115
switch upstream.repo {
103116
case "serving":
104117
if upstream.version != oldSrv {
105118
fmt.Printf("update serving from '%s' to '%s'\n", oldSrv, upstream.version)
106-
cmd = exec.Command("sed", "-i", "-e", "s/"+knSrvPrefix+oldSrv+"/"+knSrvPrefix+upstream.version+"/g", file)
119+
cmd = exec.Command("sed", "-i", "-e", "s/"+knSrvPrefix+quoteWrap(oldSrv)+"/"+knSrvPrefix+uv+"/g", file)
107120
}
108121
case "eventing":
109122
if upstream.version != oldEvt {
110123
fmt.Printf("update eventing from '%s' to '%s'\n", oldEvt, upstream.version)
111-
cmd = exec.Command("sed", "-i", "-e", "s/"+knEvtPrefix+oldEvt+"/"+knEvtPrefix+upstream.version+"/g", file)
124+
cmd = exec.Command("sed", "-i", "-e", "s/"+knEvtPrefix+quoteWrap(oldEvt)+"/"+knEvtPrefix+uv+"/g", file)
112125
}
113-
case "net-concour":
126+
case "net-contour":
114127
if upstream.version != oldCntr {
115128
fmt.Printf("update contour from '%s' to '%s'\n", oldCntr, upstream.version)
116-
cmd = exec.Command("sed", "-i", "-e", "s/"+knCtrPrefix+oldCntr+"/"+knCtrPrefix+upstream.version+"/g", file)
129+
cmd = exec.Command("sed", "-i", "-e", "s/"+knCtrPrefix+quoteWrap(oldCntr)+"/"+knCtrPrefix+uv+"/g", file)
117130
}
118131
default:
119-
err = fmt.Errorf("unkown upstream.repo '%s' in for loop, exiting", upstream.repo)
132+
err = fmt.Errorf("internal error: unknown upstream.repo '%s' in for loop, exiting", upstream.repo)
120133
return false, err
121134
}
122135
err = cmd.Run()

0 commit comments

Comments
 (0)