diff --git a/.github/workflows/bump-k8s-for-e2e-test.yml b/.github/workflows/bump-k8s-for-e2e-test.yml index 4b6893cab..54e89b6e2 100644 --- a/.github/workflows/bump-k8s-for-e2e-test.yml +++ b/.github/workflows/bump-k8s-for-e2e-test.yml @@ -38,14 +38,26 @@ jobs: echo "changes=true" >> $GITHUB_OUTPUT fi + - name: Check if update PR already exist + id: exist + run: | + LATEST_VERSION=$(go list -m -versions -json "k8s.io/api" | jq -r '.Versions[-1]') + HEAD_BRANCH="topic/github-actions/auto-bump/test-e2e-k8s-dependencies-$LATEST_VERSION" + echo "$HEAD_BRANCH" + if ! git ls-remote --exit-code origin refs/heads/$HEAD_BRANCH; then + echo "exist=true" >> $GITHUB_OUTPUT + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT + echo "head_branch=$HEAD_BRANCH" >> $GITHUB_OUTPUT + fi + - name: Create PR - if: steps.changes.outputs.changes + if: ${{ steps.changes.outputs.changes && steps.exist.outputs.exist }} run: | - HEAD_BRANCH="github-actions/auto-bump/test-e2e-k8s-dependencies-$(date +'%Y%m%d%H%M%S')" + HEAD_BRANCH=${{ steps.exist.outputs.head_branch }} git checkout -b "$HEAD_BRANCH" git add test/e2e/go.mod test/e2e/go.sum git commit -sm "Bump kubernetes group dependencies updates for e2e test" git push origin "$HEAD_BRANCH" - gh pr create --base master --title ":seedling: Bump the kubernetes group updates for e2e test" --label "ok-to-test" --body "This is an automatic generated pull request to bump the latest k8s dependencies for e2e test." + gh pr create --base master --title ":seedling: Bump the kubernetes group updates to ${{ steps.exist.outputs.latest_version }} for e2e test" --label "ok-to-test" --body "This is an automatic generated pull request to bump the latest k8s dependencies for e2e test." env: GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.github/workflows/bump-k8s.yml b/.github/workflows/bump-k8s.yml index 5f62739dd..a8bbce350 100644 --- a/.github/workflows/bump-k8s.yml +++ b/.github/workflows/bump-k8s.yml @@ -39,17 +39,22 @@ jobs: id: exist run: | LATEST_VERSION=$(go list -m -versions -json "k8s.io/api" | jq -r '.Versions[-1]') - HEAD_BRANCH="github-actions/auto-bump/k8s-dependencies-$LATEST_VERSION" - echo "exist=$(gh repo view cloud-provider-vsphere --json branch --jq ".branches[].name | select(. == \"$HEAD_BRANCH\"))" >> $GITHUB_OUTPUT + 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 + echo "exist=true" >> $GITHUB_OUTPUT + echo "latest_version=$LATEST_VERSION" >> $GITHUB_OUTPUT + echo "head_branch=$HEAD_BRANCH" >> $GITHUB_OUTPUT + fi - name: Create PR - if: steps.changes.outputs.changes && steps.exist.outputs.exist + if: ${{ steps.changes.outputs.changes && steps.exist.outputs.exist }} run: | - HEAD_BRANCH="github-actions/auto-bump/k8s-dependencies-$(date +'%Y%m%d%H%M%S')" + HEAD_BRANCH=${{ steps.exist.outputs.head_branch }} git checkout -b "$HEAD_BRANCH" 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 updates " --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 updates to ${{ steps.exist.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 }}