update test #5
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: Deploy Vue App | |
on: | |
push: | |
branches: | |
- main # 监听main分支的推送 | |
jobs: | |
build-and-deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout source code | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 # 获取完整历史记录 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: '18' # 根据项目需求设置Node.js版本 | |
cache: 'npm' | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build project | |
run: pnpm build | |
- name: Checkout target branch | |
uses: actions/checkout@v3 | |
with: | |
ref: web-build # 目标分支名称 | |
fetch-depth: 0 | |
token: ${{ secrets.GITHUB_TOKEN }} | |
- name: Copy build files | |
run: | | |
mkdir -p dist | |
cp -R ../dist/* ./dist/ | |
- name: Commit and push build files | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
git config --global user.name "github-actions[bot]" | |
git config --global user.email "github-actions[bot]@users.noreply.github.com" | |
git add dist/ | |
git commit -m "Deploy build files" || echo "No changes to commit" | |
git push origin web-build | |
- name: Clean up | |
run: | | |
git clean -fd |