Trang chủ / Blog / CI/CD Cho Game Developer: Tự Động Build...
Programming 02/05/2026 9 phút đọc

CI/CD Cho Game Developer: Tự Động Build Và Deploy Game

Hướng dẫn thiết lập CI/CD pipeline cho game developer - Unity Cloud Build, GitHub Actions, GameCI, automated testing và distribution.

L
LamGame Game Developer & Writer

CI/CD Cho Game Developer: Tự Động Hóa Build Và Deploy Game

Trong thế giới phát triển phần mềm hiện đại, CI/CD (Continuous Integration / Continuous Deployment) đã trở thành tiêu chuẩn. Tuy nhiên, trong game development, nhiều team vẫn build game thủ công trên máy local - một quy trình tốn thời gian, dễ lỗi, và không scalable. Bài viết này sẽ hướng dẫn bạn thiết lập CI/CD pipeline hoàn chỉnh cho dự án game Unity, từ automated build đến distribution. Tham khảo thêm các dự án game mẫu có CI/CD tại kho source game LamGame.

1. Tại Sao Game Developer Cần CI/CD?

Build game Unity cho nhiều platform (Android, iOS, Windows, WebGL) là quá trình tốn thời gian. Một build Android có thể mất 15-30 phút, iOS build còn lâu hơn. Nếu bạn cần build cho 4 platform, đó là hàng giờ ngồi chờ. Với CI/CD, quá trình này hoàn toàn tự động - bạn push code lên Git, pipeline tự động build cho tất cả platform, chạy test, và distribute build đến tester hoặc store.

Ngoài tiết kiệm thời gian, CI/CD còn mang lại nhiều lợi ích quan trọng khác. Đầu tiên là consistency - mọi build đều được tạo trong cùng một environment sạch, loại bỏ vấn đề "works on my machine". Thứ hai là early bug detection - automated tests chạy mỗi khi có code mới, phát hiện regression sớm. Thứ ba là faster iteration - QA team có thể nhận build mới trong vài phút sau khi developer push code, thay vì phải chờ đến cuối ngày.

2. GitHub Actions Với GameCI

GameCI là bộ công cụ mã nguồn mở cung cấp Docker images và GitHub Actions cho Unity CI/CD. Đây là giải pháp phổ biến nhất cho indie developer và small team vì hoàn toàn miễn phí (sử dụng GitHub Actions free tier). GameCI hỗ trợ tất cả Unity versions và build targets.

Đầu tiên, bạn cần setup Unity license. GameCI cần Unity license để activate trong CI environment. Tạo GitHub Secrets cho repository với các giá trị UNITY_LICENSE (nội dung file .ulf), UNITY_EMAIL, và UNITY_PASSWORD. Sau đó tạo workflow file:

# .github/workflows/build.yml
name: Game Build Pipeline

on:
  push:
    branches: [main, develop]
  pull_request:
    branches: [main]

jobs:
  test:
    name: Run Tests
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          lfs: true
      - uses: game-ci/unity-test-runner@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          projectPath: .
          testMode: all
          artifactsPath: test-results
      - uses: actions/upload-artifact@v4
        if: always()
        with:
          name: Test Results
          path: test-results

  build-android:
    name: Build Android
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          lfs: true
      - uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          targetPlatform: Android
          androidKeystoreName: user.keystore
          androidKeystoreBase64: ${{ secrets.ANDROID_KEYSTORE_BASE64 }}
          androidKeystorePass: ${{ secrets.ANDROID_KEYSTORE_PASS }}
          androidKeyaliasName: ${{ secrets.ANDROID_KEYALIAS_NAME }}
          androidKeyaliasPass: ${{ secrets.ANDROID_KEYALIAS_PASS }}
      - uses: actions/upload-artifact@v4
        with:
          name: Android Build
          path: build/Android

  build-webgl:
    name: Build WebGL
    needs: test
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
        with:
          lfs: true
      - uses: game-ci/unity-builder@v4
        env:
          UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
        with:
          targetPlatform: WebGL
      - uses: actions/upload-artifact@v4
        with:
          name: WebGL Build
          path: build/WebGL

3. Unity Cloud Build

Unity Cloud Build là dịch vụ CI/CD chính thức từ Unity, tích hợp trực tiếp vào Unity Dashboard. Ưu điểm lớn nhất là không cần cấu hình phức tạp - kết nối repository, chọn platform, và Unity lo phần còn lại. Unity Cloud Build hỗ trợ GitHub, GitLab, Bitbucket, và SVN. Nó cũng tự động quản lý Unity license, không cần setup thủ công như GameCI.

Tuy nhiên, Unity Cloud Build có một số hạn chế. Free tier chỉ cho phép 1 concurrent build với thời gian build giới hạn. Bạn không có nhiều control over build environment như khi sử dụng GitHub Actions. Và nếu project sử dụng native plugins hoặc custom build scripts phức tạp, có thể gặp vấn đề tương thích. Đối với team lớn hoặc project phức tạp, self-hosted CI/CD thường linh hoạt hơn.

4. Automated Testing Trong Game

Testing trong game development thường bị bỏ qua vì "game khó test". Tuy nhiên, có nhiều phần của game hoàn toàn có thể và nên được test tự động:

  • Unit Tests: Test các hàm logic thuần túy - damage calculation, inventory management, quest system, save/load. Sử dụng Unity Test Framework (NUnit) với Test Runner.
  • Integration Tests: Test interaction giữa các system - player nhặt item thì inventory cập nhật đúng, enemy chết thì drop loot đúng. Chạy trong Play Mode.
  • Build Verification Tests: Đảm bảo game build thành công, scene load không lỗi, không có missing references. Đây là minimum viable testing cho CI/CD.
  • Performance Tests: Sử dụng Unity Performance Testing Package để đo FPS, memory usage, load time. Set threshold và fail build nếu performance regression.
using NUnit.Framework;

[TestFixture]
public class DamageCalculatorTests
{
    [Test]
    public void CalculateDamage_WithArmor_ReducesDamage()
    {
        var calculator = new DamageCalculator();
        float result = calculator.Calculate(baseDamage: 100, armor: 50);
        Assert.AreEqual(50f, result, 0.01f);
    }

    [Test]
    public void CalculateDamage_CriticalHit_DoublesDamage()
    {
        var calculator = new DamageCalculator();
        float result = calculator.Calculate(baseDamage: 100, armor: 0, isCritical: true);
        Assert.AreEqual(200f, result, 0.01f);
    }

    [Test]
    public void CalculateDamage_NegativeArmor_ClampsToZero()
    {
        var calculator = new DamageCalculator();
        float result = calculator.Calculate(baseDamage: 100, armor: -10);
        Assert.GreaterOrEqual(result, 100f);
    }
}

5. Build Distribution Tự Động

Sau khi build thành công, bước tiếp theo là distribute build đến đúng người. Có nhiều giải pháp distribution tùy theo mục đích:

Firebase App Distribution cho internal testing trên Android và iOS. Tích hợp dễ dàng với GitHub Actions thông qua Firebase CLI. Tester nhận notification khi có build mới và có thể cài đặt trực tiếp từ link. TestFlight cho iOS beta testing - upload IPA tự động thông qua fastlane. Google Play Internal Testing cho Android - upload AAB trực tiếp lên Play Console internal track. Steam sử dụng SteamCMD trong CI pipeline để upload build lên Steam depot tự động. itch.io sử dụng butler CLI tool để push build - đặc biệt phù hợp cho indie game và game jam.

# Ví dụ: Deploy WebGL build lên itch.io
deploy-itchio:
  name: Deploy to itch.io
  needs: build-webgl
  runs-on: ubuntu-latest
  steps:
    - uses: actions/download-artifact@v4
      with:
        name: WebGL Build
        path: build/WebGL
    - uses: KikimoraGames/[email protected]
      with:
        butlerApiKey: ${{ secrets.BUTLER_API_KEY }}
        gameData: build/WebGL
        itchUsername: your-username
        itchGameId: your-game
        buildChannel: webgl

6. Git LFS Và Asset Management

Game project thường chứa nhiều file binary lớn (textures, models, audio) không phù hợp với Git thông thường. Git LFS (Large File Storage) là giải pháp chuẩn - nó lưu trữ file lớn trên server riêng và chỉ giữ pointer trong Git repository. Cấu hình Git LFS cho Unity project bằng cách tạo file .gitattributes track các file asset phổ biến như *.png, *.psd, *.fbx, *.wav, *.mp3. Trong CI pipeline, đảm bảo checkout step có lfs: true để download LFS files.

7. Versioning Và Release Management

Quản lý version number tự động là phần quan trọng của CI/CD pipeline. Sử dụng Semantic Versioning (MAJOR.MINOR.PATCH) và tự động increment version dựa trên Git tags hoặc commit messages. Trong Unity, version number được set trong PlayerSettings - bạn có thể update nó trong CI pipeline thông qua Unity command line arguments hoặc script. Mỗi build nên có unique build number (sử dụng CI run number) để dễ dàng track và debug.

CI/CD không chỉ dành cho team lớn - ngay cả solo developer cũng hưởng lợi từ automated build và testing. Bắt đầu đơn giản với một workflow build cho một platform, sau đó mở rộng dần. Thời gian đầu tư vào CI/CD sẽ được hoàn lại gấp nhiều lần trong suốt vòng đời dự án. Nếu bạn đang tìm kiếm vị trí DevOps hoặc Build Engineer trong ngành game, hãy xem các cơ hội việc làm tại LamGame.

Bài viết hữu ích?
Chia sẻ:
FB X TG
L

LamGame

Game Developer & Technical Writer tại LamGame.vn. Chia sẻ kiến thức về game development, Unity, AI tools cho cộng đồng developer Việt Nam.

Đọc thêm bài viết hay

Khám phá kiến thức game dev, tips & tricks từ cộng đồng

← Về trang Blog