From 236b87d86297f28ec1e87bc0820e3a1e8ccc6376 Mon Sep 17 00:00:00 2001 From: Xu-create-ops Date: Sat, 14 Jun 2025 16:39:07 +0800 Subject: [PATCH] update --- .github/workflows/azure-back-end-03b2a610f.yml | 18 +++++++----------- ...re-static-web-apps-green-moss-03b2a610f.yml | 16 +++++++++------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/.github/workflows/azure-back-end-03b2a610f.yml b/.github/workflows/azure-back-end-03b2a610f.yml index d72b3b9..5dd7a58 100644 --- a/.github/workflows/azure-back-end-03b2a610f.yml +++ b/.github/workflows/azure-back-end-03b2a610f.yml @@ -1,15 +1,10 @@ name: CI/CD for .NET app to Azure on: - # ✅ PR 到 main:只执行 CI pull_request: branches: ['main'] - - # ✅ 合并 PR 到 main:自动部署到 Test push: branches: ['main'] - - # ✅ 手动触发部署 workflow_dispatch: inputs: environment: @@ -26,8 +21,7 @@ env: jobs: ci-check: - # ✅ 只在 PR 阶段执行 - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' runs-on: windows-latest steps: - name: Checkout code @@ -45,10 +39,12 @@ jobs: run: dotnet build ./dev-share-api/dev-share-api.csproj --configuration Release --no-restore deploy: - # ✅ 仅在 main 合并 或 workflow_dispatch 时执行 if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' runs-on: windows-latest + env: + DEPLOY_ENV: ${{ github.event.inputs.environment || 'Test' }} + steps: - name: Checkout code uses: actions/checkout@v4 @@ -66,14 +62,14 @@ jobs: - name: Publish run: | - $envName = if ("${{ github.event.inputs.environment }}" -eq "Production") { "Production" } else { "Test" } + $envName = "${{ env.DEPLOY_ENV }}" dotnet publish ./dev-share-api/dev-share-api.csproj ` --configuration Release ` --output ./publish ` -p:EnvironmentName=$envName - name: Deploy to Azure Web App - Production - if: github.event.inputs.environment == 'Production' + if: env.DEPLOY_ENV == 'Production' uses: azure/webapps-deploy@v3 with: app-name: prod-share-app @@ -81,7 +77,7 @@ jobs: package: ./publish - name: Deploy to Azure Web App - Test - if: github.event.inputs.environment != 'Production' + if: env.DEPLOY_ENV != 'Production' uses: azure/webapps-deploy@v3 with: app-name: dev-share diff --git a/.github/workflows/azure-static-web-apps-green-moss-03b2a610f.yml b/.github/workflows/azure-static-web-apps-green-moss-03b2a610f.yml index faa224e..e7d2ab8 100644 --- a/.github/workflows/azure-static-web-apps-green-moss-03b2a610f.yml +++ b/.github/workflows/azure-static-web-apps-green-moss-03b2a610f.yml @@ -3,10 +3,8 @@ name: CI/CD for Next.js app to Azure Web App on: pull_request: branches: ['main'] - push: branches: ['main'] - workflow_dispatch: inputs: environment: @@ -23,7 +21,7 @@ env: jobs: ci-check: - if: github.event_name == 'pull_request' + if: github.event_name == 'pull_request' || github.ref == 'refs/heads/main' runs-on: ubuntu-latest steps: - name: Checkout code @@ -34,7 +32,7 @@ jobs: with: node-version: ${{ env.NODE_VERSION }} - - name: Install & Build (CI only) + - name: Install & Build (CI) run: | npm install npm run build @@ -43,6 +41,10 @@ jobs: deploy: if: github.event_name == 'push' || github.event_name == 'workflow_dispatch' runs-on: ubuntu-latest + + env: + DEPLOY_ENV: ${{ github.event.inputs.environment || 'Test' }} + steps: - name: Checkout code uses: actions/checkout@v4 @@ -55,7 +57,7 @@ jobs: - name: Copy correct .env file run: | envFile=".env.test" - if [[ "${{ github.event.inputs.environment }}" == "Production" ]]; then + if [[ "${{ env.DEPLOY_ENV }}" == "Production" ]]; then envFile=".env.production" fi cp ./dev-share-ui/$envFile ./dev-share-ui/.env @@ -73,7 +75,7 @@ jobs: if [ -d "public" ]; then cp -r public .next/standalone/; fi - name: Deploy to Azure Web App - Production - if: github.event.inputs.environment == 'Production' + if: env.DEPLOY_ENV == 'Production' uses: azure/webapps-deploy@v3 with: app-name: prod-share-ui @@ -81,7 +83,7 @@ jobs: package: dev-share-ui/.next/standalone - name: Deploy to Azure Web App - Test - if: github.event.inputs.environment != 'Production' + if: env.DEPLOY_ENV != 'Production' uses: azure/webapps-deploy@v3 with: app-name: dev-share-ui-v1