|
| 1 | +# Copyright 2026 The kpt Authors |
| 2 | +# |
| 3 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +# you may not use this file except in compliance with the License. |
| 5 | +# You may obtain a copy of the License at |
| 6 | +# |
| 7 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +# |
| 9 | +# Unless required by applicable law or agreed to in writing, software |
| 10 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +# See the License for the specific language governing permissions and |
| 13 | +# limitations under the License. |
| 14 | + |
| 15 | +name: Version Drift Check |
| 16 | +on: |
| 17 | + pull_request: |
| 18 | + workflow_dispatch: |
| 19 | + |
| 20 | +jobs: |
| 21 | + check-versions: |
| 22 | + name: Check Version Consistency |
| 23 | + runs-on: ubuntu-latest |
| 24 | + steps: |
| 25 | + - name: Checkout |
| 26 | + uses: actions/checkout@v4 |
| 27 | + |
| 28 | + - name: Extract versions from sources |
| 29 | + id: extract |
| 30 | + run: | |
| 31 | + # Extract Go version from go.mod |
| 32 | + go_version=$(grep '^go ' go.mod | awk '{print $2}') |
| 33 | + echo "go_version=${go_version}" >> $GITHUB_OUTPUT |
| 34 | + |
| 35 | + # Extract kpt version from go.mod (require line) |
| 36 | + kpt_version=$(grep 'github.com/kptdev/kpt ' go.mod | grep -oP 'v\d+\.\d+\.\d+(-[a-zA-Z0-9.]+)?' | head -1) |
| 37 | + echo "kpt_version=${kpt_version}" >> $GITHUB_OUTPUT |
| 38 | + |
| 39 | + # Extract kind version from porch-e2e-ci-jobs.yaml (after kind-action@v1) |
| 40 | + kind_version=$(awk '/helm\/kind-action@v1/,/version:/ {if (/version:/) print $2}' .github/workflows/porch-e2e-ci-jobs.yaml | head -1) |
| 41 | + echo "kind_version=${kind_version}" >> $GITHUB_OUTPUT |
| 42 | + |
| 43 | + # Extract git and docker versions from ubuntu-latest runner |
| 44 | + git_version=$(git --version | awk '{print $3}') |
| 45 | + echo "git_version=${git_version}" >> $GITHUB_OUTPUT |
| 46 | + |
| 47 | + docker_version=$(docker --version | grep -oP 'version \K[0-9.]+') |
| 48 | + echo "docker_version=${docker_version}" >> $GITHUB_OUTPUT |
| 49 | +
|
| 50 | + - name: Extract versions from config.toml |
| 51 | + id: config |
| 52 | + run: | |
| 53 | + # Extract versions from config.toml (stored without 'v' prefix) |
| 54 | + go_version=$(grep '^version_go = ' docs/config.toml | cut -d'"' -f2) |
| 55 | + echo "go_version=${go_version}" >> $GITHUB_OUTPUT |
| 56 | + |
| 57 | + kpt_version=$(grep '^version_kpt = ' docs/config.toml | cut -d'"' -f2) |
| 58 | + echo "kpt_version=v${kpt_version}" >> $GITHUB_OUTPUT |
| 59 | + |
| 60 | + kind_version=$(grep '^version_kind = ' docs/config.toml | cut -d'"' -f2) |
| 61 | + echo "kind_version=v${kind_version}" >> $GITHUB_OUTPUT |
| 62 | + |
| 63 | + kube_version=$(grep '^version_kube = ' docs/config.toml | cut -d'"' -f2) |
| 64 | + echo "kube_version=${kube_version}" >> $GITHUB_OUTPUT |
| 65 | + |
| 66 | + git_version=$(grep '^version_git = ' docs/config.toml | cut -d'"' -f2) |
| 67 | + echo "git_version=${git_version}" >> $GITHUB_OUTPUT |
| 68 | + |
| 69 | + docker_version=$(grep '^version_docker = ' docs/config.toml | cut -d'"' -f2) |
| 70 | + echo "docker_version=${docker_version}" >> $GITHUB_OUTPUT |
| 71 | +
|
| 72 | + - name: Compare versions |
| 73 | + id: compare |
| 74 | + run: | |
| 75 | + echo "=== Version Consistency Check ===" >> $GITHUB_STEP_SUMMARY |
| 76 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 77 | + |
| 78 | + errors=0 |
| 79 | + warnings=0 |
| 80 | + |
| 81 | + # Go version check (CRITICAL - controls build environment) |
| 82 | + if [ "${{ steps.extract.outputs.go_version }}" != "${{ steps.config.outputs.go_version }}" ]; then |
| 83 | + echo "### FAIL: Go version mismatch" >> $GITHUB_STEP_SUMMARY |
| 84 | + echo "- Source (go.mod): ${{ steps.extract.outputs.go_version }}" >> $GITHUB_STEP_SUMMARY |
| 85 | + echo "- Docs (config.toml): ${{ steps.config.outputs.go_version }}" >> $GITHUB_STEP_SUMMARY |
| 86 | + errors=$((errors + 1)) |
| 87 | + else |
| 88 | + echo "✓ Go: ${{ steps.extract.outputs.go_version }}" >> $GITHUB_STEP_SUMMARY |
| 89 | + fi |
| 90 | + |
| 91 | + # kpt version check (CRITICAL - core dependency) |
| 92 | + if [ "${{ steps.extract.outputs.kpt_version }}" != "${{ steps.config.outputs.kpt_version }}" ]; then |
| 93 | + echo "### FAIL: kpt version mismatch" >> $GITHUB_STEP_SUMMARY |
| 94 | + echo "- Source (go.mod): ${{ steps.extract.outputs.kpt_version }}" >> $GITHUB_STEP_SUMMARY |
| 95 | + echo "- Docs (config.toml): ${{ steps.config.outputs.kpt_version }}" >> $GITHUB_STEP_SUMMARY |
| 96 | + errors=$((errors + 1)) |
| 97 | + else |
| 98 | + echo "✓ kpt: ${{ steps.extract.outputs.kpt_version }}" >> $GITHUB_STEP_SUMMARY |
| 99 | + fi |
| 100 | + |
| 101 | + # kind version check (WARNING - test environment) |
| 102 | + if [ "${{ steps.extract.outputs.kind_version }}" != "${{ steps.config.outputs.kind_version }}" ]; then |
| 103 | + echo "### WARN: kind version mismatch" >> $GITHUB_STEP_SUMMARY |
| 104 | + echo "- Source (.github/workflows): ${{ steps.extract.outputs.kind_version }}" >> $GITHUB_STEP_SUMMARY |
| 105 | + echo "- Docs (config.toml): ${{ steps.config.outputs.kind_version }}" >> $GITHUB_STEP_SUMMARY |
| 106 | + echo "Consider updating docs/config.toml to match the test environment." >> $GITHUB_STEP_SUMMARY |
| 107 | + warnings=$((warnings + 1)) |
| 108 | + else |
| 109 | + echo "✓ kind: ${{ steps.extract.outputs.kind_version }}" >> $GITHUB_STEP_SUMMARY |
| 110 | + fi |
| 111 | + |
| 112 | + # Kubernetes version (INFORMATIONAL - derived from kind) |
| 113 | + echo "ℹ Kubernetes (derived from kind): ${{ steps.extract.outputs.kind_version }} uses k8s ${{ steps.config.outputs.kube_version }}" >> $GITHUB_STEP_SUMMARY |
| 114 | + |
| 115 | + # Git version (INFORMATIONAL - runner-provided) |
| 116 | + if [ "${{ steps.extract.outputs.git_version }}" != "${{ steps.config.outputs.git_version }}" ]; then |
| 117 | + echo "ℹ Git: runner has ${{ steps.extract.outputs.git_version }}, docs list ${{ steps.config.outputs.git_version }} (advisory - updated by GitHub)" >> $GITHUB_STEP_SUMMARY |
| 118 | + else |
| 119 | + echo "✓ Git: ${{ steps.extract.outputs.git_version }}" >> $GITHUB_STEP_SUMMARY |
| 120 | + fi |
| 121 | + |
| 122 | + # Docker version (INFORMATIONAL - runner-provided) |
| 123 | + if [ "${{ steps.extract.outputs.docker_version }}" != "${{ steps.config.outputs.docker_version }}" ]; then |
| 124 | + echo "ℹ Docker: runner has ${{ steps.extract.outputs.docker_version }}, docs list ${{ steps.config.outputs.docker_version }} (advisory - updated by GitHub)" >> $GITHUB_STEP_SUMMARY |
| 125 | + else |
| 126 | + echo "✓ Docker: ${{ steps.extract.outputs.docker_version }}" >> $GITHUB_STEP_SUMMARY |
| 127 | + fi |
| 128 | + |
| 129 | + echo "" >> $GITHUB_STEP_SUMMARY |
| 130 | + echo "errors=${errors}" >> $GITHUB_OUTPUT |
| 131 | + echo "warnings=${warnings}" >> $GITHUB_OUTPUT |
| 132 | + |
| 133 | + if [ "$warnings" -gt 0 ]; then |
| 134 | + echo "**Note:** Review warnings above and update docs/config.toml if needed." >> $GITHUB_STEP_SUMMARY |
| 135 | + fi |
| 136 | +
|
| 137 | + - name: Fail if critical mismatches |
| 138 | + if: steps.compare.outputs.errors > 0 |
| 139 | + run: | |
| 140 | + echo "Critical version mismatches detected. Please update docs/config.toml to match the source files." |
| 141 | + exit 1 |
0 commit comments