|
| 1 | +name: Update StatefulSet Version |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_run: |
| 5 | + workflows: ["Manual Docker Build & Release"] |
| 6 | + types: |
| 7 | + - completed |
| 8 | + branches: |
| 9 | + - prod |
| 10 | + |
| 11 | +jobs: |
| 12 | + update-version: |
| 13 | + runs-on: ubuntu-latest |
| 14 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 15 | + permissions: |
| 16 | + contents: write |
| 17 | + pull-requests: write |
| 18 | + |
| 19 | + steps: |
| 20 | + - name: Checkout realtime repo |
| 21 | + uses: actions/checkout@v4 |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + token: ${{ secrets.UNITY_PAT }} |
| 25 | + |
| 26 | + - name: Extract version from mix.exs |
| 27 | + id: version |
| 28 | + run: | |
| 29 | + VERSION=$(grep -oP 'version: "\K[^"]+' mix.exs) |
| 30 | + echo "version=$VERSION" >> $GITHUB_OUTPUT |
| 31 | + echo "Extracted version: $VERSION" |
| 32 | + |
| 33 | + - name: Checkout kbve/kbve repo |
| 34 | + uses: actions/checkout@v4 |
| 35 | + with: |
| 36 | + repository: kbve/kbve |
| 37 | + token: ${{ secrets.UNITY_PAT }} |
| 38 | + path: kbve-repo |
| 39 | + fetch-depth: 0 |
| 40 | + |
| 41 | + - name: Check StatefulSet versions |
| 42 | + id: check-versions |
| 43 | + working-directory: kbve-repo |
| 44 | + run: | |
| 45 | + STATEFULSET_FILE="kbve/apps/kube/realtime/manifests/realtime-statefulset.yaml" |
| 46 | + MIX_VERSION="${{ steps.version.outputs.version }}" |
| 47 | + |
| 48 | + # Extract current image version from StatefulSet |
| 49 | + CURRENT_IMAGE_VERSION=$(grep -oP 'image: ghcr\.io/kbve/realtime:v\K[^"]+' "$STATEFULSET_FILE" || echo "") |
| 50 | + |
| 51 | + # Extract current mountPath version from StatefulSet |
| 52 | + CURRENT_MOUNT_VERSION=$(grep -oP 'mountPath: /app/lib/realtime-\K[^/]+' "$STATEFULSET_FILE" || echo "") |
| 53 | + |
| 54 | + echo "Mix.exs version: $MIX_VERSION" |
| 55 | + echo "Current image version: $CURRENT_IMAGE_VERSION" |
| 56 | + echo "Current mountPath version: $CURRENT_MOUNT_VERSION" |
| 57 | + |
| 58 | + # Check if versions match |
| 59 | + if [ "$MIX_VERSION" = "$CURRENT_IMAGE_VERSION" ] && [ "$MIX_VERSION" = "$CURRENT_MOUNT_VERSION" ]; then |
| 60 | + echo "All versions match. No update needed." |
| 61 | + echo "needs_update=false" >> $GITHUB_OUTPUT |
| 62 | + else |
| 63 | + echo "Version mismatch detected. Update needed." |
| 64 | + echo "needs_update=true" >> $GITHUB_OUTPUT |
| 65 | + echo "new_version=$MIX_VERSION" >> $GITHUB_OUTPUT |
| 66 | + fi |
| 67 | + |
| 68 | + - name: Check if PR already exists |
| 69 | + if: steps.check-versions.outputs.needs_update == 'true' |
| 70 | + id: check-pr |
| 71 | + working-directory: kbve-repo |
| 72 | + env: |
| 73 | + GH_TOKEN: ${{ secrets.UNITY_PAT }} |
| 74 | + run: | |
| 75 | + NEW_VERSION="${{ steps.check-versions.outputs.new_version }}" |
| 76 | + BRANCH_NAME="realtime-upgrade-v$NEW_VERSION" |
| 77 | + PR_TITLE="🚀 Update realtime StatefulSet to v$NEW_VERSION" |
| 78 | + |
| 79 | + # Check if PR already exists with this title |
| 80 | + EXISTING_PR=$(gh pr list --base main --state open --json title --jq ".[] | select(.title == \"$PR_TITLE\") | .title") |
| 81 | + |
| 82 | + if [ -n "$EXISTING_PR" ]; then |
| 83 | + echo "PR with title '$PR_TITLE' already exists. Skipping." |
| 84 | + echo "create_pr=false" >> $GITHUB_OUTPUT |
| 85 | + else |
| 86 | + echo "No existing PR found. Will create new PR." |
| 87 | + echo "create_pr=true" >> $GITHUB_OUTPUT |
| 88 | + echo "branch_name=$BRANCH_NAME" >> $GITHUB_OUTPUT |
| 89 | + echo "pr_title=$PR_TITLE" >> $GITHUB_OUTPUT |
| 90 | + fi |
| 91 | + |
| 92 | + - name: Create branch and update versions |
| 93 | + if: steps.check-versions.outputs.needs_update == 'true' && steps.check-pr.outputs.create_pr == 'true' |
| 94 | + working-directory: kbve-repo |
| 95 | + run: | |
| 96 | + NEW_VERSION="${{ steps.check-versions.outputs.new_version }}" |
| 97 | + BRANCH_NAME="${{ steps.check-pr.outputs.branch_name }}" |
| 98 | + STATEFULSET_FILE="kbve/apps/kube/realtime/manifests/realtime-statefulset.yaml" |
| 99 | + |
| 100 | + # Configure git |
| 101 | + git config user.name "github-actions[bot]" |
| 102 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 103 | + |
| 104 | + # Create and checkout new branch |
| 105 | + git checkout -b "$BRANCH_NAME" |
| 106 | + |
| 107 | + # Update image version in StatefulSet |
| 108 | + sed -i "s|image: ghcr\.io/kbve/realtime:v[0-9]\+\.[0-9]\+\.[0-9]\+|image: ghcr.io/kbve/realtime:v$NEW_VERSION|g" "$STATEFULSET_FILE" |
| 109 | + |
| 110 | + # Update mountPath version in StatefulSet |
| 111 | + sed -i "s|mountPath: /app/lib/realtime-[0-9]\+\.[0-9]\+\.[0-9]\+/|mountPath: /app/lib/realtime-$NEW_VERSION/|g" "$STATEFULSET_FILE" |
| 112 | + |
| 113 | + # Commit changes |
| 114 | + git add "$STATEFULSET_FILE" |
| 115 | + git commit -m "Update realtime StatefulSet to v$NEW_VERSION |
| 116 | +
|
| 117 | + - Updated Docker image tag to v$NEW_VERSION |
| 118 | + - Updated mountPath version to $NEW_VERSION |
| 119 | + - Auto-generated from realtime docker-build-release workflow" |
| 120 | + |
| 121 | + # Push branch |
| 122 | + git push origin "$BRANCH_NAME" |
| 123 | + |
| 124 | + - name: Create Pull Request |
| 125 | + if: steps.check-versions.outputs.needs_update == 'true' && steps.check-pr.outputs.create_pr == 'true' |
| 126 | + working-directory: kbve-repo |
| 127 | + env: |
| 128 | + GH_TOKEN: ${{ secrets.UNITY_PAT }} |
| 129 | + run: | |
| 130 | + NEW_VERSION="${{ steps.check-versions.outputs.new_version }}" |
| 131 | + BRANCH_NAME="${{ steps.check-pr.outputs.branch_name }}" |
| 132 | + PR_TITLE="${{ steps.check-pr.outputs.pr_title }}" |
| 133 | + |
| 134 | + # Create PR body |
| 135 | + PR_BODY="## Realtime Version Update |
| 136 | +
|
| 137 | + This PR updates the realtime StatefulSet to version **v$NEW_VERSION** to match the latest release. |
| 138 | +
|
| 139 | + **Changes included:** |
| 140 | + - Updated Docker image tag from \`ghcr.io/kbve/realtime:v*\` to \`ghcr.io/kbve/realtime:v$NEW_VERSION\` |
| 141 | + - Updated mountPath from \`/app/lib/realtime-*/\` to \`/app/lib/realtime-$NEW_VERSION/\` |
| 142 | +
|
| 143 | + **Triggered by:** |
| 144 | + - Successful completion of realtime docker-build-release workflow |
| 145 | + - Version mismatch detection between mix.exs and StatefulSet |
| 146 | +
|
| 147 | + **Review checklist:** |
| 148 | + - [ ] Verify the version numbers are correct |
| 149 | + - [ ] Check that both image tag and mountPath are updated consistently |
| 150 | + - [ ] Confirm this matches the intended release version |
| 151 | +
|
| 152 | + --- |
| 153 | + *This PR was automatically created by the update-statefulset-version workflow*" |
| 154 | + |
| 155 | + gh pr create \ |
| 156 | + --base main \ |
| 157 | + --head "$BRANCH_NAME" \ |
| 158 | + --title "$PR_TITLE" \ |
| 159 | + --body "$PR_BODY" |
| 160 | + |
| 161 | + echo "✅ Created PR: $PR_TITLE" |
0 commit comments