"The code looks good locally but when deployed to the server it crashes" - surely every developer has experienced this heart-wrenching feeling. Recalling the sleepless nights SSHing into the server, typing each command line to copy files and then restarting the service, I realized that doing it manually is not only time-consuming but also full of risks. That's when I looked for an automation solution. The application of GitHub Actions CI/CD automatic deployment is the "lifesaver", helping to turn the entire complex process into smooth underground steps right on the repository. If you're looking to free yourself from repetitive tasks, GitHub Actions that automatically deploy CI/CD tests is the perfect tool to get started.
Automated CI/CD deployment process with GitHub Actions from A-Z for beginners
The CI/CD process of automatically deploying GitHub Actions includes creating YAML files, defining trigger events (Events), setting up the running environment (Jobs) and execution steps (Steps). This is the core platform that helps automate software testing and release.
To understand what GitHub Actions is, you can imagine it as a robot standing by 24/7 on your source code repository. Whenever there is a change, it will automatically run tests and push the code to the server. At Pham Hai, we always encourage teams to establish this process from the first day of the project to minimize human errors. Understanding the core concept is essential. Therefore, learning What is CI/CD continuous deployment process will help you grasp the operating philosophy before getting into engineering. Below are instructions for installing GitHub Actions CI/CD through 5 standard steps.
Step 1: Create YAML workflow file - The brain of automation
File workflow YAML là nơi chứa toàn bộ kịch bản tự động hóa, được đặt bắt buộc trong thư mục .github/workflows của Repository để hệ thống có thể nhận diện.
Mọi thứ bắt đầu bằng một YAML file. Cú pháp YAML syntax rất trực quan, dựa trên việc thụt lề để phân cấp thông tin. Bạn chỉ cần tạo một thư mục .github/workflows ở thư mục gốc của dự án và thêm một file (ví dụ: deploy.yml). Nếu bạn là người mới, việc xây dựng nền tảng qua bài viết Học Git GitHub từ đầu cho developer sẽ giúp quá trình làm việc với Repository trơn tru hơn rất nhiều. File YAML này chính là bộ não định nghĩa toàn bộ Workflow của bạn.
Step 2: Define Events - When will the workflow run?
Events are events that trigger the workflow, most commonly when new code is pushed to the main branch or when a new Pull request is created.
Bạn cần nói cho GitHub biết khi nào thì bắt đầu làm việc. Các Events phổ biến nhất là Push (khi ai đó đẩy code lên) hoặc mở một Pull request. Theo bản cập nhật mới nhất đầu năm 2026 của nền tảng, bạn thậm chí có thể lên lịch chạy workflow theo múi giờ địa phương cụ thể (ví dụ: timezone: "Asia/Ho_Chi_Minh") thay vì chỉ dùng giờ UTC [1]. Điều này cực kỳ tiện lợi cho các tác vụ Continuous Integration chạy báo cáo hàng đêm.
| Event type | YAML syntax | Practical application |
|---|---|---|
| Push | on: push |
Tự động deploy khi merge code vào nhánh main. |
| Pull Request | on: pull_request |
Run automated tests before allowing code merges. |
| Schedule | on: schedule |
Run a cronjob to clean up the database weekly. |
Step 3: Configure Jobs and Steps - Tell GitHub Actions what to do
Jobs represent large processes running on virtual servers (Runners), while Steps are small specific actions (Build, Test) that make up a Job.
A workflow can contain multiple Jobs running in parallel or in series. Each Job will run in a virtual environment called Runners (such as Ubuntu, Windows, macOS). Inside each Job are Steps. For example, step 1 is checkout code, step 2 is install library, step 3 is Build and step 4 is Test. Clear divisions make it easy to track progress and detect errors immediately during the DevOps process.
Step 4: Use Actions from Marketplace - Don't write your own when the community already exists
GitHub Marketplace provides tens of thousands of available Actions developed by the community, helping you integrate complex tasks with just a few lines of declarative code.
Đừng cố gắng phát minh lại bánh xe. Tính đến năm 2026, Marketplace của GitHub đã có hơn 24.000 Actions khác nhau để bạn tự do lựa chọn [1]. Bạn muốn gửi thông báo qua Slack? Có sẵn action cho việc đó. Bạn muốn setup Node.js? Dùng ngay actions/setup-node. Việc tận dụng các module có sẵn này giúp quá trình thiết lập CI/CD pipeline với GitHub Actions nhanh chóng, chuẩn xác và tiết kiệm hàng chục giờ code tay.
Step 5: Manage Secrets - Great way to keep API keys and passwords safe
GitHub Secrets is an encrypted storage place for sensitive information such as server passwords and API keys, ensuring they are never exposed in public source code.
When deploying applications to the server using GitHub Actions, you absolutely must not reveal your SSH password or access token. GitHub provides the Secrets feature to encrypt this data. You can set separate environment variables for the Production, Staging, and Development environments. From the March 2026 update, the platform also allows the use of environments without requiring auto-deployment, making security variable management more flexible than ever [1].
Real-life example: Deploy a simple web application to the server
Applying GitHub Actions for web applications helps turn theory into practical scenarios such as deploying via SSH, building Docker or uploading to the Cloud.
Enough theory, now let's get into the specific GitHub Actions deploy application example. Below are the 3 most common scenarios that developers often use to automate deployment with GitHub Actions in a corporate environment.
Scenario 1: Deploy Node.js application (NextJS/React) to VPS via SSH
This script automates connecting SSH to the VPS, pulling the latest code, building the NextJS project, and restarting the service using PM2 completely automatically.
Nếu bạn đang tìm cách Deploy ứng dụng NextJS với GitHub Actions, cách đơn giản và tiết kiệm nhất là dùng kết nối SSH trực tiếp. Workflow sẽ chạy lệnh build ngay trên Server của bạn. Bạn chỉ cần lưu SSH Key vào mục Secrets, dùng một action như appleboy/ssh-action để kết nối vào VPS. Sau đó, cấu hình các lệnh như git pull, npm install, npm run build và cuối cùng là pm2 restart. Mọi thứ diễn ra tự động chỉ sau một cú push code.
Scenario 2: Package and push Docker image to Docker Hub
Combining GitHub Actions with Docker helps automatically read Dockerfile, build into Image and push to the secure Docker Hub repository every time a new version is available.
Với kiến trúc vi dịch vụ hiện đại, việc dùng GitHub Actions với Docker gần như là tiêu chuẩn bắt buộc. Workflow sẽ đọc file Dockerfile của bạn, thực hiện lệnh docker build để tạo ra một Docker Image hoàn chỉnh. Sau đó, nó sẽ tự động đăng nhập và docker push image đó lên Docker Hub. Với những ai chưa từng làm việc với container, việc đọc hướng dẫn Docker là gì hướng dẫn cài đặt cơ bản là bước chuẩn bị cực kỳ quan trọng để hiểu cách hệ thống này vận hành.
Scenario 3: Deploying applications to cloud platforms (referring to AWS, Kubernetes)
Deploying to the Cloud requires more complex configurations, but GitHub Actions provides deep integration tools with the AWS and Kubernetes ecosystems.
Ở cấp độ dự án lớn, bạn sẽ cần GitHub Actions deploy lên AWS (như dịch vụ ECS, EKS) hoặc GitHub Actions deploy lên Kubernetes. Các nhà cung cấp đám mây đều có các Actions chính chủ hỗ trợ việc này. Ví dụ, aws-actions/configure-aws-credentials giúp xác thực an toàn không cần lưu key cứng. Sau khi build image, workflow sẽ cập nhật file manifest và apply lên cluster. Để có thể làm chủ luồng công việc này, việc bổ sung kiến thức qua bài Kubernetes là gì hướng dẫn triển khai cơ bản sẽ giúp bạn tự tin hơn khi quản lý hạ tầng lớn.
Why am I so "crazy" about GitHub Actions? The benefits cannot be denied
The benefits of GitHub Actions in CI/CD lie in its perfect integration with repositories, rich Marketplace ecosystem, and extremely optimized pricing policy.
After many years of configuring Jenkins or GitLab CI, I am really convinced by the benefits of GitHub Actions in CI/CD. It delivers a seamless Automation experience that few tools on the market today can match.
Built-in GitHub: Everything in one place, so convenient!
No need to install a separate CI/CD server, GitHub Actions is located right in your Repository tab, helping to centrally manage code and deployment flow.
You don't need to maintain a bloated Jenkins server or switch back and forth between browser tabs. All build results and error logs are displayed visually right on the Pull Request interface. This speeds up the Continuous Delivery process, helping the team review code and track Deploy status in one single place.
Huge Community and Marketplace: Whatever you need is there, just "use it"
The community-contributed Actions ecosystem helps you solve most complex CI/CD problems without having to write your own scripts from scratch.
As mentioned above, Marketplace is truly a gold mine. From scanning for security errors, checking code format to sending Telegram messages when deploying successfully, everything is available. You just need to copy the syntax and use. This saves dozens of hours of setup time for system engineers.
Free for public projects and generous limits for private projects
GitHub is completely free for open source projects and gives away 2,000 running minutes per month for personal accounts or private projects.
This is the most "money-making" point that makes many companies convert to this platform. Public projects can be used for unlimited minutes. With the private project, you have 2,000 free minutes available each month. In particular, according to the latest announcement, from January 1, 2026, this platform has reduced the price of their hosted runners by up to 39%, helping teams significantly optimize infrastructure costs when expanding [1].
Easy to learn, easy to use with intuitive YAML syntax
The YAML syntax is easy to read and understand, allowing even non-systems programmers to set up and edit the deploy flow themselves.
Compared to writing complex Groovy scripts, YAML is much more developer-friendly. You can look at a configuration file and immediately understand the flow of data. This clear structure makes handing over projects or mentoring new members much easier.
"Tricks" and bloody experiences when using GitHub Actions CI/CD
Although powerful, setting up a CI/CD pipeline with GitHub Actions still has potential pitfalls such as security exposure, slow builds, or overly cumbersome workflow design.
No tool is absolutely perfect. In the process of learning how to use GitHub Actions deploy, me and the team at Pham Hai had to pay the price with a lot of server downtime. Below are practical experiences you should pay attention to to avoid falling into the same trap.
Mistake 1: Hard-code credentials in YAML files
Directly writing a password or token into a YAML file is the most serious security hole, which can cause the entire system to be stolen.
Đây là lỗi sơ đẳng nhưng cực kỳ nguy hiểm mà nhiều người mới mắc phải. Đừng bao giờ gõ thẳng mật khẩu database hay API key vào file cấu hình. Hãy luôn sử dụng cú pháp ${{ secrets.MY_PASSWORD }}. Nếu lộ mã nguồn, hacker sẽ có toàn quyền truy cập vào hệ thống hạ tầng của bạn.
Mistake 2: Not taking advantage of Cache to speed up build
Bypassing the caching mechanism causes each time the workflow runs to have to reload the entire library from the beginning, increasing waiting time and consuming free minutes.
Nếu bạn đang setup CI/CD cho PHP với GitHub Actions (chạy lệnh composer install) hay dự án Node.js (chạy npm install), việc không dùng cache sẽ khiến thời gian build kéo dài thêm vài phút mỗi lần. Sử dụng actions/cache để lưu lại thư mục node_modules hoặc vendor sẽ giúp workflow ở những lần chạy sau nhanh như chớp.
Mistake 3: Workflow is too complex and difficult to debug
Cramming too much logic into a single workflow file makes maintenance, reading comprehension, and troubleshooting a nightmare.
Don't turn your YAML file into a jumble thousands of lines long. Let's break it down into reusable workflows. Separate the build stream, test stream and deploy stream into separate files. When there is an error somewhere, you will localize it and handle it immediately.
Pro-tip: How to debug workflow when it "goes wrong"
Turning on debug log mode and using SSH connection tools directly to the runner is the fastest way to diagnose errors when the workflow is not working as expected.
Khi tự động deploy dự án với GitHub Actions bị lỗi mà log trên màn hình không rõ ràng, hãy thêm secret ACTIONS_STEP_DEBUG với giá trị true để xem log chi tiết đến từng biến môi trường. Đôi khi, việc chèn các đoạn mã bash nhỏ vào steps là cần thiết để kiểm tra trạng thái file. Nếu bạn thường xuyên thao tác với hệ thống, việc nắm vững Shell script cơ bản cho DevOps sẽ là vũ khí bí mật giúp bạn gỡ rối mọi tình huống hóc búa ngay trên runner.
In short, setting up an automated GitHub Actions CI/CD deploy process is not as scary and complicated as many people think. It is an extremely valuable skill in this day and age, saving you tons of time and effort typing commands manually. I dare to affirm that, once you get used to the convenience and speed of this tool, you will never want to go back to the old copy-paste deployment method again. This is a completely worthy investment for anyone's career advancement path.
Are you ready to automate your deployment process? Try it out with your smallest project and share the results in the comments below!
Lưu ý: 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.