0Pricing
Load Testing & Performance Benchmarking (JMeter & k6) · レッスン

GitHub Actionsでのk6

GitHub Actionsのワークフローの一部としてk6テストを自動実行するよう設定します。

「GitHub Actionsでのk6」はCoddyKit上の無料Load Testing & Performance Benchmarking (JMeter & k6)レッスンです。 これはレッスン2/4です。 下記で完全なレッスンを無料で読むことができます。その後、ブラウザ内の組み込みコードエディタと24時間対応のAIチューターでハンズオン演習できます。 これはLoad Testing & Performance Benchmarking (JMeter & k6)学習パスの一部であり、ウェブとCoddyKitアプリ全体で進捗が同期されます。 Load Testing & Performance Benchmarking (JMeter & k6)コースには全4レッスンが含まれています。

このレッスンの一部はまだ翻訳されておらず、英語で表示されています。

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!

よくある質問

「GitHub Actionsでのk6」レッスンは無料ですか?

はい。「GitHub Actionsでのk6」の完全なテキストはこのウェブで無料で読めます。インタラクティブに演習し(組み込みコードエディタと24時間対応のAIチューター)、Load Testing & Performance Benchmarking (JMeter & k6)コースの残りをアンロックするには、CoddyKit PROにアップグレードしてください。 Load Testing & Performance Benchmarking (JMeter & k6)コースには全4レッスンが含まれています。

「GitHub Actionsでのk6」で何を学びますか?

GitHub Actionsのワークフローの一部としてk6テストを自動実行するよう設定します。 ブラウザで直接実行するハンズオンコードでLoad Testing & Performance Benchmarking (JMeter & k6)を演習し、24時間対応のAIチューターがレッスンを進める中での質問に答えます。

Load Testing & Performance Benchmarking (JMeter & k6)を始めるのに経験は必要ですか?

事前経験は必要ありません。CoddyKitのLoad Testing & Performance Benchmarking (JMeter & k6)は初級者から上級者向けに構成されているため、ここから始めるか最初から始めて、自分のペースで進むことができます。 これはレッスン2/4です。

「GitHub Actionsでのk6」レッスンにはどのくらい時間がかかりますか?

ほとんどのCoddyKitレッスンは約5~10分かかります。各レッスンはコンパクトでインタラクティブなので、着実に進歩し、ウェブとアプリ全体で正確に前回の場所から再開できます。

このLoad Testing & Performance Benchmarking (JMeter & k6)レッスンでコードを書いて実行できますか?

はい。すべてのLoad Testing & Performance Benchmarking (JMeter & k6)レッスンに組み込みコードエディタが含まれているため、ブラウザでリアルコードを書いて実行し、即座のAIフィードバックを取得できます。ローカル設定は不要です。

このコースのすべてのレッスン

  1. JMeterとJenkinsの統合
  2. GitHub Actionsでのk6
  3. パフォーマンスゲートとSLO
  4. CIにおけるトレンド分析とベースライン作成
← Load Testing & Performance Benchmarking (JMeter & k6)に戻る