-
Notifications
You must be signed in to change notification settings - Fork 0
188 lines (166 loc) · 6.47 KB
/
Copy pathsync-audit.yml
File metadata and controls
188 lines (166 loc) · 6.47 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
name: Sync & Audit Config
on:
schedule:
- cron: '0 10 * * 1-5' # Weekdays at 10am UTC (midi Paris)
workflow_dispatch: {} # Manual trigger
permissions:
contents: write
pull-requests: write
jobs:
check-release:
runs-on: ubuntu-latest
timeout-minutes: 2
outputs:
new_release: ${{ steps.check.outputs.new_release }}
latest_version: ${{ steps.check.outputs.latest_version }}
stored_version: ${{ steps.check.outputs.stored_version }}
steps:
- uses: actions/checkout@v4
- name: Check for new Claude Code release
id: check
run: |
LATEST=$(npm view @anthropic-ai/claude-code version 2>/dev/null || echo "unknown")
STORED=$(grep -oP 'Latest version: v\K[0-9.]+' docs/claude-cookbook-best-practices.md || echo "0.0.0")
echo "latest_version=$LATEST" >> "$GITHUB_OUTPUT"
echo "stored_version=$STORED" >> "$GITHUB_OUTPUT"
if [ "$LATEST" = "$STORED" ]; then
echo "new_release=false" >> "$GITHUB_OUTPUT"
echo "No new release (current: v$STORED)"
else
echo "new_release=true" >> "$GITHUB_OUTPUT"
echo "New release detected: v$STORED -> v$LATEST"
fi
- name: Summary
if: steps.check.outputs.new_release == 'false'
run: |
{
echo "## Sync & Audit — $(date +%Y-%m-%d)"
echo ""
echo "**Statut** : Pas de nouvelle release (v${{ steps.check.outputs.stored_version }}). Skipped."
} >> "$GITHUB_STEP_SUMMARY"
sync-audit:
needs: check-release
if: needs.check-release.outputs.new_release == 'true' || github.event_name == 'workflow_dispatch'
runs-on: ubuntu-latest
timeout-minutes: 15
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '22'
- name: Install Claude Code
run: npm install -g @anthropic-ai/claude-code
- name: Setup workspace
run: |
# Symlink checkout to ~/.claude so commands resolve correctly
ln -sfn "$GITHUB_WORKSPACE" "$HOME/.claude"
# Git identity for commits
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
- name: Sync best practices
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
PREV="${{ needs.check-release.outputs.stored_version }}"
NEXT="${{ needs.check-release.outputs.latest_version }}"
claude -p "/sync-cookbook — New release detected: v${PREV} -> v${NEXT}. Update the version header to v${NEXT} and focus changelog fetch on versions after v${PREV}." \
--model claude-haiku-4-5 \
--dangerously-skip-permissions \
--max-turns 30 \
--output-format text \
| tee /tmp/sync-report.txt
# Fail if Claude wasn't authenticated
if grep -qi "not logged in\|please run /login\|authentication" /tmp/sync-report.txt; then
echo "::error::Claude authentication failed. Check ANTHROPIC_API_KEY secret."
exit 1
fi
- name: Run audit and apply fixes
env:
ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
cd "$HOME/.claude"
claude -p "/audit-config — Claude Code version: v${{ needs.check-release.outputs.latest_version }}" \
--model claude-sonnet-4-6 \
--dangerously-skip-permissions \
--max-turns 30 \
--output-format text \
| tee /tmp/audit-report.txt
- name: Check for changes
id: changes
run: |
if git diff --quiet && [ -z "$(git ls-files --others --exclude-standard)" ]; then
echo "has_changes=false" >> "$GITHUB_OUTPUT"
else
echo "has_changes=true" >> "$GITHUB_OUTPUT"
{
echo "### Changed files:"
git diff --stat
git ls-files --others --exclude-standard | sed 's/^/ new: /'
} > /tmp/sync-summary.txt
fi
- name: Create PR
if: steps.changes.outputs.has_changes == 'true'
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
BRANCH="chore/sync-$(date +%Y-%m-%d)"
# Clean up old sync branches and PRs
git fetch origin
for old_branch in $(git branch -r --list 'origin/chore/sync-*' | sed 's|origin/||' | xargs); do
gh pr close "$old_branch" --delete-branch 2>/dev/null || true
git push origin --delete "$old_branch" 2>/dev/null || true
done
git checkout -b "$BRANCH"
git add -A
git commit -m "chore: sync docs and apply audit improvements"
git push -u origin "$BRANCH"
# Build PR body
{
echo "## Changes"
echo ""
cat /tmp/sync-summary.txt
echo ""
echo "---"
echo ""
echo "## Audit Report"
echo ""
if [ -f /tmp/audit-report.txt ]; then
cat /tmp/audit-report.txt | tail -80
else
echo "No audit report generated."
fi
} > /tmp/pr-body.txt
gh pr create \
--title "chore: sync & improve config $(date +%Y-%m-%d)" \
--body-file /tmp/pr-body.txt \
--assignee nicolas-codemate
- name: Summary
if: always()
run: |
{
echo "## Sync & Audit — $(date +%Y-%m-%d)"
echo ""
echo "**Release** : v${{ needs.check-release.outputs.stored_version }} -> v${{ needs.check-release.outputs.latest_version }}"
echo ""
if [ "${{ steps.changes.outputs.has_changes }}" = "true" ]; then
echo "**Statut** : PR cree avec changements"
echo ""
cat /tmp/sync-summary.txt
else
echo "**Statut** : Aucun changement detecte. Pas de PR."
fi
echo ""
echo "---"
echo ""
echo "### Sync report (derniere 20 lignes)"
echo ""
if [ -f /tmp/sync-report.txt ]; then
echo '```'
tail -20 /tmp/sync-report.txt
echo '```'
else
echo "Sync non execute ou echoue."
fi
} >> "$GITHUB_STEP_SUMMARY"