I remember in the old days, every time I deployed, I "sweated", trashtalking each other with the test team in all kinds of ways because of environmental errors. Since the day I learned about GitHub Actions automatically deploying CI/CD tests, my dev life has turned to a new page. Automatically build, automatically test, automatically deploy with just a few lines of YAML code, no need to call any DevOps guy. This article is the passion Pham Hai has compiled after many years of working in the profession, helping you set up a delicious pipeline yourself, even if you are a newbie.
Get to work: Build your first automated CI/CD deployment pipeline in 15 minutes
Để thiết lập pipeline CI/CD với GitHub Actions, bạn chỉ cần tạo một file định dạng YAML trong thư mục .github/workflows của Repository, khai báo các sự kiện kích hoạt và các bước thực thi. Quy trình này cực kỳ nhanh chóng và thân thiện.
GitHub Actions CI/CD guide for beginners often scares people because they think it has to be complicated to set up a server. But in fact, you can completely master it during your lunch break. At Pham Hai, we always encourage young developers to do this step themselves to understand their application life cycle.
Step 1: Create a YAML workflow file - "The brain" of automation
The Workflow YAML file is where your entire automation script resides, acting as a blueprint for ordering the system.
Mọi thứ bắt đầu bằng một YAML file. Trong Repository của bạn trên GitHub, hãy tạo một cấu trúc thư mục là .github/workflows. Bên trong đó, tạo một file ví dụ tên là deploy.yml. Đây chính là "bộ não" nơi bạn viết kịch bản. Việc viết file này khá trực quan, giống như bạn đang liệt kê các gạch đầu dòng những việc cần làm. Trong thế giới công nghệ, tự động hóa là chìa khóa. Nếu bạn thích các dạng tự động hóa trực quan không cần code, việc tìm hiểu n8n tự động hóa workflow miễn phí là một hướng đi mở rộng rất thú vị.
Step 2: Define Events - When is the pipeline triggered? (push, pull_request)
Events are events that trigger the workflow, most commonly when new code is pushed (push) or when there is a request to merge code (Pull Request).
Bạn muốn kịch bản chạy khi nào? Đó là lúc ta định nghĩa Events. Thường thì mình sẽ cài đặt để mỗi khi có ai đó push code lên nhánh main, hoặc tạo một Pull Request, thì hệ thống sẽ tự động chạy. Dưới đây là một ví dụ cơ bản:
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
Đặc biệt, dựa trên bản cập nhật mới nhất vào tháng 3/2026, GitHub đã hỗ trợ múi giờ IANA cho các workflow chạy theo lịch trình (cron). Nghĩa là bạn có thể dễ dàng hẹn giờ chạy job theo múi giờ Asia/Ho_Chi_Minh thay vì phải tự trừ lùi giờ UTC như trước kia. Điều này thực sự là một cứu cánh cho anh em dev Việt Nam.
Step 3: Set up Jobs and Steps - Tell GitHub Actions what to do?
Jobs are large groups of tasks (like build, test), while Steps are small commands, executed sequentially within that Job.
In the YAML file, you will divide the job into Jobs. Each Job runs independently on a virtual server. Inside the Job are Steps that execute sequentially from top to bottom. For example: Step 1 is to checkout the code, Step 2 is to install the library, Step 3 is Build code. This thinking of breaking down sequential steps is very common in automation. To better understand how automated systems simulate human operations, you can read our article What is RPA for process automation.
Step 4: Run a test and see the "magic" happen in the Actions tab
After committing the YAML file, you just need to switch to the "Actions" tab on the GitHub interface to monitor the real-time progress of the system.
Khi bạn đã viết xong, hãy commit và push file YAML đó lên repo. Ngay lập tức, bạn bấm vào tab "Actions" trên thanh menu của GitHub. Bạn sẽ thấy một tiến trình đang xoay vòng báo hiệu đang chạy. Nhấp vào đó, log sẽ hiện ra chi tiết từng bước. Cảm giác lần đầu tiên nhìn các dòng log xanh lá cây chạy vèo vèo và báo Success thực sự rất "đã", nó chứng minh bạn đã Thiết lập pipeline CI/CD với GitHub Actions thành công.
What is GitHub Actions and why is it so "divine"? Real benefits, not gossip
GitHub Actions is a CI/CD platform built right into the GitHub ecosystem, helping to automate all software development processes without the need to install third-party tools.
Many friends often ask me what GitHub Actions is for CI/CD and why everyone is mentioning it lately. Simply put, the benefit of GitHub Actions in CI/CD lies in "All-in-one". You code on GitHub, and you deploy using GitHub itself.
It's not a big deal: A simple understanding of Continuous Integration and Deployment (CI/CD)
CI/CD is the process of continuously combining code (Continuous Integration), automating testing, and safely delivering the product to users (Continuous Delivery).
Tích hợp liên tục và triển khai liên tục với GitHub Actions nghe có vẻ học thuật và to tát. Nhưng thực tế, Continuous Integration (CI) chỉ là việc bạn code xong, đẩy lên, máy tự động kiểm tra xem có lỗi cú pháp hay hỏng hóc gì không. Continuous Delivery (CD) là máy tự động đóng gói và Deploy ứng dụng lên server của bạn. Mọi thứ diễn ra trơn tru, giảm thiểu tối đa sự can thiệp của con người. Để tối ưu hóa quy trình CI này, nhiều team hiện nay còn ứng dụng AI code review kiểm tra chất lượng code ngay trong pipeline để bắt lỗi logic từ sớm.
Why does my small team love GitHub Actions? Economical, fast and built-in
GitHub Actions for small projects is the perfect choice because it is free for public repos, does not require maintaining a separate server, and is developer-friendly.
For startups or dev teams of 3-5 people, GitHub Actions for small projects is truly sincere. You GitHub Actions don't need a DevOps expert to install, configure, and maintain cumbersome Jenkins servers.
| Criteria | Manual Deployment | Use GitHub Actions |
|---|---|---|
| Thời gian | 15 - 30 minutes/time | 2 - 5 minutes (Automatic) |
| Rủi ro lỗi | High (forgot orders, made mistakes) | Very low (runs according to script) |
| Chi phí hạ tầng | No cost but effort | Free basic running minutes |
Examining the core components: What's interesting about Runners, Secrets, and Marketplace?
Runners are the servers that run the code, Secrets secure sensitive information, and the Marketplace provides thousands of pre-made actions for you to reuse.
To master this tool, you only need to remember 3 core concepts:
- Runners: Là các máy chủ ảo (Ubuntu, Windows, macOS) do GitHub cấp để chạy job của bạn.
- Secrets: Nơi giấu các mã token, password database. Đừng bao giờ gõ thẳng password vào file code.
- GitHub Marketplace: Chợ ứng dụng tuyệt vời. Bạn muốn gửi thông báo Telegram khi deploy xong? Lên chợ tìm action có sẵn, copy vào là xong, không cần tự code lại từ đầu.
Upgrade the pipeline: From "running" to "running well"
For your pipeline to truly deliver high value, you need to integrate automated testing, secure environment variable management, and multi-environment deployment configurations.
How to automate deployment with GitHub Actions to be both fast and safe? Once you are familiar with the basic steps, it's time to "tune" the pipeline to make it more professional.
Test automation (automated testing): No more bugs, better sleep
Using GitHub Actions for automated testing helps prevent erroneous code from being merged into the main branch, ensuring stable software quality.
Using GitHub Actions for automated testing is a mandatory step in technology companies. Before deploying, you must run through Tests (Unit Test, E2E Test). If the test fails, the pipeline will immediately stop, preventing that error code from reaching production. This feature has saved me from losing goals countless times. Recently, the dev ecosystem also has AI tools to automatically write unit tests for projects, helping you quickly create test scripts to integrate into GitHub Actions.
Deploy multiple environments with GitHub Actions: Staging preview, Production runs for real
The Environments feature helps you set up a separate deployment process for Staging (for internal testing) and Production (for end users) environments.
When the project grows, you cannot finish coding it and push it straight to customers to use. You need to Deploy multiple environments with GitHub Actions. GitHub provides a very powerful Environments feature.
Đáng chú ý, theo cập nhật mới nhất từ GitHub vào tháng 3/2026, họ đã cho phép sử dụng Environments chỉ để quản lý biến (variables) và Secrets mà không bắt buộc phải tạo auto-deployment (deployment: false). Điều này giúp các dev linh hoạt hơn rất nhiều khi chỉ muốn tận dụng khả năng bảo mật của môi trường mà không muốn hệ thống tự động đẩy code đi.
Example GitHub Actions workflow for a real Node.js and ReactJS project
A standard workflow usually includes these steps: checkout code, install the environment (Node.js/Docker), download dependencies, run tests, build and deploy.
Below is a practical GitHub Actions workflow example that Pham Hai often uses for Node.js projects. If you use Docker, you can add a step to build Docker Image from Dockerfile and push it to the registry.
name: Node.js Production CI/CD
on:
push:
branches: [ "main" ]
jobs:
build-and-deploy:
runs-on: ubuntu-latest
steps:
- name: Lấy code về máy ảo
uses: actions/checkout@v4
- name: Cài đặt Node.js
uses: actions/setup-node@v4
with:
node-version: '20.x'
- name: Cài đặt thư viện và Test
run: |
npm ci
npm run test
- name: Build ứng dụng
run: npm run build
Management of environment variables and "secrets" is absolutely safe
GitHub Secrets encrypts your sensitive information to military standards, ensuring it is not exposed in run logs or in public source code.
Các thông tin như API Key của Stripe, Database Password phải được lưu trong mục Settings > Secrets and variables > Actions của repository. Trong file YAML, bạn gọi nó ra bằng cú pháp ${{ secrets.DB_PASSWORD }}. Hệ thống của GitHub đủ thông minh để che (mask) các giá trị này thành các dấu *** nếu nó lỡ bị in ra màn hình log, đảm bảo an toàn tuyệt đối cho dự án của bạn.
The stumbles I've encountered and how you avoided them
During use, you may encounter YAML syntax errors, free runner resource limitations, or too long build times.
Although Automation brings many benefits, "everything has a difficult beginning". Below are the bloody experiences that I want to share so you don't make the same mistake.
"Silly" YAML error: How to effectively debug and validate config files
The most common error when writing actions is incorrect white space (indentation) in the YAML file. Please use the extensions in the editor to validate before pushing.
The YAML language is extremely sensitive to whitespace. Indenting the beginning of a line by just one wrong space will cause your pipeline to report a syntax error immediately. My advice is to install the "YAML" extension on VS Code. It will underline error messages as you type, helping you debug extremely quickly before posting the code online.
Is free Runner enough? When should you think about self-hosted runner?
The free GitHub-hosted runner is usually enough for small projects. For large projects, you can host the runner yourself, but you need to note the new platform fee schedule from 2026.
For personal or open-source projects, the free minutes that GitHub grants are more than enough. However, if you are working for a business, you need to immediately update the latest price information for 2026.
Specifically, from January 1, 2026, GitHub has reduced server rental prices (GitHub-hosted runners) by up to 39%. But in return, if your company wants to use a self-hosted runner for private repos for security, then from March 1, 2026, GitHub will start charging a "platform fee" of $0.002 for every running minute. Therefore, the cost problem between renting a machine from GitHub or running it yourself at home needs to be carefully recalculated.
Optimize build speed: Use cache to save time and money
Sử dụng action cache (như actions/cache) để lưu lại các thư viện đã tải, giúp giảm đáng kể thời gian cho các lần chạy tiếp theo.
Nếu mỗi lần chạy pipeline đều phải tải lại hàng trăm MB thư viện từ đầu thì quá lãng phí tài nguyên. Hãy sử dụng tính năng Cache của GitHub Actions. Nó sẽ lưu lại các thư mục như node_modules hoặc .m2. Lần sau chạy, hệ thống chỉ việc lấy ra xài, giúp giảm thời gian chạy từ 10 phút xuống còn 2 phút. Trong thế giới cloud, tiết kiệm thời gian chạy chính là tiết kiệm tiền thật cho công ty.
In short, with GitHub Actions automatically deploying CI/CD tests, setting up a software development process is no longer a huge technical barrier. It empowers us developers, helping to eliminate boring, repetitive tasks to focus on creating high-quality products. Don't be afraid to experiment, because once you get your project on the automation track, you'll wonder why you didn't use it sooner.
Are you ready to upgrade your project? Try creating a simple workflow for your repository today and share the results, or difficulties you encounter in the comments section below!
Lưu ý: Các thông tin trong bài viết này chỉ mang tính chất tham khảo. Để có lời khuyên tốt nhất, vui lòng liên hệ trực tiếp với chúng tôi để được tư vấn cụ thể dựa trên nhu cầu thực tế của bạn.