diff --git a/.github/workflows/docs-sync.yml b/.github/workflows/docs-sync.yml new file mode 100644 index 000000000..c041168d4 --- /dev/null +++ b/.github/workflows/docs-sync.yml @@ -0,0 +1,104 @@ +name: Sync Generated Docs + +on: + schedule: + # Run daily at 2 AM UTC + - cron: "0 2 * * *" + + # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + +permissions: + contents: write + pull-requests: write + +jobs: + sync-docs: + name: Generate and Sync Docs + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v5.0.0 + with: + fetch-depth: 0 + + - name: Setup Tools + uses: tanstack/config/.github/setup@main + + - name: Build Packages + run: pnpm run build + + - name: Generate Docs + run: pnpm docs:generate + + - name: Check for changes + id: check_changes + run: | + if [ -n "$(git status --porcelain)" ]; then + echo "has_changes=true" >> $GITHUB_OUTPUT + echo "Changes detected in generated docs" + else + echo "has_changes=false" >> $GITHUB_OUTPUT + echo "No changes in generated docs" + fi + + - name: Configure Git + if: steps.check_changes.outputs.has_changes == 'true' + run: | + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + + - name: Commit and Push Changes + if: steps.check_changes.outputs.has_changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BRANCH_NAME="docs/auto-generate" + + # Check if branch exists remotely + if git ls-remote --exit-code --heads origin $BRANCH_NAME; then + echo "Branch exists, checking out and updating" + git fetch origin $BRANCH_NAME + git checkout $BRANCH_NAME + git pull origin $BRANCH_NAME + else + echo "Creating new branch" + git checkout -b $BRANCH_NAME + fi + + # Stage and commit changes + git add docs/ + git commit -m "docs: regenerate API documentation + + Auto-generated by daily docs sync workflow" + + # Push changes + git push origin $BRANCH_NAME + + - name: Create or Update PR + if: steps.check_changes.outputs.has_changes == 'true' + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + BRANCH_NAME="docs/auto-generate" + + # Check if PR already exists + existing_pr=$(gh pr list --head $BRANCH_NAME --json number --jq '.[0].number') + + if [ -n "$existing_pr" ]; then + echo "PR #$existing_pr already exists, it has been updated with the latest changes" + gh pr comment $existing_pr --body "Updated with latest generated docs from scheduled workflow run." + else + echo "Creating new PR" + gh pr create \ + --title "docs: sync generated API documentation" \ + --body "This PR was automatically created by the daily docs sync workflow. + + The generated API documentation has been updated to reflect the latest changes in the codebase. + + **Generated by**: [Docs Sync Workflow](https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}) + + Please review and merge if the changes look correct." \ + --head $BRANCH_NAME \ + --base main + fi diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 2780293be..5ff230848 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -90,31 +90,3 @@ jobs: run: | cd examples/react/projects pnpm build - check-docs: - name: Check Generated Docs - runs-on: ubuntu-latest - steps: - - name: Checkout - uses: actions/checkout@v5.0.0 - - name: Setup Tools - uses: tanstack/config/.github/setup@main - - name: Build Packages - run: pnpm run build - - name: Generate Docs - run: pnpm docs:generate - - name: Check for changes - run: | - if [ -n "$(git status --porcelain)" ]; then - echo "Error: Generated docs are out of sync!" - echo "" - echo "Please run the following commands locally and commit the changes:" - echo " 1. pnpm install" - echo " 2. pnpm build" - echo " 3. pnpm docs:generate" - echo " 4. git add docs/" - echo " 5. git commit -m 'docs: regenerate API documentation'" - echo "" - echo "Files that need to be updated:" - git status --short - exit 1 - fi diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 155b5ae7d..6ce729857 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -30,6 +30,19 @@ jobs: uses: tanstack/config/.github/setup@main - name: Run Tests run: pnpm run lint && pnpm run build && pnpm run test + - name: Generate Docs + run: pnpm docs:generate + - name: Commit Generated Docs + run: | + if [ -n "$(git status --porcelain)" ]; then + git config user.name "github-actions[bot]" + git config user.email "github-actions[bot]@users.noreply.github.com" + git add docs/ + git commit -m "docs: regenerate API documentation" + git push + else + echo "No changes in generated docs" + fi - name: Run Changesets (version or publish) id: changesets uses: changesets/action@v1.5.3