0Pricing
Load Testing & Performance Benchmarking (JMeter & k6) · Aula

k6 nas Ações do GitHub

Configure os testes do k6 para serem executados automaticamente como parte dos seus fluxos de trabalho do GitHub Actions.

k6 nas Ações do GitHub é uma aula grátis de Load Testing & Performance Benchmarking (JMeter & k6) no CoddyKit. Esta é a aula 2 de 4. Você pode ler a aula completa abaixo gratuitamente — depois pratica ao vivo no navegador com um editor de código integrado e um tutor de IA 24/7. Faz parte do caminho de aprendizado de Load Testing & Performance Benchmarking (JMeter & k6), e seu progresso é sincronizado entre a web e o app CoddyKit. O curso de Load Testing & Performance Benchmarking (JMeter & k6) inclui 4 aulas no total.

Partes desta aula ainda não foram traduzidas e aparecem em inglês.

Automating Performance Testing

Welcome to integrating performance testing with CI/CD! Continuous Integration (CI) and Continuous Delivery (CD) pipelines automate software development steps.

Bringing performance tests into this flow ensures that performance issues are caught early, before they reach users.

Why k6 in GitHub Actions?

GitHub Actions provides a powerful way to automate tasks directly within your GitHub repository. Here's why it's great for k6 performance tests:

  • Automation: Tests run automatically on code changes.
  • Consistency: The test environment is standardized.
  • Early Feedback: Catch performance regressions quickly.
  • Version Control: Your test scripts and workflows live with your code.

GitHub Actions Workflow Basics

A GitHub Actions workflow is defined by a YAML file in the .github/workflows/ directory of your repository.

It specifies when to run, what to run (jobs and steps), and on which operating system.

Our Simple k6 Test Script

Before creating the workflow, let's have a basic k6 script. This script will perform a simple HTTP GET request to a test endpoint. Save this as test.js in your repository.

import http from 'k6/http';
import { check, sleep } from 'k6';

export default function () {
  const res = http.get('https://test.k6.io');
  check(res, {
    'status is 200': (r) => r.status === 200,
  });
  sleep(1);
}

Creating the Workflow File

First, create a new directory .github/workflows/ in the root of your repository. Inside this, create a file named, for example, k6-perf-test.yml.

This file will define our automation steps.

Workflow Structure: Name & Trigger

Every workflow needs a name and a trigger (on). We'll trigger our test on every push to the main branch.

Here's the start of our k6-perf-test.yml file:

name: k6 Performance Test

on:
  push:
    branches:
      - main

jobs:

Defining the Test Job

Next, we define a job. A job is a set of steps that execute on the same runner. We'll call ours run-k6-test and use an ubuntu-latest runner.

name: k6 Performance Test

on:
  push:
    branches:
      - main

jobs:
  run-k6-test:
    runs-on: ubuntu-latest
    steps:

Checkout Code & Install k6

Inside our job's steps, we first need to check out our repository code, then install k6. We'll use a pre-built GitHub Action to easily install k6.

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Install k6
        uses: k6io/action@v2.0.0

Executing the k6 Test

Finally, we add a step to run our test.js k6 script. We can specify options like the number of virtual users (-u) and duration (-d) directly.

      - name: Install k6
        uses: k6io/action@v2.0.0

      - name: Run k6 test
        run: k6 run -u 10 -d 30s test.js

Viewing Test Results

After committing your .yml file and test.js script to your GitHub repository, navigate to the Actions tab.

You'll see your workflow running. Click on the workflow run, then the run-k6-test job to view the detailed logs, including k6's output and results.

Workflow Essentials

Which of the following is the correct path and file extension for a GitHub Actions workflow file?

Recap & Next Steps

You've learned how to integrate k6 performance tests into GitHub Actions! This enables automated, consistent, and early performance feedback.

  • We explored the workflow structure.
  • Set up a k6 script and the YAML workflow file.
  • Configured steps for checking out code, installing k6, and running the test.
  • Understood how to view results in GitHub Actions.

Next, explore more advanced k6 features in your workflows, like reporting and thresholds!

Perguntas Frequentes

A aula “k6 nas Ações do GitHub” é grátis?

Sim — o texto completo de “k6 nas Ações do GitHub” é grátis para ler aqui na web. Para praticá-la interativamente (um editor de código integrado e um tutor de IA 24/7) e desbloquear o restante do curso de Load Testing & Performance Benchmarking (JMeter & k6), atualize para CoddyKit PRO. O curso de Load Testing & Performance Benchmarking (JMeter & k6) inclui 4 aulas no total.

O que vou aprender em “k6 nas Ações do GitHub”?

Configure os testes do k6 para serem executados automaticamente como parte dos seus fluxos de trabalho do GitHub Actions. Você pratica Load Testing & Performance Benchmarking (JMeter & k6) com código prático que executa diretamente no navegador, e um tutor de IA 24/7 responde suas dúvidas enquanto trabalha na aula.

Preciso ter experiência prévia para começar Load Testing & Performance Benchmarking (JMeter & k6)?

Nenhuma experiência prévia é necessária. Load Testing & Performance Benchmarking (JMeter & k6) no CoddyKit é estruturado para alunos iniciantes até avançados, então você pode começar aqui ou desde o início e aprender no seu ritmo. Esta é a aula 2 de 4.

Quanto tempo leva a aula “k6 nas Ações do GitHub”?

A maioria das aulas CoddyKit leva cerca de 5–10 minutos. Cada uma é compacta e interativa, então você faz progresso constante e retoma exatamente de onde parou entre web e app.

Posso escrever e executar código nesta aula de Load Testing & Performance Benchmarking (JMeter & k6)?

Sim. Cada aula de Load Testing & Performance Benchmarking (JMeter & k6) inclui um editor de código integrado, então você escreve e executa código real direto no navegador e recebe feedback de IA instantaneamente — nenhuma configuração local necessária.

Todas as aulas deste curso

  1. Integrando o JMeter ao Jenkins
  2. k6 nas Ações do GitHub
  3. Barreiras de Desempenho e SLOs
  4. Análise de tendências e definição de linha de base na CI
← Voltar para Load Testing & Performance Benchmarking (JMeter & k6)