1+ name : CI / CD
2+
3+ on :
4+ push :
5+ branches : [main, develop]
6+ pull_request :
7+ branches : [main, develop]
8+ tags :
9+ - ' v*'
10+
11+ env :
12+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
13+ DOTNET_NOLOGO : true
14+ NUGET_PACKAGES : ${{ github.workspace }}/.nuget/packages
15+
16+ jobs :
17+ build-and-test :
18+ name : Build & Test (${{ matrix.os }})
19+ runs-on : ${{ matrix.os }}
20+ strategy :
21+ matrix :
22+ os : [ubuntu-latest, windows-latest]
23+
24+ steps :
25+ - name : Checkout
26+ uses : actions/checkout@v4
27+ with :
28+ fetch-depth : 0
29+
30+ - name : Setup .NET
31+ uses : actions/setup-dotnet@v5
32+ with :
33+ dotnet-version : 10.0.x
34+
35+ - name : Cache NuGet packages
36+ uses : actions/cache@v4
37+ with :
38+ path : ${{ env.NUGET_PACKAGES }}
39+ key : ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
40+ restore-keys : ${{ runner.os }}-nuget-
41+
42+ - name : Restore
43+ run : dotnet restore BeyondNet.Aop.sln
44+
45+ - name : Build
46+ run : dotnet build BeyondNet.Aop.sln --configuration Release --no-restore
47+
48+ - name : Test
49+ run : dotnet test BeyondNet.Aop.sln --configuration Release --no-build --logger "trx;LogFileName=results.trx"
50+
51+ - name : Upload test results
52+ uses : actions/upload-artifact@v4
53+ if : always()
54+ with :
55+ name : test-results-${{ matrix.os }}
56+ path : " **/*.trx"
57+
58+ version :
59+ name : Determine Version
60+ runs-on : ubuntu-latest
61+ needs : build-and-test
62+ if : github.event_name == 'push' || github.event_name == 'tag'
63+ outputs :
64+ version : ${{ steps.version.outputs.version }}
65+ is_release : ${{ steps.version.outputs.is_release }}
66+ steps :
67+ - name : Checkout
68+ uses : actions/checkout@v4
69+
70+ - name : Get version from tag
71+ id : version
72+ run : |
73+ TAG="${GITHUB_REF#refs/tags/}"
74+ if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
75+ VERSION="${TAG#v}"
76+ echo "version=$VERSION" >> $GITHUB_OUTPUT
77+ echo "is_release=true" >> $GITHUB_OUTPUT
78+ else
79+ HASH="${GITHUB_SHA:0:7}"
80+ BRANCH_NAME="${GITHUB_REF#refs/heads/}"
81+ echo "version=0.0.0-$BRANCH_NAME+$HASH" >> $GITHUB_OUTPUT
82+ echo "is_release=false" >> $GITHUB_OUTPUT
83+ fi
84+
85+ pack :
86+ name : Pack NuGet Packages
87+ runs-on : ubuntu-latest
88+ needs : [build-and-test, version]
89+ if : needs.version.outputs.is_release == 'true'
90+ strategy :
91+ matrix :
92+ project :
93+ - src/BeyondNetCode.Shell.Aop/BeyondNetCode.Shell.Aop.csproj
94+ - src/BeyondNetCode.Shell.Aop.Aspects/BeyondNetCode.Shell.Aop.Aspects.csproj
95+ - src/BeyondNetCode.Shell.Aop.Aspects.Logger/BeyondNetCode.Shell.Aop.Aspects.Logger.csproj
96+ - src/BeyondNetCode.Shell.Aop.Aspects.Logger.Serilog/BeyondNetCode.Shell.Aop.Aspects.Logger.Serilog.csproj
97+ - src/BeyondNetCode.Shell.Aop.DispatchProxy/BeyondNetCode.Shell.Aop.DispatchProxy.csproj
98+ - src/BeyondNetCode.Shell.Aop.DI/BeyondNetCode.Shell.Aop.DI.csproj
99+ steps :
100+ - uses : actions/checkout@v4
101+
102+ - name : Setup .NET
103+ uses : actions/setup-dotnet@v5
104+ with :
105+ dotnet-version : 10.0.x
106+
107+ - name : Pack
108+ run : |
109+ dotnet pack "${{ matrix.project }}" \
110+ -c Release \
111+ --version:${{ needs.version.outputs.version }} \
112+ --no-build \
113+ -p:PackageOutputPath=${{ github.workspace }}/nupkgs
114+
115+ - name : Upload artifacts
116+ uses : actions/upload-artifact@v4
117+ with :
118+ name : packages-${{ matrix.project }}
119+ path : nupkgs/*.nupkg
120+
121+ publish :
122+ name : Publish to NuGet
123+ runs-on : ubuntu-latest
124+ needs : pack
125+ if : needs.pack.result == 'success' && needs.version.outputs.is_release == 'true'
126+ environment : nuget-release
127+
128+ steps :
129+ - name : Download packages
130+ uses : actions/download-artifact@v4
131+ with :
132+ pattern : packages-*
133+ path : ./nupkgs
134+ merge-multiple : true
135+
136+ - name : Setup .NET
137+ uses : actions/setup-dotnet@v5
138+ with :
139+ dotnet-version : 10.0.x
140+
141+ - name : Push to NuGet.org
142+ run : |
143+ for nupkg in $(find ./nupkgs -name '*.nupkg'); do
144+ dotnet nuget push "$nupkg" \
145+ --api-key ${{ secrets.NUGET_API_KEY }} \
146+ --source https://api.nuget.org/v3/index.json \
147+ --skip-duplicate
148+ done
149+ env :
150+ DOTNET_CLI_TELEMETRY_OPTOUT : ' 1'
151+
152+ release :
153+ name : Create GitHub Release
154+ runs-on : ubuntu-latest
155+ needs : [version]
156+ if : needs.version.outputs.is_release == 'true'
157+ steps :
158+ - uses : actions/checkout@v4
159+
160+ - name : Generate Release Notes
161+ id : release-notes
162+ uses : actions/github-script@v7
163+ with :
164+ script : |
165+ const { data: commits } = await github.rest.repos.listCommits({
166+ owner: context.repo.owner,
167+ repo: context.repo.repo,
168+ per_page: 100,
169+ since: '2024-01-01'
170+ });
171+ let body = '## What\'s New\n\n';
172+ body += `**Version:** ${context.payload.ref.replace('refs/tags/', '')}\n\n`;
173+ body += '### Commits\n';
174+ commits.slice(0, 20).forEach(c => {
175+ body += `- ${c.commit.message.split('\n')[0]} (${c.sha.slice(0, 7)})\n`;
176+ });
177+ return body;
178+
179+ - name : Create Release
180+ uses : softprops/action-gh-release@v2
181+ with :
182+ tag_name : ${{ github.ref_name }}
183+ name : Release ${{ github.ref_name }}
184+ body : ${{ steps.release-notes.outputs.result }}
185+ draft : false
186+ prerelease : ${{ contains(needs.version.outputs.version, 'beta') || contains(needs.version.outputs.version, 'alpha') }}
187+ env :
188+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
0 commit comments