conocimientocicd-architecttemplates/9891 B
cd.fase2.dotnet.yml.template
Fichero que /hv:cicd-architect usa o materializa en el proyecto. Se muestra tal cual está en el plugin.
# =============================================================================
# {{PROYECTO_NOMBRE}} — Workflow CD {{PIPELINE_NAME}} (Fase 2 completa, stack .NET, entrypoint {{SLUG}})
# Ovillo cicd-architect github-dotnet @ {{TEMPLATE_STAMP}} (sello de plantilla; /cicd-status detecta drift)
# Reglas: cicd-runtime G1-G19. G1 = el gate es `environment:` + workflow_dispatch (on-demand); G4 = deploy sin
# checkout; G8 = verdict-file; G9 = rollback; G14 = smoke; G15/G16/G18/G19 = permisos, pin SHA, OIDC, concurrency.
# Materializado por /cicd-init en .github/workflows/cd-{{SLUG}}.yml (uno por entrypoint desplegable, R25).
# Requiere: .github/workflows/_reusable-dotnet-build.yml y .github/actions/{security-scan,security-gate,quality-sync}.
#
# MODELO DE DEPLOY (P2-bis). Este template trae ON-DEMAND (default, G1):
# - push a la rama base => solo `build` (construye y publica el artefacto; NINGUN deploy)
# - Actions > Run workflow (o `gh workflow run cd-{{SLUG}}.yml -f environment=<dev|pre|pro>`) => build + ese deploy
# - pre y pro llevan ademas reviewers en su environment (FASE 2.5-gh): doble gate.
# Modelo AUTO: en deploy-dev cambiar el `if:` por github.event_name == 'push' (DEV en cada push; pre/pro on-demand).
# Modelo BRANCH-GATED (gitlab-flow/gitflow): anadir a cada `if:` && github.ref == 'refs/heads/<rama del entorno>'
# y en `on.push.branches` incluir ambas ramas ({{TRIGGER_BRANCHES_EXTRA}}).
#
# RAMAS CONDICIONALES que /cicd-init aplica al generar:
# (a) SIN proyecto de test -> pasar test-filter/runsettings vacios al reusable y quitar `quality-sync`.
# (b) SIN endpoint /health -> sustituir el smoke estricto por el best-effort (ver cd.fase2.vue.yml.template).
# (c) SIN Hub (hub.enabled=false) -> quitar el step `Publish quality record`.
# (d) SIN OIDC (destino iis-selfhosted/custom) -> quitar `id-token: write` de los jobs de deploy.
# (e) `# {{DEPLOY_STEP}}` -> sustituir el step Deploy por el del destino elegido en P3-gh.
#
# ROLLBACK (G9) en GitHub Actions: (1) el step Deploy hace backup en el destino antes de copiar;
# (2) re-ejecutar con el commit anterior: gh workflow run cd-{{SLUG}}.yml --ref <sha_anterior> -f environment=<env>;
# (3) manual segun ops/cicd/RUNBOOK.md.
# =============================================================================
name: CD {{PIPELINE_NAME}}
on:
push:
branches:
- '{{RAMA_BASE}}'
# {{TRIGGER_BRANCHES_EXTRA}} <- /cicd-init anade aqui "- 'develop'" en el modelo branch-gated
paths:
- '{{ENTRYPOINT_PATH}}/**'
- 'ops/**'
- '.github/workflows/cd-{{SLUG}}.yml'
- '.github/workflows/_reusable-dotnet-build.yml'
- '.github/actions/**'
workflow_dispatch:
inputs:
environment:
description: 'Entorno a desplegar (G1 on-demand: el push solo construye)'
type: choice
required: true
options: [dev, pre, pro]
permissions:
contents: read
concurrency:
group: cd-{{SLUG}}-${{ github.ref }}
cancel-in-progress: false # G19: un deploy cancelado a medias deja el entorno roto
jobs:
build:
name: Build
uses: ./.github/workflows/_reusable-dotnet-build.yml
with:
solution-path: '{{SLN_PATH}}'
dotnet-version: '{{NET_VERSION}}'
test-filter: '{{TEST_FILTER}}'
api-project: '{{API_CSPROJ}}'
artifact-name: publish-{{SLUG}}
runner: '{{RUNNER}}'
quality:
name: Quality record
runs-on: '{{RUNNER}}'
needs: build
if: always() && needs.build.result != 'cancelled'
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
- name: Download coverage
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: coverage-${{ github.run_number }}
path: TestResults
continue-on-error: true
- name: Publish quality record
# Rama condicional (c): sin Hub, /cicd-init elimina este job. Best-effort: nunca tumba el workflow.
uses: ./.github/actions/quality-sync
with:
project-id: ${{ vars.HUB_PROJECT_ID }}
hub-server-url: '{{HUB_SERVER_URL}}'
hub-service-key: ${{ secrets.HUB_SERVICE_KEY }}
results-dir: TestResults
code-search-base: 'https://github.com/${{ github.repository }}/search?q='
deploy-dev:
name: Deploy dev
runs-on: '{{RUNNER}}'
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.environment == 'dev'
timeout-minutes: 20
environment:
name: dev
url: '{{DEV_URL}}'
permissions:
contents: read
id-token: write # G18: OIDC hacia la nube; quitar si el destino no lo usa
steps:
- name: Checkout (solo .github/actions)
# Las composite actions locales exigen el repo en disco; sparse checkout de .github/actions para no romper G4:
# el codigo NO se despliega desde el checkout, la unica fuente del deploy es el artefacto descargado.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/actions
- name: Download artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: publish-{{SLUG}}-${{ github.sha }}
path: ./publish
- name: Security gate (G8, warn)
uses: ./.github/actions/security-gate
with:
mode: warn
gate-severity: High
# {{DEPLOY_STEP}} — /cicd-init sustituye el step Deploy por el del destino (P3-gh): azure-webapp | iis-selfhosted | container | custom
- name: Deploy
run: |
echo "::error::Paso de despliegue sin configurar para dev (sustituir {{DEPLOY_STEP}} en /cicd-init)"
exit 1
- name: Smoke test (G14, estricto)
shell: bash
run: |
for i in 1 2 3 4 5 6; do
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "{{DEV_URL}}/health/live" || true)
[ "$code" = "200" ] && { echo "health/live OK"; exit 0; }
echo "intento $i: HTTP $code"; sleep 10
done
echo "::error::Smoke test fallido contra {{DEV_URL}}/health/live"; exit 1
deploy-pre:
name: Deploy pre
runs-on: '{{RUNNER}}'
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.environment == 'pre'
timeout-minutes: 20
environment:
name: pre
url: '{{DEMO_URL}}'
permissions:
contents: read
id-token: write
steps:
- name: Checkout (solo .github/actions)
# Las composite actions locales exigen el repo en disco; sparse checkout de .github/actions para no romper G4:
# el codigo NO se despliega desde el checkout, la unica fuente del deploy es el artefacto descargado.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/actions
- name: Download artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: publish-{{SLUG}}-${{ github.sha }}
path: ./publish
- name: Security gate (G8, block)
uses: ./.github/actions/security-gate
with:
mode: block
gate-severity: High
# {{DEPLOY_STEP}}
- name: Deploy
run: |
echo "::error::Paso de despliegue sin configurar para pre (sustituir {{DEPLOY_STEP}} en /cicd-init)"
exit 1
- name: Smoke test (G14, estricto)
shell: bash
run: |
for i in 1 2 3 4 5 6; do
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "{{DEMO_URL}}/health/live" || true)
[ "$code" = "200" ] && { echo "health/live OK"; exit 0; }
echo "intento $i: HTTP $code"; sleep 10
done
echo "::error::Smoke test fallido contra {{DEMO_URL}}/health/live"; exit 1
deploy-pro:
name: Deploy pro
runs-on: '{{RUNNER}}'
needs: build
if: github.event_name == 'workflow_dispatch' && inputs.environment == 'pro'
timeout-minutes: 30
environment:
name: pro
url: '{{PROD_URL}}'
permissions:
contents: read
id-token: write
steps:
- name: Checkout (solo .github/actions)
# Las composite actions locales exigen el repo en disco; sparse checkout de .github/actions para no romper G4:
# el codigo NO se despliega desde el checkout, la unica fuente del deploy es el artefacto descargado.
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
sparse-checkout: .github/actions
- name: Download artifact
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: publish-{{SLUG}}-${{ github.sha }}
path: ./publish
- name: Security gate (G8, block)
uses: ./.github/actions/security-gate
with:
mode: block
gate-severity: High
# {{DEPLOY_STEP}} — en pro el step debe hacer backup previo (G9 capa 1) y desplegar nodo a nodo si hay varios
- name: Deploy
run: |
echo "::error::Paso de despliegue sin configurar para pro (sustituir {{DEPLOY_STEP}} en /cicd-init)"
exit 1
- name: Smoke test (G14, estricto)
shell: bash
run: |
for i in 1 2 3 4 5 6; do
code=$(curl -s -o /dev/null -w '%{http_code}' --max-time 10 "{{PROD_URL}}/health/live" || true)
[ "$code" = "200" ] && { echo "health/live OK"; exit 0; }
echo "intento $i: HTTP $code"; sleep 10
done
echo "::error::Smoke test fallido contra {{PROD_URL}}/health/live. Rollback: gh workflow run cd-{{SLUG}}.yml --ref <sha_anterior> -f environment=pro"; exit 1