Docs fixes (#15) #12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Docs Sync → cosmos/docs | |
| # Runs when docs/ files change on main. | |
| # Transforms .md → .mdx and opens a PR on the docs site 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: | |
| - "docs/**" | |
| jobs: | |
| sync: | |
| name: Sync docs to cosmos/docs | |
| 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 example repo | |
| uses: actions/checkout@v4 | |
| - name: Set up Python | |
| uses: actions/setup-python@v5 | |
| with: | |
| python-version: "3.12" | |
| - name: Checkout cosmos/docs | |
| uses: actions/checkout@v4 | |
| with: | |
| repository: cosmos/docs | |
| # Fine-grained PAT with contents:write and pull-requests:write on cosmos/docs | |
| token: ${{ secrets.DOCS_REPO_TOKEN }} | |
| path: cosmos-docs | |
| persist-credentials: false | |
| - name: Transform docs → Mintlify format | |
| run: | | |
| python3 scripts/docs-sync/transform.py \ | |
| --direction to-mintlify \ | |
| --input docs/ \ | |
| --output-dir cosmos-docs/sdk/next/tutorials/example/ | |
| - name: Check for changes | |
| id: diff | |
| run: | | |
| cd cosmos-docs | |
| [ -n "$(git status --porcelain sdk/next/tutorials/example/)" ] \ | |
| && echo "changed=true" >> "$GITHUB_OUTPUT" \ | |
| || echo "changed=false" >> "$GITHUB_OUTPUT" | |
| - name: Open or update PR on cosmos/docs | |
| if: steps.diff.outputs.changed == 'true' | |
| env: | |
| GH_TOKEN: ${{ secrets.DOCS_REPO_TOKEN }} | |
| run: | | |
| cd cosmos-docs | |
| git config user.name "docs-sync[bot]" | |
| git config user.email "docs-sync[bot]@users.noreply.github.com" | |
| git remote set-url origin "https://x-access-token:${{ secrets.DOCS_REPO_TOKEN }}@github.com/cosmos/docs.git" | |
| # Check for an existing open sync PR | |
| EXISTING=$(gh pr list \ | |
| --repo cosmos/docs \ | |
| --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') | |
| # Update the existing branch | |
| git fetch origin "$BRANCH" | |
| git checkout "$BRANCH" | |
| git add sdk/next/tutorials/example/ | |
| git commit -m "docs: sync example tutorials from cosmos/example [docs-sync]" | |
| git push origin "$BRANCH" | |
| gh pr comment "$PR_NUMBER" \ | |
| --repo cosmos/docs \ | |
| --body "Sync updated: cosmos/example was updated before this PR merged. Branch has been refreshed — please re-review." | |
| echo "Updated existing PR #$PR_NUMBER" | |
| else | |
| # No existing PR — create a new branch and open one | |
| BRANCH="docs-sync/example-$(date +%Y%m%d-%H%M%S)" | |
| git checkout -b "$BRANCH" | |
| git add sdk/next/tutorials/example/ | |
| git commit -m "docs: sync example tutorials from cosmos/example [docs-sync]" | |
| git push origin "$BRANCH" | |
| gh pr create \ | |
| --repo cosmos/docs \ | |
| --head "$BRANCH" \ | |
| --base main \ | |
| --title "docs: sync example tutorials from cosmos/example" \ | |
| --label "docs-sync" \ | |
| --body "Auto-synced from cosmos/example. Transforms docs/*.md to sdk/next/tutorials/example/*.mdx. Do not edit these files directly — edit the source in cosmos/example and let the sync bot update them." | |
| fi |