CI(Continuous Integration,持續整合)
每次Commit和Push的時候,都可以自動化的執行的測試、建置,透過這樣的方式快速找出問題
CD(Continuous Delivery / Deployment,持續交付 / 部署)
程式碼通過自動化測試後,可以快速且可靠地部署到測試環境或正式環境
== CI Pipeline ==
== CD Pipeline ==
是 GitHub 提供的一個自動化服務,就是把 CI/CD 流程寫成程式碼直接在 GitHub 裡運行,當上傳code後,就可以自動化完成:
(範例使用ChatGPT生成)
這邊用一個很簡單的前端網頁
首先需要一個在 GitHub 上建立一個 repo
專案裡放一個index.html
,內容隨便寫了一個Hello World
然後在 repo 裡新增一個資料夾 .github/workflows/
,並新增檔案 deploy.yml
name: Deploy static site to GitHub Pages
on:
push:
branches:
- main # 當 main 分支有更新時執行
permissions:
contents: write # 允許 Github Actions push 到 gh-pages 分支
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_dir: ./
流程:
main
分支,會自動執行gh-pages
分支開啟 GitHub Pages
到 repo 的 Settings → Pages,選擇 Branch = gh-pages,就能看到網頁了
https://medium.com/技術筆記/何謂-ci-cd-利用-github-actions-做一個簡單的-ci-cd-2d55e6dabeed
https://kucw.io/blog/github-actions-intro/