Skip to content

Commit 1799190

Browse files
committed
Added docs-update.yml
1 parent cad7218 commit 1799190

File tree

1 file changed

+183
-0
lines changed

1 file changed

+183
-0
lines changed

.github/workflows/docs-update.yml

Lines changed: 183 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,183 @@
1+
name: CodeBoarding Documentation update workflow
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
repository_url:
7+
description: 'Repository URL to test with'
8+
required: false
9+
default: 'https://github.com/CodeBoarding/mcp-use'
10+
type: string
11+
source_branch:
12+
description: 'Source branch for generation'
13+
required: false
14+
default: 'main'
15+
type: string
16+
target_branch:
17+
description: 'Target branch for pull request'
18+
required: false
19+
default: 'main'
20+
type: string
21+
output_format:
22+
description: 'Output format for documentation'
23+
required: false
24+
default: '.mdx'
25+
type: choice
26+
options:
27+
- '.mdx'
28+
- '.md'
29+
- '.rst'
30+
output_directory:
31+
description: 'Output directory for documentation files'
32+
required: false
33+
default: 'docs/api-reference/auto-generated'
34+
type: string
35+
36+
jobs:
37+
update-docs-action-usage:
38+
runs-on: ubuntu-latest
39+
timeout-minutes: 45
40+
permissions:
41+
contents: write
42+
pull-requests: write
43+
steps:
44+
- name: Checkout repository
45+
uses: actions/checkout@v4
46+
with:
47+
token: ${{ secrets.GITHUB_TOKEN }}
48+
fetch-depth: 0 # Required to access branch history
49+
50+
# Determine branches based on context
51+
- name: Set branch variables
52+
id: set-branches
53+
run: |
54+
if [ "${{ github.event_name }}" = "pull_request" ]; then
55+
echo "source_branch=${{ github.head_ref }}" >> $GITHUB_OUTPUT
56+
echo "target_branch=${{ github.base_ref }}" >> $GITHUB_OUTPUT
57+
elif [ "${{ github.event.inputs.source_branch }}" != "" ] && [ "${{ github.event.inputs.target_branch }}" != "" ]; then
58+
echo "source_branch=${{ github.event.inputs.source_branch }}" >> $GITHUB_OUTPUT
59+
echo "target_branch=${{ github.event.inputs.target_branch }}" >> $GITHUB_OUTPUT
60+
else
61+
echo "source_branch=main" >> $GITHUB_OUTPUT
62+
echo "target_branch=main" >> $GITHUB_OUTPUT
63+
fi
64+
65+
- name: Fetch CodeBoarding Documentation
66+
timeout-minutes: 30
67+
id: codeboarding
68+
uses: CodeBoarding/[email protected]
69+
with:
70+
repository_url: ${{ github.event.inputs.repository_url }}
71+
source_branch: ${{ steps.set-branches.outputs.source_branch }}
72+
target_branch: ${{ steps.set-branches.outputs.target_branch }}
73+
output_directory: ${{ github.event.inputs.output_directory || 'docs/api-reference/auto-generated' }}
74+
output_format: ${{ github.event.inputs.output_format || '.mdx' }}
75+
76+
- name: Display Action Results
77+
run: |
78+
echo "Documentation files created: ${{ steps.codeboarding.outputs.markdown_files_created }}"
79+
echo "JSON files created: ${{ steps.codeboarding.outputs.json_files_created }}"
80+
echo "Documentation directory: ${{ steps.codeboarding.outputs.output_directory }}"
81+
echo "JSON directory: ${{ steps.codeboarding.outputs.json_directory }}"
82+
echo "Has changes: ${{ steps.codeboarding.outputs.has_changes }}"
83+
84+
# Check if we have any changes to commit
85+
- name: Check for changes
86+
id: git-changes
87+
run: |
88+
if [ -n "$(git status --porcelain)" ]; then
89+
echo "has_git_changes=true" >> $GITHUB_OUTPUT
90+
else
91+
echo "has_git_changes=false" >> $GITHUB_OUTPUT
92+
fi
93+
94+
# Update documentation to include the generated files
95+
- name: Update documentation structure with generated docs
96+
if: steps.git-changes.outputs.has_git_changes == 'true' && steps.codeboarding.outputs.has_changes == 'true'
97+
run: |
98+
# Install jq for JSON manipulation
99+
sudo apt-get update && sudo apt-get install -y jq
100+
101+
# Update docs.json to include auto-generated files in API Reference
102+
if [ -d "${{ steps.codeboarding.outputs.output_directory }}" ]; then
103+
# Create a list of generated files for docs.json
104+
generated_files=""
105+
find "${{ steps.codeboarding.outputs.output_directory }}" -name "*.mdx" -type f | while read file; do
106+
# Get relative path from docs root without extension
107+
rel_path=$(echo "$file" | sed 's|^docs/||' | sed 's|\.mdx$||')
108+
if [ -z "$generated_files" ]; then
109+
generated_files="\"$rel_path\""
110+
else
111+
generated_files="$generated_files,\"$rel_path\""
112+
fi
113+
echo "$rel_path" >> generated_files_list.txt
114+
done
115+
116+
# Update docs.json to include auto-generated files
117+
if [ -s generated_files_list.txt ]; then
118+
# Create a new group for auto-generated docs
119+
temp_json=$(mktemp)
120+
jq --argjson new_group '{
121+
"group": "Auto-Generated API Documentation",
122+
"pages": []
123+
}' '
124+
.navigation[0].groups |= map(
125+
if .group == "API Reference" then
126+
.groups += [$new_group] |
127+
.groups[-1].pages = (input | split("\n") | map(select(length > 0)))
128+
else . end
129+
)' docs/docs.json generated_files_list.txt > "$temp_json"
130+
131+
# If the above doesn't work, try a simpler approach
132+
if [ $? -ne 0 ]; then
133+
# Simple insertion: add auto-generated files to existing API Reference group
134+
while read -r file_path; do
135+
if [ -n "$file_path" ]; then
136+
jq --arg path "$file_path" '
137+
(.navigation[] | select(.tab == "API Reference") | .groups[] | select(.group == "API Reference") | .pages) += [$path]
138+
' docs/docs.json > "$temp_json" && mv "$temp_json" docs/docs.json
139+
fi
140+
done < generated_files_list.txt
141+
else
142+
mv "$temp_json" docs/docs.json
143+
fi
144+
145+
rm -f generated_files_list.txt
146+
fi
147+
148+
# Update development.mdx to mention auto-generated documentation
149+
# Insert before the Project Structure section
150+
sed -i '/## Project Structure/i \
151+
## Auto-Generated API Documentation\
152+
\
153+
This project includes automatically generated API documentation files created by the CodeBoarding documentation workflow. These files provide detailed documentation for the codebase and are updated automatically when changes are made to the source code.\
154+
\
155+
The auto-generated documentation files are located in the **API Reference** section of this documentation site under "Auto-Generated API Documentation".\
156+
\
157+
' docs/development.mdx
158+
fi
159+
160+
- name: Create Pull Request
161+
if: steps.git-changes.outputs.has_git_changes == 'true' && steps.codeboarding.outputs.has_changes == 'true'
162+
uses: peter-evans/create-pull-request@v5
163+
with:
164+
token: ${{ secrets.PAT_TOKEN }}
165+
commit-message: "docs: update codeboarding documentation"
166+
title: "📚 CodeBoarding Documentation Update"
167+
body: |
168+
## 📚 Documentation Update
169+
This PR contains updated documentation files fetched from the CodeBoarding service.
170+
### 📊 Summary
171+
- **Documentation files created/updated**: ${{ steps.codeboarding.outputs.markdown_files_created }}
172+
- **JSON files created/updated**: ${{ steps.codeboarding.outputs.json_files_created }}
173+
- **Documentation directory**: `${{ steps.codeboarding.outputs.output_directory }}/`
174+
- **JSON directory**: `${{ steps.codeboarding.outputs.json_directory }}/`
175+
- **Output format**: `${{ github.event.inputs.output_format || '.mdx' }}`
176+
- **Repository analyzed**: `${{ steps.codeboarding.outputs.repo_url }}`
177+
178+
The generated .mdx files have been automatically integrated into the development documentation.
179+
180+
🤖 This PR was automatically generated by the CodeBoarding documentation update workflow.
181+
branch: docs/codeboarding-update
182+
base: main
183+
delete-branch: true

0 commit comments

Comments
 (0)