|
| 1 | +name: Sync Generated Docs |
| 2 | + |
| 3 | +on: |
| 4 | + schedule: |
| 5 | + # Run daily at 2 AM UTC |
| 6 | + - cron: '0 2 * * *' |
| 7 | + |
| 8 | + # Allows you to run this workflow manually from the Actions tab |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +permissions: |
| 12 | + contents: write |
| 13 | + pull-requests: write |
| 14 | + |
| 15 | +jobs: |
| 16 | + sync-docs: |
| 17 | + name: Generate and Sync Docs |
| 18 | + runs-on: ubuntu-latest |
| 19 | + steps: |
| 20 | + - name: Checkout |
| 21 | + |
| 22 | + with: |
| 23 | + fetch-depth: 0 |
| 24 | + |
| 25 | + - name: Setup Tools |
| 26 | + uses: tanstack/config/.github/setup@main |
| 27 | + |
| 28 | + - name: Build Packages |
| 29 | + run: pnpm run build |
| 30 | + |
| 31 | + - name: Generate Docs |
| 32 | + run: pnpm generate-docs |
| 33 | + |
| 34 | + - name: Check for changes |
| 35 | + id: check_changes |
| 36 | + run: | |
| 37 | + if [ -n "$(git status --porcelain)" ]; then |
| 38 | + echo "has_changes=true" >> $GITHUB_OUTPUT |
| 39 | + echo "Changes detected in generated docs" |
| 40 | + else |
| 41 | + echo "has_changes=false" >> $GITHUB_OUTPUT |
| 42 | + echo "No changes in generated docs" |
| 43 | + fi |
| 44 | +
|
| 45 | + - name: Configure Git |
| 46 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 47 | + run: | |
| 48 | + git config user.name "github-actions[bot]" |
| 49 | + git config user.email "github-actions[bot]@users.noreply.github.com" |
| 50 | +
|
| 51 | + - name: Commit and Push Changes |
| 52 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 53 | + env: |
| 54 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 55 | + run: | |
| 56 | + BRANCH_NAME="docs/auto-generate" |
| 57 | +
|
| 58 | + # Check if branch exists remotely |
| 59 | + if git ls-remote --exit-code --heads origin $BRANCH_NAME; then |
| 60 | + echo "Branch exists, checking out and updating" |
| 61 | + git fetch origin $BRANCH_NAME |
| 62 | + git checkout $BRANCH_NAME |
| 63 | + git pull origin $BRANCH_NAME |
| 64 | + else |
| 65 | + echo "Creating new branch" |
| 66 | + git checkout -b $BRANCH_NAME |
| 67 | + fi |
| 68 | +
|
| 69 | + # Stage and commit changes |
| 70 | + git add docs/ |
| 71 | + git commit -m "docs: regenerate API documentation |
| 72 | +
|
| 73 | + Auto-generated by daily docs sync workflow" |
| 74 | +
|
| 75 | + # Push changes |
| 76 | + git push origin $BRANCH_NAME |
| 77 | +
|
| 78 | + - name: Create or Update PR |
| 79 | + if: steps.check_changes.outputs.has_changes == 'true' |
| 80 | + env: |
| 81 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 82 | + run: | |
| 83 | + BRANCH_NAME="docs/auto-generate" |
| 84 | +
|
| 85 | + # Check if PR already exists |
| 86 | + existing_pr=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number') |
| 87 | +
|
| 88 | + if [ -n "$existing_pr" ]; then |
| 89 | + echo "PR #$existing_pr already exists, it has been updated with the latest changes" |
| 90 | + gh pr comment $existing_pr --body "Updated with latest generated docs from scheduled workflow run." |
| 91 | + else |
| 92 | + echo "Creating new PR" |
| 93 | + gh pr create \ |
| 94 | + --title "docs: sync generated API documentation" \ |
| 95 | + --body "This PR was automatically created by the daily docs sync workflow. |
| 96 | +
|
| 97 | + The generated API documentation has been updated to reflect the latest changes in the codebase. |
| 98 | +
|
| 99 | + **Generated by**: [Docs Sync Workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) |
| 100 | +
|
| 101 | + Please review and merge if the changes look correct." \ |
| 102 | + --head $BRANCH_NAME \ |
| 103 | + --base main |
| 104 | + fi |
0 commit comments