k6 ใน GitHub Actions
ตั้งค่าการทดสอบ k6 ให้ทำงานโดยอัตโนมัติเป็นส่วนหนึ่งของเวิร์กโฟลว์ GitHub Actions
k6 ใน GitHub Actions เป็นบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ฟรีบน CoddyKit นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน คุณสามารถอ่านบทเรียนทั้งหมดด้านล่างฟรี — จากนั้นลองปฏิบัติด้วยตัวคุณเองในเบราว์เซอร์พร้อมตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7 บทเรียนนี้เป็นส่วนหนึ่งของเส้นทางการเรียน 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.0Executing 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.jsViewing 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!
คำถามที่พบบ่อย
บทเรียน “k6 ใน GitHub Actions” ฟรีหรือไม่
ใช่ — ข้อความเต็มของ “k6 ใน GitHub Actions” ฟรีให้อ่านที่นี่บนเว็บ เพื่อปฏิบัติแบบโต้ตอบ (ตัวแก้ไขโค้ดในตัวและติวเตอร์ AI ตลอด 24/7) และปลดล็อคส่วนที่เหลือของคอร์ส Load Testing & Performance Benchmarking (JMeter & k6) ให้อัปเกรดเป็น CoddyKit PRO คอร์ส Load Testing & Performance Benchmarking (JMeter & k6) มีบทเรียนทั้งหมด 4 บทเรียน
คุณจะเรียนรู้อะไรในบทเรียน “k6 ใน GitHub Actions”
ตั้งค่าการทดสอบ k6 ให้ทำงานโดยอัตโนมัติเป็นส่วนหนึ่งของเวิร์กโฟลว์ GitHub Actions คุณปฏิบัติ Load Testing & Performance Benchmarking (JMeter & k6) ด้วยโค้ดที่ใช้งานได้จริงที่คุณเรียกใช้โดยตรงในเบราว์เซอร์ และติวเตอร์ AI ตลอด 24/7 ตอบคำถามของคุณขณะที่คุณไปผ่านบทเรียน
คุณต้องมีประสบการณ์ก่อนที่จะเริ่มเรียน Load Testing & Performance Benchmarking (JMeter & k6) หรือไม่
ไม่จำเป็นต้องมีประสบการณ์มาก่อน Load Testing & Performance Benchmarking (JMeter & k6) บน CoddyKit ออกแบบมาสำหรับผู้เริ่มต้นไปจนถึงผู้เรียนขั้นสูง คุณสามารถเริ่มต้นที่นี่หรือเริ่มจากตัวแรกและเรียนด้วยความเร็วของคุณเอง นี่คือบทเรียนที่ 2 จากทั้งหมด 4 บทเรียน
บทเรียน “k6 ใน GitHub Actions” ใช้เวลานานแค่ไหน
บทเรียน CoddyKit ส่วนใหญ่ใช้เวลาประมาณ 5–10 นาที แต่ละบทเรียนจึงสั้นและเป็นแบบโต้ตอบ คุณสามารถก้าวหน้าอย่างต่อเนื่องและกลับมาเรียนต่อจากตรงที่เพิ่งหยุดบนเว็บและแอปได้เลย
ฉันเขียนและรันโค้ดในบทเรียน Load Testing & Performance Benchmarking (JMeter & k6) นี้ได้ไหม
ได้ บทเรียน Load Testing & Performance Benchmarking (JMeter & k6) ทุกบทมีตัวแก้ไขโค้ดในตัว คุณจึงเขียนและรันโค้ดจริงได้เลยในเบราว์เซอร์ และได้รับข้อเสนอแนะจาก AI ในทันที — ไม่ต้องติดตั้งในเครื่องของคุณ
บทเรียนทั้งหมดในหลักสูตรนี้
- การผสาน JMeter กับ Jenkins
- k6 ใน GitHub Actions
- ด่านประสิทธิภาพและ SLOs
- การวิเคราะห์แนวโน้มและการสร้างค่าฐานใน CI