GitHub Actions
คู่มือนี้อธิบายวิธีผสาน LoadFocus JMeter API Client กับ GitHub Actions สำหรับการทดสอบประสิทธิภาพอัตโนมัติ
ขั้นตอนการตั้งค่า
1. จัดเก็บ Credentials เป็น GitHub Secrets
ก่อนอื่น จัดเก็บ LoadFocus API credentials เป็น GitHub repository secrets:
- ไปที่ GitHub repository ของคุณ
- นำทางไปที่ Settings > Secrets and variables > Actions
- เพิ่ม repository secrets ต่อไปนี้:
LOADFOCUS_API_KEY: API key ของ LoadFocusLOADFOCUS_TEAM_ID: Team ID ของ LoadFocus
2. สร้าง GitHub Actions Workflow
สร้างไฟล์ใหม่ใน repository ที่ .github/workflows/performance-test.yml:
name: Performance Testson:push:branches: [ main, develop ]pull_request:branches: [ main ]schedule:- cron: '0 0 * * 1' # Run at midnight every Mondayjobs:performance-test:runs-on: ubuntu-lateststeps:- uses: actions/checkout@v3- name: Setup Node.jsuses: actions/setup-node@v3with:node-version: '16'- name: Install LoadFocus JMeter API Clientrun: npm install -g @loadfocus/loadfocus-api-client- name: Configure LoadFocus API Clientrun: |loadfocus-api config set apikey ${{ secrets.LOADFOCUS_API_KEY }}loadfocus-api config set teamid ${{ secrets.LOADFOCUS_TEAM_ID }}- name: Run Performance Testsrun: |loadfocus-api jmeter run-test \--name "GitHub_${{ github.repository_owner }}_${{ github.repository }}_${{ github.ref_name }}" \--thresholds "avgresponse<=200,errors==0,p95<=250" \--format json > performance_results.json- name: Upload Performance Test Resultsuses: actions/upload-artifact@v3with:name: performance-test-resultspath: performance_results.json
เคล็ดลับสำหรับการผสาน GitHub Actions
- Caching: แคช npm dependencies เพื่อเร่งการรัน workflow
- Concurrency Control: จำกัดทดสอบประสิทธิภาพพร้อมกัน
- Environment-specific Tests: ใช้ GitHub environments สำหรับการกำหนดค่าทดสอบที่แตกต่างกัน
- การทดสอบแบบมีเงื่อนไข: รันทดสอบประสิทธิภาพเฉพาะเมื่อไฟล์เฉพาะเปลี่ยนแปลง
สำหรับข้อมูลเพิ่มเติม ดู เอกสาร GitHub Actions และ เอกสาร LoadFocus API Client