From 5ea9d74d34a882be9c7998269f77ec4959c8dffb Mon Sep 17 00:00:00 2001 From: xudong liu Date: Mon, 1 Apr 2024 05:28:33 +0000 Subject: [PATCH 1/3] fix auto bump github action Signed-off-by: xudong liu --- .github/workflows/release.yml | 2 ++ hack/bump-k8s-dep.sh | 25 +++++++++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f587bb3ea..c2ae51295 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,8 @@ on: paths: - "charts/**" + workflow_dispatch: # Use for manaully trigger to debug + jobs: release: runs-on: ubuntu-latest diff --git a/hack/bump-k8s-dep.sh b/hack/bump-k8s-dep.sh index a1444db1d..3046a069e 100755 --- a/hack/bump-k8s-dep.sh +++ b/hack/bump-k8s-dep.sh @@ -33,11 +33,32 @@ GREEN='\033[0;32m' BLUE='\033[0;34m' RESET='\033[0m' # Reset color to default +pre_release_regex="-((alpha|beta|rc)\.[0-9]+)" + +get_latest_version() { + local current_version=$1 + local dep=$2 + local minor_version + local latest_version + + if [[ $current_version =~ $pre_release_regex ]]; then + echo "$current_version is a pre-release version, checking for the same minor version latest patch release." + minor_version=$(echo "$current_version" | grep -oP 'v[0-9]+\.[0-9]+') + latest_version=$(go list -m -versions -json "$dep" | jq -r "$minor_version" '.Versions[] | select(startswith($minor_version))' | tail -n 1) + else + echo "$current_version is a stable version, checking for the latest minor version." + latest_version=$(go list -m -versions -json "$dep" | jq -r '.Versions[-1]') + fi + + echo "$latest_version" +} + + check_and_bump_dependency() { dep=$1 + current_version=$(go list -m -f '{{.Version}}' "${dep}") - latest_version=$(go list -m -versions -json "${dep}" | jq -r '.Versions[-1]') - # latest_stable_version=$(go list -m -u -json ${dep} | jq -r .Version) + latest_version=$(get_latest_version "$current_version" "$dep") # filter out the alpha release if [[ $latest_version =~ alpha\.([0-9]+)$ ]]; then From 2af83d111cb1b29445bccb0910a9112bc82935ae Mon Sep 17 00:00:00 2001 From: xudong liu Date: Mon, 1 Apr 2024 05:28:33 +0000 Subject: [PATCH 2/3] fix auto bump github action Signed-off-by: xudong liu --- .github/workflows/release.yml | 2 ++ hack/bump-k8s-dep.sh | 27 ++++++++++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index f587bb3ea..c2ae51295 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -7,6 +7,8 @@ on: paths: - "charts/**" + workflow_dispatch: # Use for manaully trigger to debug + jobs: release: runs-on: ubuntu-latest diff --git a/hack/bump-k8s-dep.sh b/hack/bump-k8s-dep.sh index a1444db1d..a86214f2f 100755 --- a/hack/bump-k8s-dep.sh +++ b/hack/bump-k8s-dep.sh @@ -33,11 +33,32 @@ GREEN='\033[0;32m' BLUE='\033[0;34m' RESET='\033[0m' # Reset color to default +pre_release_regex="-((alpha|beta|rc)\.[0-9]+)" + +get_latest_version() { + local current_version=$1 + local dep=$2 + local minor_version + local latest_version + + if [[ $current_version =~ $pre_release_regex ]]; then + echo "$current_version is a pre-release version, checking for the same minor version latest patch release." 1>&2 + minor_version=$(echo "$current_version" | grep -oP 'v[0-9]+\.[0-9]+') + latest_version=$(go list -m -versions -json "$dep" | jq -r '.Versions[] | select(startswith("'"$minor_version"'"))' | tail -n 1) + else + echo "$current_version is a stable version, checking for the latest minor version." 1>&2 + latest_version=$(go list -m -versions -json "$dep" | jq -r '.Versions[-1]') + fi + + echo "$latest_version" +} + + check_and_bump_dependency() { dep=$1 + current_version=$(go list -m -f '{{.Version}}' "${dep}") - latest_version=$(go list -m -versions -json "${dep}" | jq -r '.Versions[-1]') - # latest_stable_version=$(go list -m -u -json ${dep} | jq -r .Version) + latest_version=$(get_latest_version "$current_version" "$dep") # filter out the alpha release if [[ $latest_version =~ alpha\.([0-9]+)$ ]]; then @@ -50,7 +71,7 @@ check_and_bump_dependency() { echo -e "${BLUE} $dep@$current_version is already up to date.${RESET}" else echo -e "${GREEN} Updating $dep to $latest_version ...${RESET}" - go get -u "${dep}"@"${latest_version}" + go get "${dep}"@"${latest_version}" fi } From d41d34d8b6bcee4c7d45f674576462a24746d82b Mon Sep 17 00:00:00 2001 From: xudong liu Date: Tue, 2 Apr 2024 04:26:58 +0000 Subject: [PATCH 3/3] fix auto bump github action Signed-off-by: xudong liu --- .github/workflows/bump-k8s.yml | 9 ++++++--- hack/bump-k8s-dep.sh | 12 ++++++++---- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/bump-k8s.yml b/.github/workflows/bump-k8s.yml index f1d6fde4c..c17914580 100644 --- a/.github/workflows/bump-k8s.yml +++ b/.github/workflows/bump-k8s.yml @@ -20,7 +20,10 @@ jobs: go-version-file: 'go.mod' - name: Bump latest k8s.io dependencies - run: bash ./hack/bump-k8s-dep.sh + id: bump + run: | + LATEST_VERSION=$(./hack/bump-k8s-dep.sh) + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT - name: Configure Git run: | @@ -38,7 +41,7 @@ jobs: - name: Check if update PR exist id: exist run: | - LATEST_VERSION=$(go list -m -versions -json "k8s.io/api" | jq -r '.Versions[-1]') + LATEST_VERSION=${{ steps.bump.outputs.latest_version }} HEAD_BRANCH="topic/github-actions/auto-bump/k8s-dependencies-$LATEST_VERSION" echo "$HEAD_BRANCH" if ! git ls-remote --exit-code origin refs/heads/$HEAD_BRANCH; then @@ -55,6 +58,6 @@ jobs: git add go.mod go.sum git commit -sm "Bump Kubernetes group dependencies updates" git push origin "$HEAD_BRANCH" - gh pr create --base master --title ":seedling: Bump the Kubernetes group to ${{ steps.exist.outputs.latest_version }}" --label "ok-to-test" --body "This is an automatically generated pull request to bump the latest k8s dependencies." + gh pr create --base master --title ":seedling: Bump the Kubernetes group to ${{ steps.bump.outputs.latest_version }}" --label "ok-to-test" --body "This is an automatically generated pull request to bump the latest k8s dependencies." env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/hack/bump-k8s-dep.sh b/hack/bump-k8s-dep.sh index d5fe97969..b87de1c60 100755 --- a/hack/bump-k8s-dep.sh +++ b/hack/bump-k8s-dep.sh @@ -61,22 +61,26 @@ check_and_bump_dependency() { # filter out the alpha release if [[ $latest_version =~ alpha\.([0-9]+)$ ]]; then - echo -e "${BLUE} Skip auto bump for alpha release: [$dep@$latest_version]${RESET}" + echo -e "${BLUE} Skip auto bump for alpha release: [$dep@$latest_version]${RESET}" 1>&2 return fi # Bump the version if needed if [ "$current_version" == "$latest_version" ]; then - echo -e "${BLUE} $dep@$current_version is already up to date.${RESET}" + echo -e "${BLUE} $dep@$current_version is already up to date.${RESET}" 1>&2 else - echo -e "${GREEN} Updating $dep to $latest_version ...${RESET}" + echo -e "${GREEN} Updating $dep to $latest_version ...${RESET}" 1>&2 go get "${dep}"@"${latest_version}" fi + + echo "$latest_version" } # Loop through the list of dependencies for dep in "${dependencies[@]}"; do - check_and_bump_dependency "$dep" + latest_version=$(check_and_bump_dependency "$dep") done go mod tidy + +echo "$latest_version"