name: "多环境发布" on: workflow_dispatch: inputs: environment: description: "部署环境" required: true default: "staging" type: choice options: - staging - production - testing version_type: description: "版本类型" required: true default: "patch" type: choice options: - patch - minor - major custom_tags: description: "自定义标签(每行一个)" required: false default: "" jobs: release: runs-on: ubuntu-latest name: "发布到 ${{ github.event.inputs.environment }} 环境" strategy: matrix: include: - environment: staging app_env: "staging" namespace: "staging" - environment: production app_env: "production" namespace: "production" - environment: testing app_env: "testing" namespace: "testing" steps: - name: 检出代码 uses: actions/checkout@v4 with: fetch-depth: 0 token: ${{ secrets.GITEA_TOKEN }} - name: 设置构建环境 uses: actions/xgj/setup-env@main with: kube-config: ${{ secrets.KUBE_CONFIG }} - name: 安装依赖 uses: actions/xgj/npm-install@main with: package-manager: "pnpm" - name: 发布构建 id: release uses: actions/xgj/release-web@main with: release-command: "npm run release -- --release -V --increment ${{ github.event.inputs.version_type }}" env: GITEA_TOKEN: ${{ secrets.GITEA_TOKEN }} APP_ENV: ${{ matrix.app_env }} - name: 部署应用 run: | ENVIRONMENT="${{ github.event.inputs.environment }}" VERSION="${{ steps.release.outputs.version }}" NAMESPACE="${{ matrix.namespace }}" echo "🚀 部署到 ${ENVIRONMENT} 环境..." echo "📦 版本: ${VERSION}" echo "📍 命名空间: ${NAMESPACE}" # 这里可以根据实际情况部署应用 # 例如通过配置文件更新、API调用等方式 echo "✅ 部署完成!" - name: 发布总结 run: | echo "🎉 多环境发布完成!" echo "" echo "📋 发布信息:" echo " - 环境: ${{ github.event.inputs.environment }}" echo " - 版本: ${{ steps.release.outputs.version }}" echo " - 版本类型: ${{ github.event.inputs.version_type }}" echo " - 命名空间: ${{ matrix.namespace }}"