-
Notifications
You must be signed in to change notification settings - Fork 264
104 lines (84 loc) · 3.23 KB
/
Copy pathdocs-sync.yml
File metadata and controls
104 lines (84 loc) · 3.23 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
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.1
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 generate-docs
- 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