conocimientocicd-architecttemplates/3440 B
ci.nettool.yml.template
Fichero que /hv:cicd-architect usa o materializa en el proyecto. Se muestra tal cual está en el plugin.
# =============================================================================
# {{PROYECTO_NOMBRE}} — Workflow .NET-tool / libreria NuGet (Variante C)
# Ovillo cicd-architect github-nettool @ {{TEMPLATE_STAMP}} (sello de plantilla; /cicd-status detecta drift)
# Reglas: cicd-runtime G1-G19. Un solo flujo build+test+pack; el push del paquete SOLO en tags v* (G1: la
# publicacion es el "deploy" y se dispara con /hv:cicd-release, nunca en cada push).
# Materializado por /cicd-init en .github/workflows/publish-nuget.yml
#
# Destino: {{NUGET_SOURCE}}. Con GitHub Packages (https://nuget.pkg.github.com/{{ORG}}/index.json) basta el
# GITHUB_TOKEN con `packages: write`; con NuGet.org u otro feed, el secret NUGET_API_KEY (P4-gh).
# El ruleset de tags (git-best-practices/templates/tag-ruleset.json.template) impide borrar o mover v*.
# =============================================================================
name: NuGet {{PIPELINE_NAME}}
on:
push:
branches: ['{{RAMA_BASE}}']
tags: ['v*']
pull_request:
branches: ['{{RAMA_BASE}}']
merge_group:
branches: ['{{RAMA_BASE}}']
permissions:
contents: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ !startsWith(github.ref, 'refs/tags/') }}
env:
DOTNET_VERSION: '{{NET_VERSION}}'
SOLUTION_PATH: '{{SLN_PATH}}'
PACK_PROJECT: '{{PACK_CSPROJ_PATH}}'
jobs:
build:
name: Build
runs-on: '{{RUNNER}}'
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0 # la version del paquete puede derivar del tag (MinVer, Nerdbank.GitVersioning)
- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Restore
run: dotnet restore "${{ env.SOLUTION_PATH }}"
- name: Build
run: dotnet build "${{ env.SOLUTION_PATH }}" --no-restore --configuration Release
- name: Test
run: dotnet test "${{ env.SOLUTION_PATH }}" --no-build --configuration Release
- name: Pack
run: dotnet pack "${{ env.PACK_PROJECT }}" --no-build --configuration Release --output ./nupkg
- name: Upload nupkg
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
with:
name: nupkg-${{ github.sha }}
path: ./nupkg/*.nupkg
retention-days: 30
publish:
name: Publish
runs-on: '{{RUNNER}}'
needs: build
if: startsWith(github.ref, 'refs/tags/v')
timeout-minutes: 10
environment:
name: nuget
permissions:
contents: read
packages: write # GitHub Packages; innecesario con NuGet.org (usa NUGET_API_KEY)
steps:
- name: Setup .NET
uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
- name: Download nupkg
uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1
with:
name: nupkg-${{ github.sha }}
path: ./nupkg
- name: Push
env:
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY || github.token }}
run: dotnet nuget push "./nupkg/*.nupkg" --source "{{NUGET_SOURCE}}" --api-key "$NUGET_API_KEY" --skip-duplicate