1+ name : Publish to NuGet
2+
3+ on :
4+ release :
5+ types : [published]
6+ workflow_dispatch :
7+ inputs :
8+ version :
9+ description : ' Version to publish (e.g., 1.0.1)'
10+ required : true
11+ type : string
12+
13+ jobs :
14+ publish :
15+ runs-on : ubuntu-latest
16+
17+ steps :
18+ - name : Checkout code
19+ uses : actions/checkout@v4
20+
21+ - name : Setup .NET
22+ uses : actions/setup-dotnet@v4
23+ with :
24+ dotnet-version : ' 8.0.x'
25+
26+ - name : Restore dependencies
27+ run : dotnet restore
28+
29+ - name : Build solution
30+ run : dotnet build --configuration Release --no-restore
31+
32+ - name : Run tests (excluding integration tests)
33+ run : dotnet test --configuration Release --no-build --filter "FullyQualifiedName!~IntegrationTests" --verbosity normal
34+
35+ - name : Update version (manual trigger)
36+ if : github.event_name == 'workflow_dispatch'
37+ run : |
38+ # Update version in project files
39+ sed -i "s/<Version>.*<\/Version>/<Version>${{ github.event.inputs.version }}<\/Version>/" src/Ivy.GrepApp/Ivy.GrepApp.csproj
40+ sed -i "s/<Version>.*<\/Version>/<Version>${{ github.event.inputs.version }}<\/Version>/" src/grepapp/grepapp.csproj
41+
42+ - name : Extract version from tag (release trigger)
43+ if : github.event_name == 'release'
44+ run : |
45+ # Extract version from release tag (remove 'v' prefix if present)
46+ VERSION=${GITHUB_REF#refs/tags/}
47+ VERSION=${VERSION#v}
48+ echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV
49+ # Update version in project files
50+ sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" src/Ivy.GrepApp/Ivy.GrepApp.csproj
51+ sed -i "s/<Version>.*<\/Version>/<Version>$VERSION<\/Version>/" src/grepapp/grepapp.csproj
52+
53+ - name : Pack NuGet packages
54+ run : |
55+ dotnet pack src/Ivy.GrepApp/Ivy.GrepApp.csproj --configuration Release --no-build --output ./artifacts
56+ dotnet pack src/grepapp/grepapp.csproj --configuration Release --no-build --output ./artifacts
57+
58+ - name : Publish to NuGet
59+ run : dotnet nuget push ./artifacts/*.nupkg --api-key ${{ secrets.NUGET_TOKEN }} --source https://api.nuget.org/v3/index.json --skip-duplicate
60+
61+ - name : Upload artifacts
62+ uses : actions/upload-artifact@v4
63+ with :
64+ name : nuget-packages
65+ path : ./artifacts/*.nupkg
66+ retention-days : 30
0 commit comments