Skip to content

ci: add Swagger freshness check on proto changes#318

Open
giwaov wants to merge 3 commits into
KiiChain:mainfrom
giwaov:ci/swagger-check
Open

ci: add Swagger freshness check on proto changes#318
giwaov wants to merge 3 commits into
KiiChain:mainfrom
giwaov:ci/swagger-check

Conversation

@giwaov
Copy link
Copy Markdown

@giwaov giwaov commented Apr 6, 2026

Summary

Add a CI workflow that automatically verifies Swagger files are up to date after proto changes, as requested in #66.

Problem

Proto file changes require running make proto-swagger-gen to regenerate client/docs/swagger-ui/swagger.yaml and swagger.json. This step is easy to forget, leading to stale API docs.

Solution

.github/workflows/swagger-check.yml

  • Triggers: PRs touching proto/, client/docs/, or x/**/query.go/x/**/tx.go files; pushes to main
  • What it does: Runs make proto-swagger-gen (which uses the ghcr.io/cosmos/proto-builder:0.13.0 Docker image) and then checks for a diff on the generated swagger files
  • On failure: Prints the exact diff showing what changed, with a clear error message telling the contributor to run make proto-swagger-gen and commit the result

How it helps

  • PRs that modify proto definitions or query/tx handlers will fail CI if the swagger files aren't regenerated
  • Clear error output shows exactly what's out of date
  • No false positives — only runs when relevant files change

Closes #66

Add a GitHub Actions workflow that runs 'make proto-swagger-gen' and
fails if the generated swagger.yaml or swagger.json differ from the
committed versions. Triggers on PRs touching proto/, client/docs/,
or query/tx handler files, and on pushes to main.

Closes KiiChain#66
@giwaov giwaov requested a review from jhelison as a code owner April 6, 2026 11:04
Copilot AI review requested due to automatic review settings April 6, 2026 11:04
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 6, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 08d54785-026e-48aa-b8fe-ac430fb2a29e

📥 Commits

Reviewing files that changed from the base of the PR and between 4bc1b4b and 2bb76b3.

📒 Files selected for processing (1)
  • .github/workflows/swagger-check.yml
🚧 Files skipped from review as they are similar to previous changes (1)
  • .github/workflows/swagger-check.yml

Walkthrough

Adds a new GitHub Actions workflow .github/workflows/swagger-check.yml named "Swagger Check". The workflow triggers on pull requests (when files under proto/**, client/docs/**, x/**/query.go, x/**/tx.go, or the workflow file change) and on pushes to main (when proto/** or client/docs/** change). It checks out the repo, sets up Go 1.24, runs make proto-swagger-gen using a Docker protoImage invocation that runs the container as the runner user and sets HOME=/tmp, then verifies that client/docs/swagger-ui/swagger.yaml and client/docs/swagger-ui/swagger.json match the committed files; differences cause an error annotation, diff output, and job failure. CHANGELOG.md is updated with a corresponding "Added" entry.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically summarizes the main change: adding a Swagger freshness check workflow triggered by proto changes.
Description check ✅ Passed The description is directly related to the changeset, providing clear context about the problem, solution, triggers, and benefits of the new CI workflow.
Linked Issues check ✅ Passed The PR fully addresses the requirements in #66: implements a CI pipeline that runs make proto-swagger-gen, checks for diffs in generated swagger files, and fails PRs when they are out of date.
Out of Scope Changes check ✅ Passed All changes are directly related to implementing the Swagger freshness check: the new workflow file and corresponding CHANGELOG entry. No extraneous modifications detected.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In @.github/workflows/swagger-check.yml:
- Around line 14-16: push path filters in swagger-check.yml only include
"proto/**" and "client/docs/**", so changes to module handler files (e.g.,
query.go and tx.go under x/**/) can skip the Swagger check; update the
workflow's push.paths configuration to also match module handler sources by
adding patterns that include x/**/query.go and x/**/tx.go (and any other
handler/source patterns your modules use) so commits touching those files
trigger the Swagger artifact validation.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bbc37580-8ecd-479b-9a35-f67ea953f891

📥 Commits

Reviewing files that changed from the base of the PR and between 988d05f and 4bc1b4b.

📒 Files selected for processing (2)
  • .github/workflows/swagger-check.yml
  • CHANGELOG.md

Comment on lines +14 to +16
paths:
- "proto/**"
- "client/docs/**"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

push path filters miss module handler changes that can affect Swagger output.

On Line 14-16, pushes to main only trigger for proto/** and client/docs/**. A direct push changing x/**/query.go or x/**/tx.go will skip this check and can let stale Swagger artifacts land.

Suggested patch
   push:
     branches:
       - main
     paths:
       - "proto/**"
       - "client/docs/**"
+      - "x/**/query.go"
+      - "x/**/tx.go"
+      - ".github/workflows/swagger-check.yml"
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
paths:
- "proto/**"
- "client/docs/**"
paths:
- "proto/**"
- "client/docs/**"
- "x/**/query.go"
- "x/**/tx.go"
- ".github/workflows/swagger-check.yml"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/swagger-check.yml around lines 14 - 16, push path filters
in swagger-check.yml only include "proto/**" and "client/docs/**", so changes to
module handler files (e.g., query.go and tx.go under x/**/) can skip the Swagger
check; update the workflow's push.paths configuration to also match module
handler sources by adding patterns that include x/**/query.go and x/**/tx.go
(and any other handler/source patterns your modules use) so commits touching
those files trigger the Swagger artifact validation.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a GitHub Actions workflow to enforce that generated Swagger artifacts remain in sync with protobuf/API changes, preventing stale API docs from being merged.

Changes:

  • Introduces .github/workflows/swagger-check.yml to run make proto-swagger-gen and fail if generated Swagger files differ from what’s committed.
  • Updates CHANGELOG.md to document the new CI safeguard.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
CHANGELOG.md Documents the addition of the Swagger freshness CI check under “Unreleased”.
.github/workflows/swagger-check.yml New CI workflow to regenerate Swagger and assert swagger.yaml/json are up to date.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +6 to +16
- "proto/**"
- "client/docs/**"
- "x/**/query.go"
- "x/**/tx.go"
- ".github/workflows/swagger-check.yml"
push:
branches:
- main
paths:
- "proto/**"
- "client/docs/**"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow path filters don’t include inputs that can change the generated Swagger output (e.g., go.mod/go.sum dependency updates and the generator logic in Makefile / proto/scripts). As-is, Swagger can become stale without this check running. Consider adding go.mod, go.sum, Makefile, and proto/scripts/** to the pull_request/push path lists (or otherwise ensuring the workflow runs when generation inputs change).

Suggested change
- "proto/**"
- "client/docs/**"
- "x/**/query.go"
- "x/**/tx.go"
- ".github/workflows/swagger-check.yml"
push:
branches:
- main
paths:
- "proto/**"
- "client/docs/**"
- "proto/**"
- "proto/scripts/**"
- "client/docs/**"
- "x/**/query.go"
- "x/**/tx.go"
- "go.mod"
- "go.sum"
- "Makefile"
- ".github/workflows/swagger-check.yml"
push:
branches:
- main
paths:
- "proto/**"
- "proto/scripts/**"
- "client/docs/**"
- "go.mod"
- "go.sum"
- "Makefile"

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +17
push:
branches:
- main
paths:
- "proto/**"
- "client/docs/**"

Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR description says pushes to main should also trigger on x//query.go and x//tx.go changes, but the push.paths list only includes proto/** and client/docs/**. Please align the workflow triggers with the documented behavior (either expand push.paths accordingly or update the PR description).

Copilot uses AI. Check for mistakes.
Comment on lines +8 to +9
- "x/**/query.go"
- "x/**/tx.go"
Copy link

Copilot AI Apr 6, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The workflow runs on changes to x//query.go and x//tx.go, but make proto-swagger-gen only scans *.proto files (and dependency protos via go.mod) during generation. This will trigger an expensive docker/go-mod step on handler-only changes that can’t affect Swagger output; consider removing these path patterns to reduce CI time, or document why they’re required.

Suggested change
- "x/**/query.go"
- "x/**/tx.go"

Copilot uses AI. Check for mistakes.
Security Auditor added 2 commits April 6, 2026 12:24
The Docker proto-builder container cannot write to the mounted workspace
volume on GitHub Actions because it runs as a non-root user different from
the runner. Override protoImage to pass --user flag matching the host uid/gid.
buf tries to create /.cache for its module cache, which fails when
running as a non-root user. Setting HOME=/tmp lets buf write its
cache to /tmp/.cache instead.
@giwaov
Copy link
Copy Markdown
Author

giwaov commented Apr 10, 2026

Hi @jhelison — friendly ping! This PR is ready for review whenever you have a moment. All CI checks are passing. Happy to address any feedback. Thanks!

@giwaov
Copy link
Copy Markdown
Author

giwaov commented Apr 21, 2026

Hey @Thaleszh, would love to get your eyes on this when you have a moment. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Automatically check for Swagger changes on build

2 participants