Update Check #212
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Update Check | |
| on: | |
| schedule: | |
| # Run every day at 6 AM UTC | |
| - cron: '0 6 * * *' | |
| workflow_dispatch: # Allow manual triggering | |
| inputs: | |
| create_pr: | |
| description: 'Create PR for Kind version update' | |
| required: false | |
| default: true | |
| type: boolean | |
| jobs: | |
| check-updates: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| pull-requests: write | |
| outputs: | |
| dind_rebuild_needed: ${{ steps.dind_update_check.outputs.dind_rebuild_needed }} | |
| kind_version_changed: ${{ steps.kind_version_check.outputs.kind_version_changed }} | |
| current_kind_version: ${{ steps.current_version.outputs.current_kind_version }} | |
| latest_kind_version: ${{ steps.latest_version.outputs.latest_kind_version }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Install dependencies | |
| run: sudo apt-get update && sudo apt-get install -y jq | |
| # ============ KIND VERSION CHECK ============ | |
| - name: Get current Kind version from VERSION file | |
| id: current_version | |
| run: | | |
| CURRENT_KIND_VERSION=$(cat VERSION) | |
| echo "current_kind_version=${CURRENT_KIND_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Current Kind version: ${CURRENT_KIND_VERSION}" | |
| - name: Get latest Kind version from GitHub API | |
| id: latest_version | |
| run: | | |
| LATEST_KIND_VERSION=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '.tag_name' | sed 's/^v//') | |
| echo "latest_kind_version=${LATEST_KIND_VERSION}" >> $GITHUB_OUTPUT | |
| echo "Latest Kind version: ${LATEST_KIND_VERSION}" | |
| # Get release info | |
| RELEASE_URL=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '.html_url') | |
| RELEASE_DATE=$(curl -s https://api.github.com/repos/kubernetes-sigs/kind/releases/latest | jq -r '.published_at') | |
| echo "release_url=${RELEASE_URL}" >> $GITHUB_OUTPUT | |
| echo "release_date=${RELEASE_DATE}" >> $GITHUB_OUTPUT | |
| - name: Compare Kind versions | |
| id: kind_version_check | |
| run: | | |
| CURRENT="${{ steps.current_version.outputs.current_kind_version }}" | |
| LATEST="${{ steps.latest_version.outputs.latest_kind_version }}" | |
| if [ "${CURRENT}" != "${LATEST}" ]; then | |
| echo "kind_version_changed=true" >> $GITHUB_OUTPUT | |
| echo "Kind version change detected: ${CURRENT} -> ${LATEST}" | |
| else | |
| echo "kind_version_changed=false" >> $GITHUB_OUTPUT | |
| echo "No Kind version change detected" | |
| fi | |
| # ============ DOCKER DIND UPDATE CHECK ============ | |
| - name: Check Docker DinD vs our image update times | |
| id: dind_update_check | |
| run: | | |
| # Get Docker DinD last updated time from Docker Hub API | |
| DIND_UPDATED=$(curl -s "https://registry.hub.docker.com/v2/repositories/library/docker/tags/dind/" | jq -r '.last_updated') | |
| DIND_TIMESTAMP=$(date -d "${DIND_UPDATED}" +%s) | |
| # Get our latest image update time from Docker Hub API | |
| OUR_UPDATED=$(curl -s "https://registry.hub.docker.com/v2/repositories/binbashing/kindwrind/tags/latest/" | jq -r '.last_updated') | |
| OUR_TIMESTAMP=$(date -d "${OUR_UPDATED}" +%s) | |
| echo "Docker DinD last updated: ${DIND_UPDATED}" | |
| echo "Our image last updated: ${OUR_UPDATED}" | |
| # Compare timestamps | |
| if [ ${DIND_TIMESTAMP} -gt ${OUR_TIMESTAMP} ]; then | |
| echo "dind_rebuild_needed=true" >> $GITHUB_OUTPUT | |
| echo "✅ Docker DinD is newer than our image - rebuild needed" | |
| # Calculate hours difference for info | |
| HOURS_DIFF=$(( (DIND_TIMESTAMP - OUR_TIMESTAMP) / 3600 )) | |
| echo "Docker DinD is ${HOURS_DIFF} hours newer than our image" | |
| else | |
| echo "dind_rebuild_needed=false" >> $GITHUB_OUTPUT | |
| echo "ℹ️ Our image is up to date with Docker DinD - no rebuild needed" | |
| # Calculate how much newer our image is (for info) | |
| HOURS_DIFF=$(( (OUR_TIMESTAMP - DIND_TIMESTAMP) / 3600 )) | |
| echo "Our image is ${HOURS_DIFF} hours newer than Docker DinD" | |
| fi | |
| # ============ ACTIONS BASED ON CHECKS ============ | |
| - name: Update Kind version files | |
| if: steps.kind_version_check.outputs.kind_version_changed == 'true' | |
| run: | | |
| LATEST_VERSION="${{ steps.latest_version.outputs.latest_kind_version }}" | |
| # Update VERSION file with new Kind version | |
| echo "${LATEST_VERSION}" > VERSION | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git add VERSION | |
| git commit -m "chore: update Kind version to ${LATEST_VERSION}" || echo "No changes to commit" | |
| git push | |
| - name: Create PR for Kind version update | |
| if: steps.kind_version_check.outputs.kind_version_changed == 'true' && (github.event.inputs.create_pr != 'false') | |
| uses: peter-evans/create-pull-request@v5 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| commit-message: "chore: update Kind version to ${{ steps.latest_version.outputs.latest_kind_version }}" | |
| title: "Update Kind version to ${{ steps.latest_version.outputs.latest_kind_version }}" | |
| body: | | |
| ## Kind Version Update | |
| This PR updates Kind from version `${{ steps.current_version.outputs.current_kind_version }}` to `${{ steps.latest_version.outputs.latest_kind_version }}`. | |
| ### Changes | |
| - Updated `VERSION` file with new Kind version: `${{ steps.latest_version.outputs.latest_kind_version }}` | |
| - Kind release: ${{ steps.latest_version.outputs.release_url }} | |
| - Release date: ${{ steps.latest_version.outputs.release_date }} | |
| ### Testing | |
| The integration tests will run automatically to verify the new version works correctly. | |
| --- | |
| *This PR was created automatically by the update check workflow* | |
| branch: update-kind-${{ steps.latest_version.outputs.latest_kind_version }} | |
| delete-branch: true | |
| - name: Trigger integration tests for Docker DinD update | |
| if: steps.dind_update_check.outputs.dind_rebuild_needed == 'true' | |
| run: | | |
| echo "✅ Docker DinD update detected - would trigger integration tests" | |
| echo "For now, we'll run a basic validation instead of full integration tests" | |
| # Basic validation - ensure VERSION file exists and contains valid version | |
| if [ -f VERSION ]; then | |
| KIND_VERSION=$(cat VERSION) | |
| echo "✅ VERSION file found with Kind version: ${KIND_VERSION}" | |
| else | |
| echo "❌ VERSION file not found!" | |
| exit 1 | |
| fi | |
| # Validate we can build the Docker image | |
| echo "🔨 Testing Docker build..." | |
| docker buildx build \ | |
| --build-arg KIND_VERSION=${KIND_VERSION} \ | |
| --load \ | |
| --tag kindwrind:test \ | |
| . | |
| echo "✅ Docker build successful" | |
| # Set output for downstream jobs | |
| echo "integration_test_result=success" >> $GITHUB_OUTPUT | |
| id: integration_test_step | |
| - name: Trigger integration tests workflow | |
| if: steps.dind_update_check.outputs.dind_rebuild_needed == 'true' && steps.integration_test_step.outputs.integration_test_result == 'success' | |
| run: | | |
| echo "🧪 Triggering integration tests workflow..." | |
| curl -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/integration-tests.yml/dispatches \ | |
| -d '{"ref":"${{ github.ref }}"}' | |
| echo "✅ Integration tests workflow triggered" | |
| - name: Wait and trigger build workflow | |
| if: steps.dind_update_check.outputs.dind_rebuild_needed == 'true' && steps.integration_test_step.outputs.integration_test_result == 'success' | |
| run: | | |
| echo "⏳ Waiting 30 seconds for integration tests to start..." | |
| sleep 30 | |
| echo "🚀 Triggering build and push workflow..." | |
| curl -X POST \ | |
| -H "Accept: application/vnd.github+json" \ | |
| -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \ | |
| -H "X-GitHub-Api-Version: 2022-11-28" \ | |
| https://api.github.com/repos/${{ github.repository }}/actions/workflows/merge-build-push.yaml/dispatches \ | |
| -d '{"ref":"${{ github.ref }}"}' | |
| echo "✅ Build and push workflow triggered" | |
| # Separate job for cleanup and summary tasks | |
| cleanup-and-summary: | |
| needs: [check-updates] | |
| if: always() # Run regardless of previous job results | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| - name: Keepalive commit | |
| if: needs.check-updates.outputs.kind_version_changed != 'true' && needs.check-updates.outputs.dind_rebuild_needed != 'true' | |
| run: | | |
| echo "No updates detected - checking if keepalive commit needed" | |
| # Prevent workflow suspension by making empty commits after 50+ days of inactivity | |
| LAST_COMMIT_DATE=$(git log -1 --format=%ct) | |
| CURRENT_DATE=$(date +%s) | |
| DAYS_SINCE=$((($CURRENT_DATE - $LAST_COMMIT_DATE) / 86400)) | |
| echo "Days since last commit: $DAYS_SINCE" | |
| if [ $DAYS_SINCE -gt 50 ]; then | |
| echo "Making keepalive commit to prevent workflow suspension" | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| git commit --allow-empty -m "chore: keepalive commit to prevent workflow suspension (${DAYS_SINCE} days since last activity)" | |
| git push | |
| else | |
| echo "No keepalive commit needed (last commit was $DAYS_SINCE days ago)" | |
| fi | |
| - name: Summary | |
| run: | | |
| echo "## Update Check Summary" >> $GITHUB_STEP_SUMMARY | |
| echo "### Kind Version Check" >> $GITHUB_STEP_SUMMARY | |
| echo "- Current Kind version: ${{ needs.check-updates.outputs.current_kind_version || 'Unknown' }}" >> $GITHUB_STEP_SUMMARY | |
| echo "- Latest Kind version: ${{ needs.check-updates.outputs.latest_kind_version || 'Unknown' }}" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.check-updates.outputs.kind_version_changed }}" == "true" ]; then | |
| echo "- ✅ Kind version update detected and processed" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- ✅ Kind version is up to date" >> $GITHUB_STEP_SUMMARY | |
| fi | |
| echo "### Docker DinD Update Check" >> $GITHUB_STEP_SUMMARY | |
| if [ "${{ needs.check-updates.outputs.dind_rebuild_needed }}" == "true" ]; then | |
| echo "- ✅ Docker DinD update detected - triggered integration tests" >> $GITHUB_STEP_SUMMARY | |
| echo "- Build and push will be triggered automatically after tests pass" >> $GITHUB_STEP_SUMMARY | |
| else | |
| echo "- ✅ Our images are up to date with Docker DinD" >> $GITHUB_STEP_SUMMARY | |
| fi |