This commit is contained in:
97
.github/workflows/deploy.yml
vendored
97
.github/workflows/deploy.yml
vendored
@@ -1,46 +1,83 @@
|
||||
name: Debug-Deploy-Workflow
|
||||
name: Pro-CI-CD-Pipeline
|
||||
|
||||
on:
|
||||
push:
|
||||
tags:
|
||||
- "v*"
|
||||
- "v*" # Only triggered when pushing a tag starting with v (for example v1.1.0)
|
||||
|
||||
jobs:
|
||||
deploy-job:
|
||||
runs-on: windows
|
||||
|
||||
build-and-deploy:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: 1. 检查代码检出
|
||||
# 1. Checkout code
|
||||
- name: Checkout Code
|
||||
uses: actions/checkout@v4
|
||||
|
||||
# 2. Install pnpm (Node >= 20)
|
||||
- name: Install pnpm
|
||||
uses: pnpm/action-setup@v2
|
||||
with:
|
||||
fetch-depth: 0
|
||||
version: 8 # Alternatively use latest
|
||||
|
||||
- name: 2. 打印环境信息
|
||||
# 强制使用 powershell 并且设置编码为 UTF8
|
||||
shell: powershell
|
||||
run: |
|
||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
chcp 65001
|
||||
Write-Host "Current Directory: $PWD"
|
||||
node -v
|
||||
pnpm -v
|
||||
Write-Host "Current Tag/Branch: ${{ github.ref_name }}"
|
||||
- name: Set Up Node.js
|
||||
uses: actions/setup-node@v4
|
||||
with:
|
||||
node-version: 20
|
||||
cache: "pnpm"
|
||||
|
||||
- name: 3. 安装依赖
|
||||
shell: powershell
|
||||
# 3. Install dependencies and build the project
|
||||
- name: Install Dependencies and Build
|
||||
run: |
|
||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
chcp 65001
|
||||
pnpm install --prefer-offline
|
||||
|
||||
- name: 4. 执行部署脚本
|
||||
shell: powershell
|
||||
run: |
|
||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
chcp 65001
|
||||
node deploy.js
|
||||
pnpm install
|
||||
pnpm run build
|
||||
env:
|
||||
# Inject Sentry init environment variables to UmiJS (Ant Design Pro)
|
||||
UMI_APP_SENTRY_RELEASE: ${{ github.ref_name }}
|
||||
UMI_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||
|
||||
# 4. Upload SourceMaps to GlitchTip
|
||||
- name: Upload SourceMaps to GlitchTip
|
||||
uses: getsentry/action-release@v1
|
||||
env:
|
||||
SENTRY_URL: ${{ secrets.GLITCHTIP_URL }}
|
||||
SENTRY_AUTH_TOKEN: ${{ secrets.GLITCHTIP_TOKEN }}
|
||||
SENTRY_URL: ${{ secrets.GLITCHTIP_URL }}
|
||||
SENTRY_ORG: ${{ secrets.GLITCHTIP_ORG }}
|
||||
SENTRY_PROJECT: ${{ secrets.GLITCHTIP_PROJECT }}
|
||||
with:
|
||||
version: ${{ github.ref_name }}
|
||||
sourcemaps: "./dist"
|
||||
url_prefix: "~/" # Match online deployed JS paths
|
||||
|
||||
# 5. Clean up local source maps after deployment
|
||||
- name: Clean SourceMaps
|
||||
run: find dist -name "*.map" -type f -delete
|
||||
|
||||
# 6. Install SSH key
|
||||
- name: Install SSH Key
|
||||
uses: shimataro/ssh-key-action@v2
|
||||
with:
|
||||
key: ${{ secrets.SERVER_SSH_KEY }}
|
||||
known_hosts: unnecessary # Automatically confirm first connection
|
||||
if_key_exists: replace
|
||||
|
||||
# 7. Deploy to server with atomic switch (Atomic Deployment)
|
||||
- name: Deploy to Server
|
||||
run: |
|
||||
VERSION=${{ github.ref_name }}
|
||||
REMOTE_BASE=${{ secrets.REMOTE_PATH }}
|
||||
RELEASES_PATH="$REMOTE_BASE/releases/$VERSION"
|
||||
CURRENT_PATH="$REMOTE_BASE/current"
|
||||
|
||||
echo ">>> Creating remote directory: $RELEASES_PATH"
|
||||
ssh -o StrictHostKeyChecking=no ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} "mkdir -p $RELEASES_PATH"
|
||||
|
||||
echo ">>> Uploading build artifacts (rsync)..."
|
||||
# Use rsync to sync dist directory to server releases version directory
|
||||
rsync -avz --delete ./dist/ ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }}:$RELEASES_PATH
|
||||
|
||||
echo ">>> Updating server soft link (ln -snf)..."
|
||||
# Atomic switch soft link
|
||||
ssh ${{ secrets.SERVER_USER }}@${{ secrets.SERVER_HOST }} "ln -snf $RELEASES_PATH $CURRENT_PATH"
|
||||
|
||||
- name: Success Notification
|
||||
run: echo "🎉 Version ${{ github.ref_name }} successfully deployed to ${{ secrets.SERVER_HOST }}"
|
||||
|
||||
Reference in New Issue
Block a user