|
| 1 | +# This file is managed by baton-admin. DO NOT EDIT!!! |
| 2 | +name: Check versions |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + |
| 8 | +jobs: |
| 9 | + block-versions-yaml-edits: |
| 10 | + runs-on: ubuntu-latest |
| 11 | + steps: |
| 12 | + - name: Check for .versions.yaml changes |
| 13 | + env: |
| 14 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 15 | + run: | |
| 16 | + changed_files=$(gh api repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}/files --paginate --jq '.[].filename') |
| 17 | + if echo "$changed_files" | grep -qx '.versions.yaml'; then |
| 18 | + echo "::error::.versions.yaml is managed by baton-admin and must not be edited in PRs. Update versions from baton-admin first." |
| 19 | + exit 1 |
| 20 | + fi |
| 21 | + echo ".versions.yaml not modified — OK" |
| 22 | +
|
| 23 | + verify-versions-match: |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - uses: actions/checkout@v4 |
| 27 | + with: |
| 28 | + fetch-depth: 0 |
| 29 | + - name: Verify go.mod matches .versions.yaml |
| 30 | + run: | |
| 31 | + # Get .versions.yaml from base branch |
| 32 | + base_ref="${{ github.event.pull_request.base.ref }}" |
| 33 | + if ! git show "origin/${base_ref}:.versions.yaml" > /tmp/base-versions.yaml 2>/dev/null; then |
| 34 | + echo "No .versions.yaml found on ${base_ref} — skipping check" |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +
|
| 38 | + mismatch=0 |
| 39 | +
|
| 40 | + # Compare go-version |
| 41 | + expected_go=$(yq -r '.go-version' /tmp/base-versions.yaml) |
| 42 | + actual_go=$(awk '/^go [0-9]/{print $2}' go.mod) |
| 43 | + if [ "$expected_go" != "$actual_go" ]; then |
| 44 | + echo "::error::Go version mismatch: .versions.yaml expects ${expected_go}, but go.mod has ${actual_go}. Update versions from baton-admin first." |
| 45 | + mismatch=1 |
| 46 | + else |
| 47 | + echo "Go version matches: ${expected_go}" |
| 48 | + fi |
| 49 | +
|
| 50 | + # Compare baton-sdk version |
| 51 | + expected_sdk=$(yq -r '.dependencies.baton-sdk // ""' /tmp/base-versions.yaml) |
| 52 | + if [ -n "$expected_sdk" ]; then |
| 53 | + actual_sdk=$(grep 'github.com/conductorone/baton-sdk' go.mod | grep -v '// indirect' | awk '{print $2}' | head -1) |
| 54 | + if [ "$expected_sdk" != "$actual_sdk" ]; then |
| 55 | + echo "::error::baton-sdk version mismatch: .versions.yaml expects ${expected_sdk}, but go.mod has ${actual_sdk}. Update versions from baton-admin first." |
| 56 | + mismatch=1 |
| 57 | + else |
| 58 | + echo "baton-sdk version matches: ${expected_sdk}" |
| 59 | + fi |
| 60 | + fi |
| 61 | +
|
| 62 | + # Compare baton-http version (warning only — not all repos use it) |
| 63 | + expected_http=$(yq -r '.dependencies.baton-http // ""' /tmp/base-versions.yaml) |
| 64 | + if [ -n "$expected_http" ]; then |
| 65 | + actual_http=$(grep 'github.com/conductorone/baton-http' go.mod | grep -v '// indirect' | awk '{print $2}' | head -1) |
| 66 | + if [ -z "$actual_http" ]; then |
| 67 | + echo "::warning::baton-http is listed in .versions.yaml (${expected_http}) but not found in go.mod" |
| 68 | + elif [ "$expected_http" != "$actual_http" ]; then |
| 69 | + echo "::error::baton-http version mismatch: .versions.yaml expects ${expected_http}, but go.mod has ${actual_http}. Update versions from baton-admin first." |
| 70 | + mismatch=1 |
| 71 | + else |
| 72 | + echo "baton-http version matches: ${expected_http}" |
| 73 | + fi |
| 74 | + fi |
| 75 | +
|
| 76 | + if [ "$mismatch" -ne 0 ]; then |
| 77 | + echo "::error::Version mismatches detected. Dependency versions in go.mod must match .versions.yaml on main. Update versions from baton-admin first." |
| 78 | + exit 1 |
| 79 | + fi |
| 80 | + echo "All versions match — OK" |
0 commit comments