Claude Code في CI/CD: أتمتة مع GitHub Actions و GitLab
جاري تحميل مشغل تحويل النص إلى كلام الصوتي...
لماذا Claude Code في CI/CD؟
أتمتة المهام المتكررة:
- مراجعة Pull Requests
- إصلاح Issues تلقائياً
- ترجمة النصوص
- تحديث التوثيق
- إصلاح أخطاء lint
المفهوم: @claude mention في PR أو Issue يُشغّل Claude Code.
GitHub Actions
الإعداد الأساسي
1. إنشاء Workflow
# .github/workflows/claude.yml
name: Claude Code
on:
issue_comment:
types: [created]
pull_request:
types: [opened, synchronize]
jobs:
claude:
if: contains(github.event.comment.body, '@claude')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropic/claude-code-action@v1
with:
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}2. إضافة API Key
- Settings → Secrets → Actions
- New repository secret
- Name:
ANTHROPIC_API_KEY - Value: مفتاحك من Anthropic Console
حالات الاستخدام
1. مراجعة PRs تلقائياً
name: PR Review
on:
pull_request:
types: [opened, synchronize]
jobs:
review:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropic/claude-code-action@v1
with:
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
task: |
Review this PR for:
- Security issues
- Performance problems
- Code style violations
Comment your findings on the PR.2. إصلاح Issues بـ @claude
name: Fix Issue
on:
issue_comment:
types: [created]
jobs:
fix:
if: |
github.event.issue.pull_request == null &&
contains(github.event.comment.body, '@claude fix')
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropic/claude-code-action@v1
with:
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
task: |
Fix the issue described in #${{ github.event.issue.number }}
Create a PR with the fix.3. ترجمة تلقائية
name: Translate
on:
push:
paths:
- 'locales/en/**'
jobs:
translate:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: anthropic/claude-code-action@v1
with:
anthropic-api-key: ${{ secrets.ANTHROPIC_API_KEY }}
task: |
Translate new strings in locales/en/ to Arabic and French.
Create a PR for @lang-team to review.أوامر @claude في GitHub
| الأمر | الفعل |
|---|---|
@claude review | مراجعة الكود |
@claude fix | إصلاح المشكلة |
@claude explain | شرح الكود |
@claude test | كتابة اختبارات |
@claude docs | تحديث التوثيق |
GitLab CI/CD
الإعداد الأساسي
# .gitlab-ci.yml
stages:
- claude
claude-review:
stage: claude
image: node:20
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
script:
- npm install -g @anthropic-ai/claude-code
- claude -p "Review this MR and comment findings" --no-input
variables:
ANTHROPIC_API_KEY: $ANTHROPIC_API_KEYEvent-Driven Automation
claude-on-mention:
stage: claude
rules:
- if: $CI_MERGE_REQUEST_DESCRIPTION =~ /@claude/
script:
- npm install -g @anthropic-ai/claude-code
- |
claude -p "
Task from MR description:
$CI_MERGE_REQUEST_DESCRIPTION
Implement the requested changes.
" --no-inputإصلاح Issues
claude-fix-issue:
stage: claude
rules:
- if: $CI_PIPELINE_SOURCE == "trigger"
when: always
script:
- npm install -g @anthropic-ai/claude-code
- |
claude -p "
Fix GitLab issue #$ISSUE_ID
Create a branch and MR with the fix.
" --no-inputSlack Integration
اذكر Claude في Slack
@claude fix the bug in auth module and create a PR
ماذا يحدث:
- Slack يرسل الطلب لـ Claude Code on Web
- Claude يستنسخ الريبو
- يصلح المشكلة
- ينشئ PR
- يرد في Slack بالرابط
الإعداد
- ثبّت Claude Slack App
- اربط GitHub repos
- ادعُ Claude للـ channel
أمثلة متقدمة
1. مراجعة أمنية تلقائية
security-review:
on:
pull_request:
paths:
- 'src/auth/**'
- 'src/api/**'
jobs:
review:
steps:
- uses: anthropic/claude-code-action@v1
with:
task: |
SECURITY REVIEW:
- Check for SQL injection
- Check for XSS vulnerabilities
- Verify authentication logic
- Check secrets handling
Flag any issues as 🚨 SECURITY2. إصلاح Lint تلقائي
auto-fix-lint:
on:
pull_request:
types: [opened]
jobs:
fix:
steps:
- run: npm run lint 2>&1 | tee lint-output.txt || true
- uses: anthropic/claude-code-action@v1
with:
task: |
Fix all lint errors in lint-output.txt
Commit with message "fix: auto-fix lint errors"3. تحديث Changelog
update-changelog:
on:
release:
types: [created]
jobs:
changelog:
steps:
- uses: anthropic/claude-code-action@v1
with:
task: |
Update CHANGELOG.md with:
- Release version: ${{ github.event.release.tag_name }}
- Changes from commits since last release
- Categorize: Features, Fixes, Breaking Changesأفضل الممارسات
1. حدد الصلاحيات
permissions:
contents: write # للتعديل
pull-requests: write # للتعليق
issues: read # لقراءة Issues2. استخدم Rate Limiting
claude-review:
concurrency:
group: claude-${{ github.ref }}
cancel-in-progress: true3. أضف Timeout
steps:
- uses: anthropic/claude-code-action@v1
timeout-minutes: 104. راقب التكاليف
- uses: anthropic/claude-code-action@v1
with:
max-tokens: 50000 # حد أقصى
model: claude-sonnet-4 # أرخص من Opusالأمان
✅ افعل:
- استخدم Secrets للـ API keys
- حدد repos المسموحة
- راجع PRs المُنشأة تلقائياً
- أضف حماية للـ main branch
❌ لا تفعل:
- لا تضع API key في الكود
- لا تعطِ صلاحيات زائدة
- لا تثق بالتغييرات بدون مراجعة
- لا تستخدم على repos حساسة بدون حذر
الخلاصة
Claude Code في CI/CD يوفر:
- مراجعة PRs تلقائية
- إصلاح Issues بأمر واحد
- أتمتة المهام المتكررة
- توفير وقت الفريق
ابدأ صغيراً: مراجعة PRs، ثم توسع تدريجياً.
انتهت السلسلة! 🎉
راجع كل المقالات:
- قصة Anthropic
- ما هو Claude Code؟
- المفاهيم الأساسية
- الفوائد والاستخدامات
- التسعير
- المقارنة مع المنافسين
- Claude Code على الويب
- تكامل IDEs
- CI/CD (أنت هنا)
تواصل معنا للاستشارة حول دمج Claude Code في سير عملك.
هل تريد قراءة المزيد من المقالات؟ تحقق من أحدث مقال لدينا على Unlocking the Future of AI with GPT-4o: A Comprehensive Introduction to Multimodal Capabilities.
ناقش مشروعك معنا
نحن هنا للمساعدة في احتياجات تطوير الويب الخاصة بك. حدد موعدًا لمناقشة مشروعك وكيف يمكننا مساعدتك.
دعنا نجد أفضل الحلول لاحتياجاتك.