GitHub Actions
Tento navod vysvetluje, ako integrovat LoadFocus JMeter API klienta s GitHub Actions na automatizovane testovanie vykonnosti.
Kroky nastavenia
1. Ulozenie povereni ako GitHub Secrets
Najprv ulozte vase poverenia LoadFocus API ako tajomstva repozitara GitHub:
- Prejdite na vas repozitar GitHub
- Prejdite na Settings > Secrets and variables > Actions
- Pridajte nasledujuce tajomstva repozitara:
LOADFOCUS_API_KEY: Vas LoadFocus API klucLOADFOCUS_TEAM_ID: Vase LoadFocus team ID
2. Vytvorenie GitHub Actions workflow
Vytvorte novy subor vo vasom repozitari na .github/workflows/performance-test.yml:
name: Performance Testson:push:branches: [ main, develop ]pull_request:branches: [ main ]# Optional: Run on a scheduleschedule:- 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
3. Pridanie testovania vykonnosti do vasho nasadzovacieho workflow
Aby nasadenie zaviselo od vysledkov testov vykonnosti:
name: Build, Test, and Deployon:push:branches: [ main ]jobs:build:runs-on: ubuntu-lateststeps:# Your build steps...performance-test:needs: buildruns-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 }}_${{ 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.jsondeploy:needs: performance-testruns-on: ubuntu-lateststeps:# Your deployment steps...
Tipy pre integraciu GitHub Actions
Cachovanie: Cachujte npm zavislosti na zrychlenie behov workflow.
Ovladanie sucasnosti: Obmedzte sucasne testy vykonnosti:
concurrency:group: performance-test-${{ github.ref }}cancel-in-progress: falseTesty specificke pre prostredie: Pouzite prostredia GitHub pre rozne konfiguracie testov.
Podmienene testovanie: Spustajte testy vykonnosti iba ked sa zmenia konkretne subory:
jobs:performance-test:if: |contains(github.event.pull_request.labels.*.name, 'performance-test') ||github.event_name == 'schedule' ||contains(github.event.head_commit.message, '[perf-test]')
Pre viac informacii pozrite dokumentaciu GitHub Actions a dokumentaciu LoadFocus API klienta.