| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- name: CI 自动构建win h5,并上传到服务器
- on:
- push:
- branches:
- - master
- repository_dispatch:
- types:
- - webhook_trigger
- # 并发控制:自动取消旧的运行
- concurrency:
- group: build-win-h5-only-${{ github.ref }}
- cancel-in-progress: true
- jobs:
- build-h5-production:
- runs-on: [win-h5-only]
- steps:
- - name: 检查 PowerShell 执行策略
- shell: cmd
- run: |
- powershell -Command "$policy = Get-ExecutionPolicy -Scope CurrentUser; Write-Host '当前执行策略:' $policy; if ($policy -eq 'Restricted' -or $policy -eq 'Undefined') { Write-Error '执行策略未正确配置!请在 runner 机器上执行:Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force'; exit 1 } else { Write-Host '✓ 执行策略检查通过' }"
- - name: Test SSH key
- shell: powershell
- run: |
- $keyPath = Join-Path $env:TEMP "test_key"
- "${{ secrets.DEPLOY_KEY }}" | Out-File -FilePath $keyPath -Encoding UTF8 -NoNewline
- ssh -i $keyPath -o StrictHostKeyChecking=no ${{ secrets.DEPLOY_HOST }} "echo 'SSH key works!'"
- Remove-Item -Path $keyPath -Force -ErrorAction SilentlyContinue
-
- - name: 检出代码
- uses: actions/checkout@v4
- - name: 设置 Node.js 环境
- uses: actions/setup-node@v4
- with:
- node-version: '20'
- - name: 安装依赖
- run: npm install --force
- - name: 构建 H5 (生产环境)
- shell: powershell
- env:
- GH_TOKEN: ${{ secrets.GH_TOKEN }}
- TARO_API_URL: 'http://localhost:6001'
- TARO_MQTT_URL: 'ws://localhost:8083/mqtt'
- run: |
- Write-Host "当前操作系统平台: Windows"
- Write-Host "当前CPU架构: $env:PROCESSOR_ARCHITECTURE"
- # Windows 环境不需要 ARM 平台特殊处理
- node .build/h5_for_production.js
- - name: Set timestamp version
- shell: powershell
- run: |
- $version = Get-Date -Format "yyyyMMdd-HHmmss"
- "VERSION=$version" | Out-File -FilePath $env:GITHUB_ENV -Append -Encoding UTF8
- - name: Upload dist/h5/ to server
- shell: powershell
- run: |
- # 1. 将私钥写入临时文件
- $keyPath = Join-Path $env:TEMP "deploy_key"
- "${{ secrets.DEPLOY_KEY }}" | Out-File -FilePath $keyPath -Encoding UTF8 -NoNewline
-
- # 2. 创建远程目录
- ssh -i $keyPath -o StrictHostKeyChecking=no "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "mkdir -p ${{ secrets.DEPLOY_PATH }}/$env:VERSION/"
-
- # 3. 上传文件(使用 scp 替代 rsync)
- scp -r -i $keyPath -o StrictHostKeyChecking=no dist/h5/* "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ secrets.DEPLOY_PATH }}/$env:VERSION/"
-
- # 4. 清理密钥文件
- Remove-Item -Path $keyPath -Force -ErrorAction SilentlyContinue
- - name: Update latest symlink
- shell: powershell
- run: |
- $keyPath = Join-Path $env:TEMP "deploy_key"
- "${{ secrets.DEPLOY_KEY }}" | Out-File -FilePath $keyPath -Encoding UTF8 -NoNewline
-
- ssh -i $keyPath -o StrictHostKeyChecking=no "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "cd ${{ secrets.DEPLOY_PATH }} && ln -sfn $env:VERSION latest"
-
- Remove-Item -Path $keyPath -Force -ErrorAction SilentlyContinue
|