update test #19
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@v4 | |
with: | |
fetch-depth: 0 # 获取完整历史记录 | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: 'lts/*' # 使用LTS版本 | |
check-latest: true # 确保使用最新版本 | |
cache-dependency-path: 'pnpm-lock.yaml' | |
- name: Install pnpm | |
run: npm install -g pnpm | |
- name: Install dependencies | |
run: pnpm install | |
- name: Build project | |
run: pnpm build | |
- name: Verify build output | |
run: | | |
if [ ! -d "./dist" ]; then | |
echo "Error: dist directory not found. Build might have failed." | |
exit 1 | |
fi | |
- name: Checkout target branch | |
uses: actions/checkout@v4 | |
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 |