GitHub Actions

คู่มือนี้อธิบายวิธีผสาน LoadFocus JMeter API Client กับ GitHub Actions สำหรับการทดสอบประสิทธิภาพอัตโนมัติ

ขั้นตอนการตั้งค่า

1. จัดเก็บ Credentials เป็น GitHub Secrets

ก่อนอื่น จัดเก็บ LoadFocus API credentials เป็น GitHub repository secrets:

  1. ไปที่ GitHub repository ของคุณ
  2. นำทางไปที่ Settings > Secrets and variables > Actions
  3. เพิ่ม repository secrets ต่อไปนี้:
    • LOADFOCUS_API_KEY: API key ของ LoadFocus
    • LOADFOCUS_TEAM_ID: Team ID ของ LoadFocus

2. สร้าง GitHub Actions Workflow

สร้างไฟล์ใหม่ใน repository ที่ .github/workflows/performance-test.yml:

name: Performance Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
schedule:
- cron: '0 0 * * 1' # Run at midnight every Monday
jobs:
performance-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '16'
- name: Install LoadFocus JMeter API Client
run: npm install -g @loadfocus/loadfocus-api-client
- name: Configure LoadFocus API Client
run: |
loadfocus-api config set apikey ${{ secrets.LOADFOCUS_API_KEY }}
loadfocus-api config set teamid ${{ secrets.LOADFOCUS_TEAM_ID }}
- name: Run Performance Tests
run: |
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 Results
uses: actions/upload-artifact@v3
with:
name: performance-test-results
path: performance_results.json

เคล็ดลับสำหรับการผสาน GitHub Actions

  1. Caching: แคช npm dependencies เพื่อเร่งการรัน workflow
  2. Concurrency Control: จำกัดทดสอบประสิทธิภาพพร้อมกัน
  3. Environment-specific Tests: ใช้ GitHub environments สำหรับการกำหนดค่าทดสอบที่แตกต่างกัน
  4. การทดสอบแบบมีเงื่อนไข: รันทดสอบประสิทธิภาพเฉพาะเมื่อไฟล์เฉพาะเปลี่ยนแปลง

สำหรับข้อมูลเพิ่มเติม ดู เอกสาร GitHub Actions และ เอกสาร LoadFocus API Client