-
Notifications
You must be signed in to change notification settings - Fork 1
148 lines (121 loc) · 4.45 KB
/
Copy pathupdate-docs.yaml
File metadata and controls
148 lines (121 loc) · 4.45 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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
name: Update API Documentation
on:
# Trigger on pushes to main branch (when API changes)
push:
branches: [main]
paths:
- "app/**"
workflow_dispatch: # Allow manual triggering of the workflow
permissions:
contents: write
jobs:
update-docs:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.12"
- name: Install Python dependencies
run: |
python -m pip install --upgrade pip
pip install .
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
- name: Start API server
run: |
# Start the API in the background
uvicorn app.main:app --host 0.0.0.0 --port 5000 &
API_PID=$!
echo "API_PID=$API_PID" >> $GITHUB_ENV
# Wait for API to be ready
echo "Waiting for API to be ready..."
for i in {1..30}; do
if curl -f http://localhost:5000/docs > /dev/null 2>&1; then
echo "API is ready!"
break
fi
echo "Attempt $i: API not ready yet, waiting..."
sleep 2
done
# Verify API is responding
if ! curl -f http://localhost:5000/docs > /dev/null 2>&1; then
echo "Error: API failed to start"
exit 1
fi
- name: Download OpenAPI spec
run: |
# Create docs directory if it doesn't exist
mkdir -p docs
# Download the OpenAPI spec
curl -o docs/openapi.json http://localhost:5000/openapi.json
# Verify the file was downloaded and is valid JSON
if [ ! -f "docs/openapi.json" ]; then
echo "Error: Failed to download openapi.json"
exit 1
fi
# Basic JSON validation
if ! python -m json.tool docs/openapi.json > /dev/null; then
echo "Error: Downloaded file is not valid JSON"
exit 1
fi
echo "Successfully downloaded OpenAPI spec"
- name: Generate HTML documentation
run: |
# Install and use redocly CLI
npx @redocly/cli build-docs docs/openapi.json --output docs/index.html
# Verify HTML was generated
if [ ! -f "docs/index.html" ]; then
echo "Error: Failed to generate HTML documentation"
exit 1
fi
echo "Successfully generated HTML documentation"
- name: Stop API server
if: always()
run: |
if [ -n "$API_PID" ]; then
kill $API_PID || true
fi
- name: Check for changes
id: check_changes
run: |
# Check if there are any changes to commit
if git diff --quiet docs/; then
echo "No changes detected in documentation"
echo "changes=false" >> $GITHUB_OUTPUT
else
echo "Changes detected in documentation"
echo "changes=true" >> $GITHUB_OUTPUT
fi
- name: Commit and push changes
if: steps.check_changes.outputs.changes == 'true'
run: |
# Configure git
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# Add and commit changes
git add docs/openapi.json docs/index.html
git commit -m "docs: update API documentation [automated]
- Updated OpenAPI specification
- Regenerated HTML documentation
Generated by GitHub Actions on $(date -u '+%Y-%m-%d %H:%M:%S UTC')"
# Push changes
git push
- name: Create summary
run: |
echo "## API Documentation Update Summary" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
if [ "${{ steps.check_changes.outputs.changes }}" == "true" ]; then
echo "✅ Documentation updated successfully" >> $GITHUB_STEP_SUMMARY
echo "- OpenAPI spec downloaded from API" >> $GITHUB_STEP_SUMMARY
echo "- HTML documentation regenerated" >> $GITHUB_STEP_SUMMARY
echo "- Changes committed and pushed to main branch" >> $GITHUB_STEP_SUMMARY
else
echo "ℹ️ No changes detected in documentation" >> $GITHUB_STEP_SUMMARY
fi