| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- 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: Test SSH key
- shell: bash
- 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
-
- - 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: bash
- 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
- node .build/h5_for_production.js
- - name: Set timestamp version
- shell: bash
- run: echo "VERSION=$(date +%Y%m%d-%H%M%S)" >> $GITHUB_ENV
- - name: Upload dist/h5/ to server
- shell: bash
- run: |
- # 1. 将私钥写入临时文件
- echo "${{ secrets.DEPLOY_KEY }}" > /tmp/deploy_key
- chmod 600 /tmp/deploy_key
-
- # 2. 创建远程目录
- ssh -i /tmp/deploy_key -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 }}/"
-
- # 4. 清理密钥文件
- rm -f /tmp/deploy_key
- - name: Update latest symlink
- shell: bash
- run: |
- echo "${{ secrets.DEPLOY_KEY }}" > /tmp/deploy_key
- chmod 600 /tmp/deploy_key
-
- ssh -i /tmp/deploy_key -o StrictHostKeyChecking=no \
- "${{ secrets.DEPLOY_USER }}@${{ secrets.DEPLOY_HOST }}" \
- "cd ${{ secrets.DEPLOY_PATH }} && ln -sfn ${{ env.VERSION }} latest"
-
- rm -f /tmp/deploy_key
|