-
Notifications
You must be signed in to change notification settings - Fork 0
137 lines (119 loc) · 5.22 KB
/
api-differ.yml
File metadata and controls
137 lines (119 loc) · 5.22 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
name: Claude API Documentation Differ
on:
schedule:
# Run every 48 hours (at midnight UTC on odd days)
# API docs are ~10x larger (539 pages vs 54), so less frequent updates
- cron: '0 0 1-31/2 * *'
workflow_dispatch:
# Allow manual triggering
permissions:
contents: write
concurrency:
group: api-differ
cancel-in-progress: false
jobs:
fetch-and-diff:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
# Need full history for diffing
fetch-depth: 0
- name: Set up Python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip'
- name: Install dependencies
run: |
pip install -r requirements.txt
playwright install chromium
- name: Configure Git
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Fetch Claude API documentation
run: python3 fetch.py --source api --force
- name: Check for content changes
id: check_changes
run: |
# Only detect actual .md file changes, not metadata.json timestamp updates
MD_CHANGES=$(git diff --name-only -- 'docs/api/en/*.md' 'docs/api/en/**/*.md' | wc -l)
STAGED_MD=$(git diff --staged --name-only -- 'docs/api/en/*.md' 'docs/api/en/**/*.md' | wc -l)
TOTAL=$((MD_CHANGES + STAGED_MD))
if [ "$TOTAL" -gt 0 ]; then
echo "changes=true" >> $GITHUB_OUTPUT
echo "count=$TOTAL" >> $GITHUB_OUTPUT
echo "Found $TOTAL changed .md files"
else
echo "changes=false" >> $GITHUB_OUTPUT
echo "count=0" >> $GITHUB_OUTPUT
echo "No .md file changes detected (metadata-only update)"
fi
- name: Count change types
if: steps.check_changes.outputs.changes == 'true'
id: count_changes
run: |
NEW=$(git diff --name-only --diff-filter=A -- 'docs/api/en/*.md' 'docs/api/en/**/*.md' | wc -l)
MODIFIED=$(git diff --name-only --diff-filter=M -- 'docs/api/en/*.md' 'docs/api/en/**/*.md' | wc -l)
DELETED=$(git diff --name-only --diff-filter=D -- 'docs/api/en/*.md' 'docs/api/en/**/*.md' | wc -l)
echo "new=$NEW" >> $GITHUB_OUTPUT
echo "modified=$MODIFIED" >> $GITHUB_OUTPUT
echo "deleted=$DELETED" >> $GITHUB_OUTPUT
- name: Commit documentation changes
if: steps.check_changes.outputs.changes == 'true'
run: |
git add docs/api/
NEW=${{ steps.count_changes.outputs.new || 0 }}
MOD=${{ steps.count_changes.outputs.modified || 0 }}
DEL=${{ steps.count_changes.outputs.deleted || 0 }}
git commit -m "Claude API docs update: $(date -u +%Y-%m-%d\ %H:%M\ UTC) (${MOD} modified, ${NEW} new, ${DEL} removed)"
- name: Install Claude Code CLI
if: steps.check_changes.outputs.changes == 'true'
run: npm install -g @anthropic-ai/claude-code
- name: Generate changelog
if: steps.check_changes.outputs.changes == 'true'
run: python3 diff.py --source api --changelog --force --since-last-changelog
env:
CLAUDE_CODE_OAUTH_TOKEN: ${{ secrets.CLAUDE_CODE_OAUTH_TOKEN }}
- name: Commit changelog and push
if: steps.check_changes.outputs.changes == 'true'
run: |
git add output/api/ || true
git commit -m "Add changelog for $(date -u +%Y-%m-%d)" || true
for i in 1 2 3; do
git pull --rebase origin main && git push && break
echo "Push attempt $i failed, retrying in 5s..."
sleep 5
done
- name: Push metadata-only update
if: steps.check_changes.outputs.changes == 'false'
run: |
# Commit metadata.json separately so it doesn't pollute the changelog history
if ! git diff --quiet docs/api/metadata.json; then
git add docs/api/metadata.json
git commit -m "Update API metadata: $(date -u +%Y-%m-%d\ %H:%M\ UTC) (no content changes)"
for i in 1 2 3; do
git pull --rebase origin main && git push && break
echo "Push attempt $i failed, retrying in 5s..."
sleep 5
done
fi
- name: Summary
run: |
if [ "${{ steps.check_changes.outputs.changes }}" == "true" ]; then
echo "## Claude API Documentation Changes Detected" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "**${{ steps.check_changes.outputs.count }}** pages changed." >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
CHANGELOG=$(ls output/api/*_changelog.md 2>/dev/null | head -1)
if [ -n "$CHANGELOG" ]; then
echo "### Latest Changelog" >> $GITHUB_STEP_SUMMARY
head -100 "$CHANGELOG" >> $GITHUB_STEP_SUMMARY
fi
else
echo "## No Content Changes Detected" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "Claude API documentation content is up to date. Metadata timestamp updated." >> $GITHUB_STEP_SUMMARY
fi