Skip to content

Create check-example-sync-conflict.yml#279

Merged
evanorti merged 4 commits intomainfrom
sync
Mar 31, 2026
Merged

Create check-example-sync-conflict.yml#279
evanorti merged 4 commits intomainfrom
sync

Conversation

@evanorti
Copy link
Copy Markdown
Contributor

Workflow for sync conflicts:

  1. Get the list of files changed in the PR
  2. Get the list of files changed in the open sync PR on cosmos/example
  3. Check for overlap
  4. Only comment if there's a matching file

@mintlify
Copy link
Copy Markdown

mintlify Bot commented Mar 31, 2026

Preview deployment for your docs. Learn more about Mintlify Previews.

Project Status Preview Updated (UTC)
cosmos-docs 🟢 Ready View Preview Mar 31, 2026, 8:25 PM

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Mar 31, 2026

Greptile Summary

This PR adds a new GitHub Actions workflow (check-example-sync-conflict.yml) that fires on PRs touching sdk/next/tutorials/example/** and checks whether any open docs-sync PR on cosmos/example modifies the same files, posting a warning comment if there is overlap. The approach is sound and complements the existing docs-sync-to-example.yml workflow well.

Issues found:

  • Duplicate comments (P1): The workflow triggers on every synchronize event (each new commit pushed to the PR). With no deduplication guard, a PR author who pushes several commits while the conflict exists will receive a new warning comment on every push, quickly making the PR noisy. A check against existing comments before posting — or an edit-last strategy — is needed.
  • Only first open sync PR is checked (P2): --jq '.[0]' limits the check to a single docs-sync PR on cosmos/example. If more than one is open, conflicts with the others go undetected.
  • Cross-repo token (P2): The workflow uses secrets.GITHUB_TOKEN (scoped to cosmos/docs) to read PRs from cosmos/example, whereas docs-sync-to-example.yml uses a dedicated cross-repo PAT. If cosmos/example is private, the gh pr list and gh pr view calls will fail, causing the workflow job to error and potentially blocking PRs as a broken status check.

Confidence Score: 3/5

Not ready to merge — the duplicate-comment bug will fire on every push and the cross-repo token gap could silently break the job.

There is one clear P1 defect (no deduplication means the bot spams the PR with repeated identical comments on every push) and two P2 risks (single sync PR checked; GITHUB_TOKEN may lack access to cosmos/example). The P1 alone is enough to warrant fixes before merging.

.github/workflows/check-example-sync-conflict.yml — duplicate-comment guard and token scope need addressing.

Important Files Changed

Filename Overview
.github/workflows/check-example-sync-conflict.yml New workflow that detects when a PR touches tutorial files also modified by an open docs-sync PR; has a P1 duplicate-comment bug (no deduplication guard) and a P2 risk if cosmos/example is private (uses GITHUB_TOKEN for cross-repo reads instead of the existing PAT).

Reviews (1): Last reviewed commit: "Update check-example-sync-conflict.yml" | Re-trigger Greptile

Comment on lines +80 to +92

MARKER="<!-- docs-sync-conflict-check -->"

if [ "$OVERLAP" = "[]" ] || [ -z "$OVERLAP" ]; then
echo "No overlapping files, all clear."
# If a previous warning comment exists, update it to say all clear
EXISTING_COMMENT=$(gh api "repos/cosmos/docs/issues/$PR_NUMBER/comments" \
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
if [ -n "$EXISTING_COMMENT" ]; then
gh api "repos/cosmos/docs/issues/comments/$EXISTING_COMMENT" \
-X PATCH \
-f body="$MARKER
✅ **Sync conflict resolved** — no overlapping files with open sync PRs on \`cosmos/example\`."
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.

P1 Duplicate comments on every push

The workflow triggers on every synchronize event (every new commit pushed to the PR). Since there's no guard against posting duplicate comments, a PR author who pushes multiple commits while the conflict exists will receive a new warning comment each time. This can become very noisy.

A simple fix is to check whether a matching comment already exists before posting:

# Check if a conflict comment already exists
EXISTING_COMMENT=$(gh pr view "$PR_NUMBER" \
  --repo cosmos/docs \
  --json comments \
  --jq '[.comments[].body | select(startswith("⚠️ **Potential sync conflict detected**"))] | length')

if [ "$EXISTING_COMMENT" -gt 0 ]; then
  echo "Conflict comment already posted, skipping."
  exit 0
fi

Alternatively, use the --edit-last flag or a match-and-update-or-create pattern to keep only one comment alive.

Comment on lines +39 to +44

echo "Open sync PRs: $SYNC_PRS"

if [ "$SYNC_PRS" = "[]" ] || [ -z "$SYNC_PRS" ]; then
echo "No open sync PRs on cosmos/example, all clear."
exit 0
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.

P2 Only the first open sync PR is checked

--jq '.[0]' selects only the first docs-sync PR on cosmos/example. If multiple sync PRs happen to be open simultaneously (e.g., one opened by the bot and another manually), conflicts with the second PR will go undetected.

Consider iterating over all open sync PRs:

SYNC_PRS=$(gh pr list \
  --repo cosmos/example \
  --label "docs-sync" \
  --state open \
  --json number,url,headRefName)

Then loop over each entry and union the file sets before computing the overlap.

steps:
- name: Check for conflicting sync PR on cosmos/example
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
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.

P2 Cross-repo access using GITHUB_TOKEN may fail if cosmos/example is private

GH_TOKEN is set to secrets.GITHUB_TOKEN, which is scoped to cosmos/docs. The docs-sync-to-example.yml workflow uses a separate fine-grained PAT for all operations against cosmos/example. If that repository is private, the gh pr list --repo cosmos/example and gh pr view --repo cosmos/example calls will fail with a 404/403, causing the entire job to fail and potentially surfacing as a broken required check on the PR.

If cosmos/example is public this is fine for read-only operations; but for consistency with the existing sync workflow and to future-proof against a visibility change, consider using the same cross-repo PAT (already available as a repo secret) for the cosmos/example queries.

@evanorti evanorti merged commit 1445c7c into main Mar 31, 2026
1 check passed
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.

1 participant