This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Auto Build and Deploy to Build Branch | |
on: | |
push: | |
branches: | |
- 'main' # 只监听 main 分支的提交 | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
# 检出代码 | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
# 设置 Node.js 环境 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '16' # 设置 Node.js 版本 | |
# 安装依赖 | |
- name: Install dependencies | |
run: | | |
npm install | |
# 运行构建 | |
- name: Run build | |
run: | | |
npm run build | |
# 发布构建产物到 build 分支 | |
- name: Push build to build branch | |
run: | | |
git config --global user.name "github-actions" | |
git config --global user.email "[email protected]" | |
git checkout -b build || git checkout build # 如果 build 分支不存在则创建 | |
git add . | |
git commit -m "Deploy build to build branch" | |
git push --force origin build |