name: test # 名字
on:
push:
branches: [ "main" ] # 监听main分支的 push 操作
# Environment variables available to all jobs and steps in this workflow
permissions:
contents: write # 允许写
jobs:
build:
runs-on: ubuntu-latest # 环境
environment: production
steps:
- name: Checkout # checkout
uses: actions/checkout@v4
- name: node install # 装 Node 限制版本
uses: actions/setup-node@v4.0.3
with:
# Version Spec of the version to use. Examples: 12.x, 10.15.1, >=10.15.0.
node-version: "20.X" # optional
- name: INSTALL NODE MODULES # 安装依赖
run: npm i
- name: Build # 安装编译
run: npm run build
- name: Deploy to GitHub Pages # 将编译好的文件放到新的分支中
uses: JamesIves/github-pages-deploy-action@v4
with:
branch: gh-pages # 分支名称
folder: dist # 打包的文件夹名称
- name: Deploy to server
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.REMOTE_HOST }}
username: ${{ secrets.REMOTE_USER }}
password: ${{ secrets.REMOTE_PASS }}
port: ${{ secrets.REMOTE_PORT }}
script: |
git config pull.rebase false # 这种策略会创建一个新的合并提交,将本地和远程的更改合并在一起。
cd /www/test # 进入项目在服务器上的位置
git pull origin gh-pages # 拉取最新代码
其中host: ${{ secrets.REMOTE_HOST }} username: ${{ secrets.REMOTE_USER }} password: ${{ secrets.REMOTE_PASS }} port: ${{ secrets.REMOTE_PORT }}
配置位置