fix README #59
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: Build and Deploy | |
on: | |
workflow_dispatch: | |
push: | |
branches: | |
- master | |
jobs: | |
build: | |
name: Build Website | |
runs-on: windows-latest | |
steps: | |
# 检出 Git 仓库 | |
- name: Check out git repository | |
uses: actions/checkout@v4 | |
# 安装 Node.js | |
- name: Install Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: "20.x" | |
# 复制环境变量文件 | |
- name: Copy .env.example | |
run: | | |
if (-not (Test-Path .env)) { | |
Copy-Item .env.example .env | |
} else { | |
Write-Host ".env file already exists. Skipping the copy step." | |
} | |
# 安装项目依赖 | |
- name: Install Dependencies | |
run: | | |
npm install -g pnpm | |
pnpm install | |
# 构建程序 | |
- name: Build Website | |
run: pnpm run build | |
env: | |
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }} | |
# 上传构建产物 | |
- name: Upload artifacts | |
# 链接 https://github.com/actions/upload-artifact/ | |
uses: actions/upload-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
# 以下是自动化将打包的静态页面部署到 gh-pages 分支和我自己服务器的脚本 | |
# 为了互不影响,采用并行执行的方式 | |
deploy-to-gh-pages: | |
name: Deploy to gh-pages-deprecated | |
runs-on: ubuntu-latest | |
needs: build # 表示依赖于 build 作业完成 | |
steps: | |
- name: Download artifact | |
# 链接 https://github.com/actions/download-artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
- name: Deploy to gh-pages-deprecated | |
# 链接 https://github.com/crazy-max/ghaction-github-pages/ | |
uses: crazy-max/ghaction-github-pages@v4 | |
with: | |
target_branch: gh-pages-deprecated | |
build_dir: dist | |
keep_history: false | |
# fqdn: xxx | |
allow_empty_commit: false | |
env: | |
GITHUB_TOKEN: ${{ secrets.PERSONAL_ACCESS_TOKEN }} | |
deploy-to-my-server: | |
name: Deploy to My Server | |
runs-on: ubuntu-latest | |
needs: build | |
steps: | |
- name: Download artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dist | |
path: dist | |
- name: Deploy to My Own Server | |
# 链接 https://github.com/easingthemes/ssh-deploy | |
uses: easingthemes/[email protected] | |
env: | |
SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} | |
ARGS: "-avzr --times --update --delete" | |
SOURCE: "dist/" | |
REMOTE_HOST: ${{ secrets.REMOTE_HOST }} | |
REMOTE_USER: ${{ secrets.REMOTE_USER }} | |
TARGET: ${{ secrets.TARGET }} |