Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 63 additions & 10 deletions .github/workflows/sync-kruize-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ permissions:
contents: write
pull-requests: write

# Serialize runs per base branch so overlapping runs cannot both open a PR for the same updates
concurrency:
group: sync-kruize-versions-${{ inputs.base_branch || 'mvp_demo' }}
cancel-in-progress: false

jobs:
check-and-update:
runs-on: ubuntu-latest
Expand All @@ -35,6 +40,7 @@ jobs:
- name: Checkout kruize-operator repository
uses: actions/checkout@v4
with:
ref: ${{ inputs.base_branch || 'mvp_demo' }}
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
token: ${{ steps.generate-token.outputs.token }}
fetch-depth: 0
persist-credentials: true
Expand Down Expand Up @@ -171,8 +177,52 @@ jobs:
echo "needs_ui_update=false" >> $GITHUB_OUTPUT
fi

- name: Update kruize_images.go and sample YAML
- name: Check for existing open PR with the same updates
id: existing-pr
if: steps.update-check.outputs.needs_update == 'true'
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
BASE_BRANCH: ${{ inputs.base_branch || 'mvp_demo' }}
NEEDS_AUTOTUNE_UPDATE: ${{ steps.update-check.outputs.needs_autotune_update }}
NEEDS_UI_UPDATE: ${{ steps.update-check.outputs.needs_ui_update }}
FETCHED_AUTOTUNE_VERSION: ${{ steps.fetch-autotune-version.outputs.kruize_version }}
FETCHED_UI_VERSION: ${{ steps.fetch-ui-version.outputs.ui_version }}
CURRENT_AUTOTUNE_VERSION: ${{ steps.current-versions.outputs.current_autotune_version }}
CURRENT_UI_VERSION: ${{ steps.current-versions.outputs.current_ui_version }}
run: |
set -euo pipefail

# Versions that will be present on the base branch once the update is applied
TARGET_AUTOTUNE="$CURRENT_AUTOTUNE_VERSION"
TARGET_UI="$CURRENT_UI_VERSION"
[ "$NEEDS_AUTOTUNE_UPDATE" = "true" ] && TARGET_AUTOTUNE="$FETCHED_AUTOTUNE_VERSION"
[ "$NEEDS_UI_UPDATE" = "true" ] && TARGET_UI="$FETCHED_UI_VERSION"

MARKER="<!-- kruize-version-update: autotune=${TARGET_AUTOTUNE} ui=${TARGET_UI} -->"
echo "target_autotune=$TARGET_AUTOTUNE" >> $GITHUB_OUTPUT
echo "target_ui=$TARGET_UI" >> $GITHUB_OUTPUT

# Look through all open PRs targeting the base branch for one created by this workflow
# (bump branch prefix) that carries the same marker. gh api fails on HTTP errors,
# paginates, and URL-encodes the query parameters.
MATCHES=$(gh api --paginate -X GET "repos/${{ github.repository }}/pulls" \
-f state=open -f base="$BASE_BRANCH" -f per_page=100 \
| jq -r --arg marker "$MARKER" --arg prefix "automated/bump-kruize-versions-" \
'.[] | select((.head.ref | startswith($prefix)) and ((.body // "") | contains($marker))) | .html_url')
EXISTING_PR="${MATCHES%%$'\n'*}"

if [ -n "$EXISTING_PR" ]; then
echo "An open PR for Autotune ${TARGET_AUTOTUNE} / UI ${TARGET_UI} already exists against ${BASE_BRANCH}: $EXISTING_PR"
echo "Skipping PR creation."
echo "pr_exists=true" >> $GITHUB_OUTPUT
echo "existing_pr_url=$EXISTING_PR" >> $GITHUB_OUTPUT
else
echo "No existing open PR found for these updates."
echo "pr_exists=false" >> $GITHUB_OUTPUT
fi

- name: Update kruize_images.go and sample YAML
if: steps.update-check.outputs.needs_update == 'true' && steps.existing-pr.outputs.pr_exists != 'true'
Comment thread
sourcery-ai[bot] marked this conversation as resolved.
Resolved
id: update-files
run: |
KRUIZE_VERSION="${{ steps.fetch-autotune-version.outputs.kruize_version }}"
Expand Down Expand Up @@ -202,7 +252,7 @@ jobs:
echo "sample_yaml_content=$SAMPLE_YAML_CONTENT" >> $GITHUB_OUTPUT

- name: Create branch and commit using GitHub API
if: steps.update-check.outputs.needs_update == 'true'
if: steps.update-check.outputs.needs_update == 'true' && steps.existing-pr.outputs.pr_exists != 'true'
id: create-branch
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
Expand All @@ -213,9 +263,9 @@ jobs:
REPO="${{ github.repository }}"
BASE_BRANCH="${{ inputs.base_branch || 'mvp_demo' }}"

# Get the SHA of the base branch
BASE_SHA=$(curl -s -H "Authorization: token $GH_TOKEN" \
"https://api.github.com/repos/$REPO/git/ref/heads/$BASE_BRANCH" | jq -r '.object.sha')
# Use the exact commit that was checked out (and edited) so the new tree is built
# on the same base as the file contents
BASE_SHA=$(git rev-parse HEAD)

if [ -z "$BASE_SHA" ] || [ "$BASE_SHA" = "null" ]; then
echo "Error: Failed to get base branch SHA"
Expand Down Expand Up @@ -252,7 +302,7 @@ jobs:
echo "base_sha=$BASE_SHA" >> $GITHUB_OUTPUT

- name: Commit changes using GitHub API
if: steps.update-check.outputs.needs_update == 'true'
if: steps.update-check.outputs.needs_update == 'true' && steps.existing-pr.outputs.pr_exists != 'true'
id: commit-changes
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
Expand Down Expand Up @@ -355,7 +405,7 @@ jobs:
echo "commit_sha=$NEW_COMMIT" >> $GITHUB_OUTPUT

- name: Create Pull Request using GitHub API
if: steps.update-check.outputs.needs_update == 'true'
if: steps.update-check.outputs.needs_update == 'true' && steps.existing-pr.outputs.pr_exists != 'true'
env:
GH_TOKEN: ${{ steps.generate-token.outputs.token }}
run: |
Expand All @@ -369,10 +419,12 @@ jobs:

Updates Kruize image versions from upstream repositories.

**Autotune**: ${{ steps.current-versions.outputs.current_autotune_version }} → ${{ steps.fetch-autotune-version.outputs.kruize_version }}
**UI**: ${{ steps.current-versions.outputs.current_ui_version }} → ${{ steps.fetch-ui-version.outputs.ui_version }}
**Autotune**: ${{ steps.current-versions.outputs.current_autotune_version }} → ${{ steps.existing-pr.outputs.target_autotune }}
**UI**: ${{ steps.current-versions.outputs.current_ui_version }} → ${{ steps.existing-pr.outputs.target_ui }}

- Images verified on quay.io ✓

- Images verified on quay.io ✓"
<!-- kruize-version-update: autotune=${{ steps.existing-pr.outputs.target_autotune }} ui=${{ steps.existing-pr.outputs.target_ui }} -->"

# Create pull request
PR_RESPONSE=$(curl -s -X POST -H "Authorization: token $GH_TOKEN" \
Expand Down Expand Up @@ -434,3 +486,4 @@ jobs:
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Overall" >> $GITHUB_STEP_SUMMARY
echo "- **Any Update Needed:** ${{ steps.update-check.outputs.needs_update }}" >> $GITHUB_STEP_SUMMARY
echo "- **Existing PR for same updates:** ${{ steps.existing-pr.outputs.pr_exists }} ${{ steps.existing-pr.outputs.existing_pr_url }}" >> $GITHUB_STEP_SUMMARY
Loading