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:

  1. Prejdite na vas repozitar GitHub
  2. Prejdite na Settings > Secrets and variables > Actions
  3. Pridajte nasledujuce tajomstva repozitara:
    • LOADFOCUS_API_KEY: Vas LoadFocus API kluc
    • LOADFOCUS_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 Tests
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
# Optional: Run on a schedule
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

3. Pridanie testovania vykonnosti do vasho nasadzovacieho workflow

Aby nasadenie zaviselo od vysledkov testov vykonnosti:

name: Build, Test, and Deploy
on:
push:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
# Your build steps...
performance-test:
needs: build
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 }}_${{ 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
deploy:
needs: performance-test
runs-on: ubuntu-latest
steps:
# Your deployment steps...

Tipy pre integraciu GitHub Actions

  1. Cachovanie: Cachujte npm zavislosti na zrychlenie behov workflow.

  2. Ovladanie sucasnosti: Obmedzte sucasne testy vykonnosti:

    concurrency:
    group: performance-test-${{ github.ref }}
    cancel-in-progress: false
  3. Testy specificke pre prostredie: Pouzite prostredia GitHub pre rozne konfiguracie testov.

  4. 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.