-
Notifications
You must be signed in to change notification settings - Fork 11
Feat/example tutorial and sync #258
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
21c0c3b
edc3bf3
24def85
72787a6
e92e0bf
c6ca1f0
092d9b3
5d16919
93ea22e
f91fa22
4013495
0b58459
43385df
0a70b8c
e66fb42
33f150d
ef28ee7
8ee37bd
ac04482
d5319ed
f57502f
ae1cd2f
cd1d078
25a93be
76e753b
fda51ea
56abe1c
0706147
c62b447
48ecdca
f55022c
05ffb0a
dce3990
f91c1c0
3b8105c
6c642c2
c664b47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,105 @@ | ||||||||||||||||||
| name: Docs Sync → cosmos/example | ||||||||||||||||||
|
|
||||||||||||||||||
| # Runs when example tutorial .mdx files change on main. | ||||||||||||||||||
| # Transforms .mdx → .md and opens a PR on the example repo. | ||||||||||||||||||
| # If a sync PR is already open, updates it instead of opening a new one. | ||||||||||||||||||
| # Skip if the commit was itself produced by the sync (loop guard). | ||||||||||||||||||
|
|
||||||||||||||||||
| on: | ||||||||||||||||||
| push: | ||||||||||||||||||
| branches: | ||||||||||||||||||
| - main | ||||||||||||||||||
| paths: | ||||||||||||||||||
| - "sdk/next/tutorials/example/**" | ||||||||||||||||||
|
|
||||||||||||||||||
| jobs: | ||||||||||||||||||
| sync: | ||||||||||||||||||
| name: Sync example tutorials to cosmos/example | ||||||||||||||||||
| runs-on: ubuntu-latest | ||||||||||||||||||
| # Loop guard: skip commits that the docs-sync bot created | ||||||||||||||||||
| if: "!contains(github.event.head_commit.message, '[docs-sync]')" | ||||||||||||||||||
|
|
||||||||||||||||||
| steps: | ||||||||||||||||||
| - name: Checkout cosmos/docs | ||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Set up Python | ||||||||||||||||||
| uses: actions/setup-python@v5 | ||||||||||||||||||
| with: | ||||||||||||||||||
| python-version: "3.12" | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Checkout cosmos/example | ||||||||||||||||||
| uses: actions/checkout@v4 | ||||||||||||||||||
| with: | ||||||||||||||||||
| repository: cosmos/example | ||||||||||||||||||
| # Fine-grained PAT with contents:write and pull-requests:write on cosmos/example | ||||||||||||||||||
| token: ${{ secrets.EXAMPLE_REPO_TOKEN }} | ||||||||||||||||||
| path: cosmos-example | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Transform Mintlify → example repo format | ||||||||||||||||||
| run: | | ||||||||||||||||||
| python3 scripts/docs-sync/transform.py \ | ||||||||||||||||||
| --direction to-example \ | ||||||||||||||||||
| --input sdk/next/tutorials/example/ \ | ||||||||||||||||||
| --output-dir cosmos-example/docs/ | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Check for changes | ||||||||||||||||||
| id: diff | ||||||||||||||||||
| run: | | ||||||||||||||||||
| cd cosmos-example | ||||||||||||||||||
| [ -n "$(git status --porcelain docs/)" ] \ | ||||||||||||||||||
| && echo "changed=true" >> "$GITHUB_OUTPUT" \ | ||||||||||||||||||
| || echo "changed=false" >> "$GITHUB_OUTPUT" | ||||||||||||||||||
|
|
||||||||||||||||||
| - name: Open or update PR on cosmos/example | ||||||||||||||||||
| if: steps.diff.outputs.changed == 'true' | ||||||||||||||||||
| env: | ||||||||||||||||||
| GH_TOKEN: ${{ secrets.EXAMPLE_REPO_TOKEN }} | ||||||||||||||||||
| run: | | ||||||||||||||||||
| cd cosmos-example | ||||||||||||||||||
|
|
||||||||||||||||||
| git config user.name "docs-sync[bot]" | ||||||||||||||||||
| git config user.email "docs-sync[bot]@users.noreply.github.com" | ||||||||||||||||||
|
|
||||||||||||||||||
| # Check for an existing open sync PR | ||||||||||||||||||
| EXISTING=$(gh pr list \ | ||||||||||||||||||
| --repo cosmos/example \ | ||||||||||||||||||
| --label "docs-sync" \ | ||||||||||||||||||
| --state open \ | ||||||||||||||||||
| --json number,headRefName \ | ||||||||||||||||||
| --jq '.[0]') | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -n "$EXISTING" ]; then | ||||||||||||||||||
| PR_NUMBER=$(echo "$EXISTING" | jq -r '.number') | ||||||||||||||||||
| BRANCH=$(echo "$EXISTING" | jq -r '.headRefName') | ||||||||||||||||||
|
|
||||||||||||||||||
| # Stash the transform output before switching branches, | ||||||||||||||||||
| # then restore it on top of the existing sync branch. | ||||||||||||||||||
| git stash | ||||||||||||||||||
| git fetch origin "$BRANCH" | ||||||||||||||||||
| git checkout "$BRANCH" | ||||||||||||||||||
| git stash pop | ||||||||||||||||||
| git add docs/ | ||||||||||||||||||
| git commit -m "docs: sync example tutorials from cosmos/docs [docs-sync]" | ||||||||||||||||||
| git push origin "$BRANCH" | ||||||||||||||||||
|
|
||||||||||||||||||
| gh pr comment "$PR_NUMBER" \ | ||||||||||||||||||
| --repo cosmos/example \ | ||||||||||||||||||
|
Comment on lines
+84
to
+87
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The fix is to include untracked files in the stash:
Suggested change
Using |
||||||||||||||||||
| --body "Sync updated: cosmos/docs was updated before this PR merged. Branch has been refreshed — please re-review." | ||||||||||||||||||
| echo "Updated existing PR #$PR_NUMBER" | ||||||||||||||||||
|
|
||||||||||||||||||
| else | ||||||||||||||||||
| BRANCH="docs-sync/from-docs-$(date +%Y%m%d-%H%M%S)" | ||||||||||||||||||
| git checkout -b "$BRANCH" | ||||||||||||||||||
| git add docs/ | ||||||||||||||||||
| git commit -m "docs: sync example tutorials from cosmos/docs [docs-sync]" | ||||||||||||||||||
| git push origin "$BRANCH" | ||||||||||||||||||
|
evanorti marked this conversation as resolved.
|
||||||||||||||||||
|
|
||||||||||||||||||
| gh pr create \ | ||||||||||||||||||
| --repo cosmos/example \ | ||||||||||||||||||
| --head "$BRANCH" \ | ||||||||||||||||||
| --base main \ | ||||||||||||||||||
| --title "docs: sync example tutorials from cosmos/docs" \ | ||||||||||||||||||
| --label "docs-sync" \ | ||||||||||||||||||
| --body "Auto-synced from cosmos/docs. Transforms sdk/next/tutorials/example/*.mdx to docs/*.md. Do not edit docs/ files directly in cosmos/example — edit the source and let the sync bot update them." | ||||||||||||||||||
| fi | ||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.