|
| 1 | +name: kagent contract |
| 2 | + |
| 3 | +# Checks every day, with Weaver, that kagent's telemetry registry still has what |
| 4 | +# agentevals reads from kagent spans, and keeps one labelled issue up to date |
| 5 | +# while it does not. It never runs on pull requests: kagent changes on its own |
| 6 | +# schedule. See tests/contract/kagent/. |
| 7 | +on: |
| 8 | + schedule: |
| 9 | + - cron: "23 5 * * *" |
| 10 | + workflow_dispatch: |
| 11 | + |
| 12 | +permissions: {} |
| 13 | + |
| 14 | +concurrency: |
| 15 | + group: kagent-contract |
| 16 | + cancel-in-progress: false |
| 17 | + |
| 18 | +defaults: |
| 19 | + run: |
| 20 | + shell: bash |
| 21 | + |
| 22 | +env: |
| 23 | + ISSUE_LABEL: kagent-contract |
| 24 | + |
| 25 | +jobs: |
| 26 | + check: |
| 27 | + runs-on: ubuntu-latest |
| 28 | + timeout-minutes: 30 |
| 29 | + permissions: |
| 30 | + contents: read |
| 31 | + steps: |
| 32 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 33 | + with: |
| 34 | + persist-credentials: false |
| 35 | + |
| 36 | + - name: Self test the contract policy |
| 37 | + run: tests/contract/kagent/test.sh |
| 38 | + |
| 39 | + # The release tag is fetched and used in one step, and check.sh validates it |
| 40 | + # before use, so nothing fetched passes through GITHUB_ENV or an expression. |
| 41 | + - name: Check kagent main and the newest release |
| 42 | + env: |
| 43 | + GH_TOKEN: ${{ github.token }} |
| 44 | + run: | |
| 45 | + release="$(gh release view --repo kagent-dev/kagent --json tagName --jq .tagName)" |
| 46 | + tests/contract/kagent/check.sh report.md main "$release" |
| 47 | +
|
| 48 | + - name: Summarize |
| 49 | + if: always() |
| 50 | + continue-on-error: true |
| 51 | + run: | |
| 52 | + { |
| 53 | + if [ -f report.md ]; then cat report.md; fi |
| 54 | + echo |
| 55 | + echo "## kagent main against the committed snapshot" |
| 56 | + echo |
| 57 | + tests/contract/kagent/weaver.sh registry diff --v2 --diff-format markdown \ |
| 58 | + -r "https://github.com/kagent-dev/kagent.git@main[telemetry/registry]" \ |
| 59 | + --baseline-registry /contract/registries/main-2cc3ffae |
| 60 | + } >> "$GITHUB_STEP_SUMMARY" |
| 61 | +
|
| 62 | + - name: Upload the report |
| 63 | + if: always() |
| 64 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 65 | + with: |
| 66 | + name: kagent-contract-report |
| 67 | + path: report.md |
| 68 | + if-no-files-found: ignore |
| 69 | + |
| 70 | + # The issue body is fixed text plus the report, whose fetched content sits in a |
| 71 | + # code block without backticks. It is always passed as a file, never through the shell. |
| 72 | + report-failure: |
| 73 | + needs: check |
| 74 | + if: failure() |
| 75 | + runs-on: ubuntu-latest |
| 76 | + timeout-minutes: 10 |
| 77 | + permissions: |
| 78 | + issues: write |
| 79 | + steps: |
| 80 | + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 81 | + continue-on-error: true |
| 82 | + with: |
| 83 | + name: kagent-contract-report |
| 84 | + |
| 85 | + - name: Open or update the issue |
| 86 | + env: |
| 87 | + GH_TOKEN: ${{ github.token }} |
| 88 | + GH_REPO: ${{ github.repository }} |
| 89 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 90 | + run: | |
| 91 | + set -euo pipefail |
| 92 | + { |
| 93 | + echo "The daily kagent contract check failed: $RUN_URL" |
| 94 | + echo |
| 95 | + if [ -f report.md ]; then |
| 96 | + cat report.md |
| 97 | + else |
| 98 | + echo "The check failed before it wrote a report (for example in the self test). See the run log." |
| 99 | + echo |
| 100 | + echo "<!-- kagent-contract-report: none -->" |
| 101 | + fi |
| 102 | + } > body.md |
| 103 | + # The report appends its marker last, so the last match is the real one. |
| 104 | + marker="$(grep -o 'kagent-contract-report: [0-9a-f]*' body.md | tail -n 1)" |
| 105 | +
|
| 106 | + number="$(gh issue list --label "$ISSUE_LABEL" --state open --json number --jq '.[0].number // empty')" |
| 107 | + if [ -z "$number" ]; then |
| 108 | + gh label create "$ISSUE_LABEL" --color B60205 --force \ |
| 109 | + --description "The daily check of kagent's telemetry registry failed" |
| 110 | + gh issue create --title "kagent telemetry contract check failed" \ |
| 111 | + --label "$ISSUE_LABEL" --body-file body.md |
| 112 | + exit 0 |
| 113 | + fi |
| 114 | +
|
| 115 | + # Only comment when the report changed since the last update. Comments |
| 116 | + # from people are ignored, so nobody can hide a change by quoting a marker. |
| 117 | + latest="$(gh issue view "$number" --json body,comments \ |
| 118 | + --jq '([.comments[] | select(.author.login == "github-actions")] | last | .body) // .body')" |
| 119 | + if grep -qF "$marker" <<<"$latest"; then |
| 120 | + echo "Issue #$number already has this report." |
| 121 | + else |
| 122 | + gh issue comment "$number" --body-file body.md |
| 123 | + fi |
| 124 | +
|
| 125 | + close-resolved: |
| 126 | + needs: check |
| 127 | + if: success() |
| 128 | + runs-on: ubuntu-latest |
| 129 | + timeout-minutes: 10 |
| 130 | + permissions: |
| 131 | + issues: write |
| 132 | + steps: |
| 133 | + - name: Close the issue once the check passes again |
| 134 | + env: |
| 135 | + GH_TOKEN: ${{ github.token }} |
| 136 | + GH_REPO: ${{ github.repository }} |
| 137 | + RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} |
| 138 | + run: | |
| 139 | + set -euo pipefail |
| 140 | + number="$(gh issue list --label "$ISSUE_LABEL" --state open --json number --jq '.[0].number // empty')" |
| 141 | + if [ -n "$number" ]; then |
| 142 | + gh issue close "$number" --comment "The kagent contract check passes again: $RUN_URL" |
| 143 | + fi |
0 commit comments