From 30ac2eaedefd36c56e994ca6b66629593a2049ec Mon Sep 17 00:00:00 2001 From: Jhonton Chen <504071088@qq.com> Date: Wed, 8 Apr 2026 10:02:22 +0800 Subject: [PATCH] =?UTF-8?q?'=E4=BF=AE=E6=94=B9=E5=88=B0github=E6=B5=81?= =?UTF-8?q?=E7=A8=8B'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/deploy.yml | 97 +++++++++++++++++++++++++----------- .gitignore | 1 + src/utils/sentry.ts | 2 +- 3 files changed, 69 insertions(+), 31 deletions(-) diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index c0a68ee..810c010 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -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 }}" diff --git a/.gitignore b/.gitignore index f8ff976..293035c 100644 --- a/.gitignore +++ b/.gitignore @@ -11,6 +11,7 @@ _roadhog-api-doc *.map .sentryclirc sentry-cli.log +deploy.js # misc .env diff --git a/src/utils/sentry.ts b/src/utils/sentry.ts index 940bc50..da680fd 100644 --- a/src/utils/sentry.ts +++ b/src/utils/sentry.ts @@ -14,7 +14,7 @@ if (process.env.UMI_APP_SENTRY_DSN) { // Print the version number only in the production environment if (process.env.NODE_ENV === 'production') { 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;', ); }