-
Notifications
You must be signed in to change notification settings - Fork 1
122 lines (98 loc) · 4.49 KB
/
Copy pathcheck-docs-sync-conflict.yml
File metadata and controls
122 lines (98 loc) · 4.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
name: Check for docs site sync conflicts
# When a PR touches docs/, check if any open docs-sync PRs on cosmos/docs
# modify the same files. If so, post or update a warning comment on this PR.
on:
pull_request:
paths:
- "docs/**"
jobs:
check-conflict:
name: Check for open sync PR conflict
runs-on: ubuntu-latest
permissions:
pull-requests: write
steps:
- name: Check for conflicting sync PR on cosmos/docs
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
PR_NUMBER: ${{ github.event.pull_request.number }}
run: |
# Get files changed in this PR that are in docs/
THIS_PR_FILES=$(gh pr view "$PR_NUMBER" \
--repo cosmos/example \
--json files \
--jq '[.files[].path | select(startswith("docs/"))] | sort')
echo "Files changed in this PR: $THIS_PR_FILES"
# Get all open docs-sync PRs on cosmos/docs
SYNC_PRS=$(gh pr list \
--repo cosmos/docs \
--label "docs-sync" \
--state open \
--json number,url)
echo "Open sync PRs: $SYNC_PRS"
if [ "$SYNC_PRS" = "[]" ] || [ -z "$SYNC_PRS" ]; then
echo "No open sync PRs on cosmos/docs, all clear."
exit 0
fi
# Collect all files from all open sync PRs, mapped back to docs/ paths
ALL_SYNC_FILES="[]"
SYNC_PR_URLS=""
while IFS= read -r pr; do
SYNC_PR_NUMBER=$(echo "$pr" | jq -r '.number')
SYNC_PR_URL=$(echo "$pr" | jq -r '.url')
SYNC_PR_URLS="$SYNC_PR_URLS $SYNC_PR_URL"
SYNC_FILES=$(gh pr view "$SYNC_PR_NUMBER" \
--repo cosmos/docs \
--json files \
--jq '[.files[].path
| select(startswith("sdk/next/tutorials/example/"))
| sub("^sdk/next/tutorials/example/"; "docs/")
| sub("\\.mdx$"; ".md")
] | sort')
ALL_SYNC_FILES=$(jq -n \
--argjson a "$ALL_SYNC_FILES" \
--argjson b "$SYNC_FILES" \
'$a + $b | unique | sort')
done < <(echo "$SYNC_PRS" | jq -c '.[]')
echo "All sync PR files (mapped): $ALL_SYNC_FILES"
# Find overlapping files
OVERLAP=$(jq -n \
--argjson a "$THIS_PR_FILES" \
--argjson b "$ALL_SYNC_FILES" \
'[$a[], $b[]] | group_by(.) | map(select(length > 1)) | map(.[0])')
echo "Overlapping files: $OVERLAP"
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/example/issues/$PR_NUMBER/comments" \
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
if [ -n "$EXISTING_COMMENT" ]; then
gh api "repos/cosmos/example/issues/comments/$EXISTING_COMMENT" \
-X PATCH \
-f body="$MARKER
✅ **Sync conflict resolved** — no overlapping files with open sync PRs on \`cosmos/docs\`."
fi
exit 0
fi
OVERLAP_LIST=$(echo "$OVERLAP" | jq -r '.[] | "- `\(.)`"')
SYNC_PR_LINKS=$(echo "$SYNC_PR_URLS" | tr ' ' '\n' | grep -v '^$' | sed 's/^/- /')
COMMENT_BODY="${MARKER}
⚠️ **Potential sync conflict detected**
This PR modifies tutorial docs that are also modified in open sync PR(s) on \`cosmos/docs\`:
${SYNC_PR_LINKS}
**Overlapping files:**
${OVERLAP_LIST}
These files are kept in sync between the two repos. Merging this PR before the sync PR is resolved may cause conflicts. Please coordinate with the sync PR author or wait until it is merged first."
# Update existing comment or post a new one
EXISTING_COMMENT=$(gh api "repos/cosmos/example/issues/$PR_NUMBER/comments" \
--jq ".[] | select(.body | contains(\"$MARKER\")) | .id" | head -1)
if [ -n "$EXISTING_COMMENT" ]; then
gh api "repos/cosmos/example/issues/comments/$EXISTING_COMMENT" \
-X PATCH \
-f body="$COMMENT_BODY"
echo "Updated existing warning comment."
else
gh pr comment "$PR_NUMBER" --repo cosmos/example --body "$COMMENT_BODY"
echo "Posted new warning comment."
fi