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:
|
on:
|
||||||
push:
|
push:
|
||||||
tags:
|
tags:
|
||||||
- "v*"
|
- "v*" # Only triggered when pushing a tag starting with v (for example v1.1.0)
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy-job:
|
build-and-deploy:
|
||||||
runs-on: windows
|
runs-on: ubuntu-latest
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: 1. 检查代码检出
|
# 1. Checkout code
|
||||||
|
- name: Checkout Code
|
||||||
uses: actions/checkout@v4
|
uses: actions/checkout@v4
|
||||||
|
|
||||||
|
# 2. Install pnpm (Node >= 20)
|
||||||
|
- name: Install pnpm
|
||||||
|
uses: pnpm/action-setup@v2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
version: 8 # Alternatively use latest
|
||||||
|
|
||||||
- name: 2. 打印环境信息
|
- name: Set Up Node.js
|
||||||
# 强制使用 powershell 并且设置编码为 UTF8
|
uses: actions/setup-node@v4
|
||||||
shell: powershell
|
with:
|
||||||
run: |
|
node-version: 20
|
||||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
cache: "pnpm"
|
||||||
chcp 65001
|
|
||||||
Write-Host "Current Directory: $PWD"
|
|
||||||
node -v
|
|
||||||
pnpm -v
|
|
||||||
Write-Host "Current Tag/Branch: ${{ github.ref_name }}"
|
|
||||||
|
|
||||||
- name: 3. 安装依赖
|
# 3. Install dependencies and build the project
|
||||||
shell: powershell
|
- name: Install Dependencies and Build
|
||||||
run: |
|
run: |
|
||||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
pnpm install
|
||||||
chcp 65001
|
pnpm run build
|
||||||
pnpm install --prefer-offline
|
env:
|
||||||
|
# Inject Sentry init environment variables to UmiJS (Ant Design Pro)
|
||||||
- name: 4. 执行部署脚本
|
UMI_APP_SENTRY_RELEASE: ${{ github.ref_name }}
|
||||||
shell: powershell
|
UMI_APP_SENTRY_DSN: ${{ secrets.SENTRY_DSN }}
|
||||||
run: |
|
|
||||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
# 4. Upload SourceMaps to GlitchTip
|
||||||
chcp 65001
|
- name: Upload SourceMaps to GlitchTip
|
||||||
node deploy.js
|
uses: getsentry/action-release@v1
|
||||||
env:
|
env:
|
||||||
SENTRY_URL: ${{ secrets.GLITCHTIP_URL }}
|
|
||||||
SENTRY_AUTH_TOKEN: ${{ secrets.GLITCHTIP_TOKEN }}
|
SENTRY_AUTH_TOKEN: ${{ secrets.GLITCHTIP_TOKEN }}
|
||||||
|
SENTRY_URL: ${{ secrets.GLITCHTIP_URL }}
|
||||||
SENTRY_ORG: ${{ secrets.GLITCHTIP_ORG }}
|
SENTRY_ORG: ${{ secrets.GLITCHTIP_ORG }}
|
||||||
SENTRY_PROJECT: ${{ secrets.GLITCHTIP_PROJECT }}
|
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 }}"
|
||||||
|
|||||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -11,6 +11,7 @@ _roadhog-api-doc
|
|||||||
*.map
|
*.map
|
||||||
.sentryclirc
|
.sentryclirc
|
||||||
sentry-cli.log
|
sentry-cli.log
|
||||||
|
deploy.js
|
||||||
|
|
||||||
# misc
|
# misc
|
||||||
.env
|
.env
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ if (process.env.UMI_APP_SENTRY_DSN) {
|
|||||||
// Print the version number only in the production environment
|
// Print the version number only in the production environment
|
||||||
if (process.env.NODE_ENV === 'production') {
|
if (process.env.NODE_ENV === 'production') {
|
||||||
console.log(
|
console.log(
|
||||||
`%c Current Version: ${process.env.UMI_APP_SHORT_RELEASE || 'N/A'} `,
|
`%c Current Version: ${process.env.UMI_APP_SENTRY_RELEASE || 'N/A'} `,
|
||||||
'background: #1e88e5; color: #fff; padding: 2px 5px; border-radius: 3px;',
|
'background: #1e88e5; color: #fff; padding: 2px 5px; border-radius: 3px;',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user