Skip to content

Commit 605a6bf

Browse files
committed
Create main.yml
1 parent 0183cf4 commit 605a6bf

1 file changed

Lines changed: 83 additions & 0 deletions

File tree

.github/workflows/main.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# Nome del workflow visualizzato su GitHub
2+
name: Publish to NuGet
3+
4+
# --- Trigger ---
5+
# Elenco degli eventi che attivano questo workflow
6+
on:
7+
push:
8+
branches:
9+
- main # Si attiva a ogni push sul branch 'main'
10+
tags:
11+
- 'v[0-9]+.[0-9]+.[0-9]+' # Si attiva quando viene pushato un tag come 'v1.0.0'
12+
pull_request:
13+
branches:
14+
- main # Si attiva quando viene aperta/aggiornata una PR verso 'main'
15+
workflow_dispatch: # Permette di avviare il workflow manualmente dalla UI di GitHub
16+
17+
jobs:
18+
build_and_publish:
19+
# SPECIFICA L'AMBIENTE PER ACCEDERE AI SEGRETI CORRISPONDENTI
20+
environment: Production
21+
runs-on: ubuntu-latest
22+
23+
# AGGIUNGE I PERMESSI NECESSARI PER CREARE UNA RELEASE
24+
permissions:
25+
contents: write
26+
27+
steps:
28+
# 1. Scarica il codice del repository
29+
- name: Checkout code
30+
uses: actions/checkout@v4
31+
32+
# 2. Installa la versione specificata di .NET
33+
- name: Setup .NET
34+
uses: actions/setup-dotnet@v4
35+
with:
36+
dotnet-version: '9.0.x'
37+
38+
# 3. Ripristina le dipendenze NuGet del progetto
39+
- name: Restore dependencies
40+
run: dotnet restore ProjectR.sln
41+
42+
# 4. Compila la soluzione in configurazione Release
43+
- name: Build
44+
run: dotnet build ProjectR.sln --no-restore --configuration Release
45+
46+
# 5. Esegue i test della soluzione
47+
- name: Run tests
48+
run: dotnet test ProjectR.sln --no-build --configuration Release
49+
50+
# --- Pubblicazione ---
51+
# I seguenti passaggi vengono eseguiti SOLO se il workflow
52+
# è stato attivato dal push di un tag (es. v1.2.3)
53+
54+
# 6. Crea i pacchetti NuGet per tutti i progetti nella soluzione
55+
- name: Pack projects
56+
if: startsWith(github.ref, 'refs/tags/v')
57+
run: dotnet pack ProjectR.sln --no-build --configuration Release --output ./packages
58+
59+
# 7. Pubblica tutti i pacchetti .nupkg creati nel passo precedente
60+
- name: Publish to NuGet
61+
if: startsWith(github.ref, 'refs/tags/v')
62+
run: dotnet nuget push "./packages/*.nupkg" --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json
63+
64+
# 8. Estrae le note di rilascio dal CHANGELOG.md per la versione corrente
65+
- name: Extract Release Notes
66+
if: startsWith(github.ref, 'refs/tags/v')
67+
run: |
68+
VERSION=$(echo "${{ github.ref_name }}" | sed 's/^v//')
69+
awk -v ver="$VERSION" '
70+
BEGIN { p=0 }
71+
$0 ~ "^<a name=\"" ver "\">" { p=1; next }
72+
p==1 && /^<a name=/ { p=0 }
73+
p==1 { print }
74+
' CHANGELOG.md > RELEASE_NOTES.md
75+
76+
# 9. Crea una Release su GitHub e carica i pacchetti come artefatti
77+
- name: Create GitHub Release
78+
if: startsWith(github.ref, 'refs/tags/v')
79+
uses: softprops/action-gh-release@v2
80+
with:
81+
files: ./packages/*.nupkg
82+
# Usa solo le note specifiche della versione estratte nel passo precedente
83+
body_path: RELEASE_NOTES.md

0 commit comments

Comments
 (0)