ci(pipeline): split CI and CD stages; remove env from CI jobs

CI jobs no longer carry environment vars and depend only on branches.
Deploy remains environment-aware and runs only on workflow_dispatch.
This commit is contained in:
Haitao Pan 2025-12-04 11:16:30 +08:00
parent 788a518352
commit 64bba74dd1

View File

@ -20,11 +20,12 @@ permissions:
jobs:
# -------------------------------------------------------------
# CI STAGE 1 — Code Quality (environment-independent)
# -------------------------------------------------------------
code-quality:
name: "Code quality • ${{ matrix.service }} @ ${{ matrix.platform }} (${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }})"
name: "Code quality • ${{ matrix.service }} @ ${{ matrix.platform }}"
runs-on: ubuntu-latest
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }}
strategy:
fail-fast: false
matrix:
@ -35,14 +36,14 @@ jobs:
with:
service: ${{ matrix.service }}
platform: ${{ matrix.platform }}
environment: ${{ env.ENVIRONMENT }}
# -------------------------------------------------------------
# CI STAGE 2 — Build
# -------------------------------------------------------------
build:
name: "Build • ${{ matrix.service }} @ ${{ matrix.platform }} (${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }})"
name: "Build • ${{ matrix.service }} @ ${{ matrix.platform }}"
runs-on: ubuntu-latest
needs: code-quality
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }}
strategy:
fail-fast: false
matrix:
@ -53,14 +54,14 @@ jobs:
with:
service: ${{ matrix.service }}
platform: ${{ matrix.platform }}
environment: ${{ env.ENVIRONMENT }}
# -------------------------------------------------------------
# CI STAGE 3 — Test
# -------------------------------------------------------------
test:
name: "Test • ${{ matrix.service }} @ ${{ matrix.platform }} (${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }})"
name: "Test • ${{ matrix.service }} @ ${{ matrix.platform }}"
runs-on: ubuntu-latest
needs: build
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }}
strategy:
fail-fast: false
matrix:
@ -71,14 +72,14 @@ jobs:
with:
service: ${{ matrix.service }}
platform: ${{ matrix.platform }}
environment: ${{ env.ENVIRONMENT }}
# -------------------------------------------------------------
# CI STAGE 4 — Security
# -------------------------------------------------------------
security:
name: "Security • ${{ matrix.service }} @ ${{ matrix.platform }} (${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }})"
name: "Security • ${{ matrix.service }} @ ${{ matrix.platform }}"
runs-on: ubuntu-latest
needs: test
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }}
strategy:
fail-fast: false
matrix:
@ -89,17 +90,17 @@ jobs:
with:
service: ${{ matrix.service }}
platform: ${{ matrix.platform }}
environment: ${{ env.ENVIRONMENT }}
# -------------------------------------------------------------
# CD — Deploy (only with workflow_dispatch)
# -------------------------------------------------------------
deploy:
name: "Deploy • ${{ matrix.service }} (${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }})"
name: "Deploy • ${{ matrix.service }} (${{ github.event.inputs.environment }})"
runs-on: ubuntu-latest
needs: security
if: github.event_name == 'workflow_dispatch'
env:
ENVIRONMENT: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.environment || 'dev' }}
if: >
github.event_name == 'workflow_dispatch' &&
github.event.inputs.environment == 'prod'
ENVIRONMENT: ${{ github.event.inputs.environment }}
strategy:
fail-fast: false
matrix: