1
0
mirror of https://github.com/142vip/408CSFamily.git synced 2026-02-03 02:23:38 +08:00
Files
408CSFamily/.github/workflows/CD.yaml

180 lines
5.3 KiB
YAML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## CD交付流水线
## - 部署到Github Pages
## - 部署到Vercel托管平台
## - 发布新的Github Release
## 参考资料https://v2.vuepress.vuejs.org/zh/guide/deployment.html#github-pages
name: CD
on:
push:
branches:
- next
workflow_dispatch:
## vercel 环境变量
env:
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }}
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }}
jobs:
## 部署到Github-Pages
deploy-github:
name: "部署到Github-Pages"
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
# 安装PNPM
- name: PNPM Install
uses: pnpm/action-setup@v4
with:
version: 9.6.0
# 安装Node环境
- name: Install Node.js
uses: actions/setup-node@v4
with:
node-version: 20.16.0
# 缓存
cache: pnpm
- name: Install Dependencies
run: |
./scripts/ci
# 编译 打包成dist
- name: Build with VitePress
run: pnpm build:proxy
- name: Upload artifact
uses: actions/upload-pages-artifact@v3
with:
path: docs/.vuepress/dist
# 部署
- name: Deploy to GitHub Pages
id: deployment
uses: actions/deploy-pages@v4
## 部署到vercel平台
deploy-vercel:
name: "部署到Vercel平台"
runs-on: ubuntu-latest
if: github.repository == '142vip/408CSFamily'
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
## 注意: 这里的操作时间vercel平台配置的命令拉取下来执行
- name: Pull Vercel Environment Information
run: npm i -g vercel && vercel pull --yes --environment=production --token=${{ secrets.VERCEL_TOKEN }}
## 执行vercel平台配置的命令
- name: Build Project Artifacts
run: vercel build --prod --token=${{ secrets.VERCEL_TOKEN }}
## dist文件同步到vercel平台
- name: Deploy Project Artifacts to Vercel
run: vercel deploy --prebuilt --prod --token=${{ secrets.VERCEL_TOKEN }}
## 版本发布
release:
name: "Github版本发布"
runs-on: ubuntu-latest
## 主库master、next且执行release更新时执行
if: github.repository == '142vip/408CSFamily' && startsWith(github.event.head_commit.message, 'chore(release):')
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
persist-credentials: false
# “最近更新时间” 等 git 日志相关信息,需要拉取全部提交记录
fetch-depth: 0
### 打成压缩包
- name: Create Zip Package
run: |
zip -r 408CSFamily.zip . \
-x "node_modules/*" \
-x "*.git*"
# 提取版本号
- name: Get New Version Number
id: releaseVersion
run: |
echo "version=$(node -p "require('./package.json').version")" >> $GITHUB_OUTPUT
# 创建发布版本
- name: Create New Release
id: createRelease
uses: actions/create-release@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.releaseVersion.outputs.version }}
release_name: v${{ steps.releaseVersion.outputs.version }}
body: |
Release ${{ steps.releaseVersion.outputs.version }}
### Features
### Bug Fixes
## 更新资源
- name: Upload Resource Assets
uses: actions/upload-release-asset@latest
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.createRelease.outputs.upload_url }}
asset_path: ./408CSFamily.zip
asset_name: 408CSFamily.zip
asset_content_type: application/zip
# Deploy-ESC:
# name: "部署到ESC服务器"
# needs: install-init
# runs-on: ubuntu-latest
# ## 主库master、next且执行release更新时执行
# if: github.repository == '142vip/408CSFamily' && startsWith(github.event.head_commit.message, 'chore(release):')
#
# steps:
# - name: Checkout repository
# uses: actions/checkout@v4
#
# - name: Get Current Version
# id: version
# uses: ashley-taylor/read-json-property-action@v1.0
# with:
# path: ./package.json
# property: version
#
# # 拉取镜像,更新服务
# - name: Pull Image And Update ESC
# uses: appleboy/ssh-action@master
# with:
# host: ${{ secrets.SERVER_HOST }}
# port: ${{ secrets.SERVER_PORT }}
# username: ${{ secrets.SERVER_USERNAME }}
# password: ${{ secrets.SERVER_PASSWORD }}
# script: |
# docker images
# echo "-----------正在运行的服务--------"
# docker ps
# cd /service_env/ && git reset --hard && git pull origin main
# bash ./scripts/book_doc.deploy.sh jsc ${{steps.version.outputs.value}}