Skip to content

Commit

Permalink
Merge pull request #960 from kubernetes/topic/xudong/fix-auto-bump-gi…
Browse files Browse the repository at this point in the history
…thub-action

fix auto bump github action
  • Loading branch information
k8s-ci-robot authored Apr 2, 2024
2 parents b7b7109 + d41d34d commit a4dcfd6
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 10 deletions.
9 changes: 6 additions & 3 deletions .github/workflows/bump-k8s.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: |
Expand All @@ -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
Expand All @@ -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 }}
2 changes: 2 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ on:
paths:
- "charts/**"

workflow_dispatch: # Use for manaully trigger to debug

jobs:
release:
runs-on: ubuntu-latest
Expand Down
38 changes: 31 additions & 7 deletions hack/bump-k8s-dep.sh
Original file line number Diff line number Diff line change
Expand Up @@ -33,30 +33,54 @@ 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
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}"
go get -u "${dep}"@"${latest_version}"
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"

0 comments on commit a4dcfd6

Please sign in to comment.