|
|
@@ -17,13 +17,17 @@ jobs:
|
|
|
build-h5-production:
|
|
|
runs-on: [win-h5-only]
|
|
|
steps:
|
|
|
+ - name: 设置 PowerShell 执行策略
|
|
|
+ shell: powershell
|
|
|
+ run: Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force
|
|
|
+
|
|
|
- name: Test SSH key
|
|
|
- shell: bash
|
|
|
+ shell: powershell
|
|
|
run: |
|
|
|
- echo "${{ secrets.DEPLOY_KEY }}" > /tmp/test_key
|
|
|
- chmod 600 /tmp/test_key
|
|
|
- ssh -i /tmp/test_key -o StrictHostKeyChecking=no deploy@${{ secrets.DEPLOY_HOST }} "echo 'SSH key works!'"
|
|
|
- rm /tmp/test_key
|
|
|
+ $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
|
|
|
@@ -37,53 +41,45 @@ jobs:
|
|
|
run: npm install --force
|
|
|
|
|
|
- name: 构建 H5 (生产环境)
|
|
|
- shell: bash
|
|
|
+ shell: powershell
|
|
|
env:
|
|
|
GH_TOKEN: ${{ secrets.GH_TOKEN }}
|
|
|
TARO_API_URL: 'http://localhost:6001'
|
|
|
TARO_MQTT_URL: 'ws://localhost:8083/mqtt'
|
|
|
run: |
|
|
|
- echo "当前操作系统平台: $(uname -s)"
|
|
|
- echo "当前CPU架构: $(uname -m)"
|
|
|
- if [ "$(uname -s)" = "Linux" ] && [ "$(uname -m)" = "aarch64" ]; then
|
|
|
- echo "复制arm平台必须构建文件taro.linux-arm64-gnu.node到目标位置"
|
|
|
- cp .build/taro.linux-arm64-gnu.node node_modules/@tarojs/binding/taro.linux-arm64-gnu.node
|
|
|
- echo "复制完成"
|
|
|
- fi
|
|
|
+ Write-Host "当前操作系统平台: Windows"
|
|
|
+ Write-Host "当前CPU架构: $env:PROCESSOR_ARCHITECTURE"
|
|
|
+ # Windows 环境不需要 ARM 平台特殊处理
|
|
|
node .build/h5_for_production.js
|
|
|
|
|
|
- name: Set timestamp version
|
|
|
- shell: bash
|
|
|
- run: echo "VERSION=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
|
|
|
+ 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: bash
|
|
|
+ shell: powershell
|
|
|
run: |
|
|
|
# 1. 将私钥写入临时文件
|
|
|
- echo "${{ secrets.DEPLOY_KEY }}" > /tmp/deploy_key
|
|
|
- chmod 600 /tmp/deploy_key
|
|
|
+ $keyPath = Join-Path $env:TEMP "deploy_key"
|
|
|
+ "${{ secrets.DEPLOY_KEY }}" | Out-File -FilePath $keyPath -Encoding UTF8 -NoNewline
|
|
|
|
|
|
# 2. 创建远程目录
|
|
|
- ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no \
|
|
|
- "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
|
|
|
- "mkdir -p ${{ secrets.DEPLOY_PATH }}/${{ env.VERSION }}/"
|
|
|
+ ssh -i $keyPath -o StrictHostKeyChecking=no "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "mkdir -p ${{ secrets.DEPLOY_PATH }}/$env:VERSION/"
|
|
|
|
|
|
- # 3. 上传文件(不删除本地)
|
|
|
- rsync -avz -e "ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no" \
|
|
|
- dist/h5/ \
|
|
|
- "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}:${{ 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. 清理密钥文件
|
|
|
- rm -f /tmp/deploy_key
|
|
|
+ Remove-Item -Path $keyPath -Force -ErrorAction SilentlyContinue
|
|
|
|
|
|
- name: Update latest symlink
|
|
|
- shell: bash
|
|
|
+ shell: powershell
|
|
|
run: |
|
|
|
- echo "${{ secrets.DEPLOY_KEY }}" > /tmp/deploy_key
|
|
|
- chmod 600 /tmp/deploy_key
|
|
|
+ $keyPath = Join-Path $env:TEMP "deploy_key"
|
|
|
+ "${{ secrets.DEPLOY_KEY }}" | Out-File -FilePath $keyPath -Encoding UTF8 -NoNewline
|
|
|
|
|
|
- ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no \
|
|
|
- "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
|
|
|
- "cd ${{ secrets.DEPLOY_PATH }} && ln -sfn ${{ env.VERSION }} latest"
|
|
|
+ ssh -i $keyPath -o StrictHostKeyChecking=no "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" "cd ${{ secrets.DEPLOY_PATH }} && ln -sfn $env:VERSION latest"
|
|
|
|
|
|
- rm -f /tmp/deploy_key
|
|
|
+ Remove-Item -Path $keyPath -Force -ErrorAction SilentlyContinue
|