-
Notifications
You must be signed in to change notification settings - Fork 84
286 lines (250 loc) Β· 10.2 KB
/
build.yml
File metadata and controls
286 lines (250 loc) Β· 10.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
name: Build and Test
on:
push:
pull_request:
workflow_dispatch:
inputs:
runPublish:
description: 'Publish Nuget ?'
required: true
default: false
type: boolean
publishWhichNuget:
description: 'Which Nuget ?'
required: true
default: 'Only Changed'
type: choice
options:
- Only Changed
- All
jobs:
build:
runs-on: ubuntu-latest
outputs:
semver: ${{ steps.gitversion.outputs.semVer }}
fullsemver: ${{ steps.gitversion.outputs.fullSemVer }}
nugetversion: ${{ steps.gitversion.outputs.fullSemVer }}
publishNuget: ${{ steps.changes.outputs.BddfyUpdated == 'true' || steps.changes.outputs.SamplesUpdated == 'true' || github.event.inputs.publishWhichNuget == 'All' }}
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0 # Required for GitVersion
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v4.1.0
with:
versionSpec: '6.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v4.1.0
id: gitversion
- name: Format NuGet version
run: |
buildNumber="${{steps.gitversion.outputs.preReleaseNumber}}${{ steps.gitversion.outputs.buildMetaData }}"
if [[ "${GITHUB_REF}" != "refs/heads/${{ github.event.repository.default_branch }}" ]]; then
buildNumber="${buildNumber}-beta"
fi
packageVersion="${{ steps.gitversion.outputs.majorMinorPatch }}.${buildNumber}"
echo "packageVersion=$packageVersion" >> $GITHUB_OUTPUT
id: formatversion
- name: Display GitVersion outputs
run: |
echo "Version: ${{ steps.gitversion.outputs.semVer }}"
echo "AssemblyVersion: ${{ steps.gitversion.outputs.assemblySemVer }}"
echo "FileVersion: ${{ steps.gitversion.outputs.assemblySemFileVer }}"
echo "NuGet Version: ${{ steps.gitversion.outputs.fullSemVer }}"
echo "Package Version: ${{ steps.formatversion.outputs.packageVersion }}"
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Build project
working-directory: src
run: >-
dotnet build --configuration Release
/p:Version=${{ steps.gitversion.outputs.assemblySemVer }}
/p:AssemblyVersion=${{ steps.gitversion.outputs.assemblySemVer }}
/p:FileVersion=${{ steps.gitversion.outputs.assemblySemFileVer }}
/p:PackageVersion=${{ steps.formatversion.outputs.packageVersion }}
- name: Run tests with coverage
working-directory: src
env:
DiffEngine_Disabled: 'true'
run: >-
dotnet test
--configuration Release
--collect:"XPlat Code Coverage"
--results-directory ../coverage
- name: Generate coverage report
uses: danielpalme/ReportGenerator-GitHub-Action@5.4.16
with:
reports: 'coverage/**/coverage.cobertura.xml'
targetdir: 'coverage-report'
reporttypes: 'Html;Cobertura;TextSummary'
- name: Display Code Coverage Summary
run: |
echo "## π Code Coverage Summary" >> $GITHUB_STEP_SUMMARY
if [ -f "coverage-report/Summary.txt" ]; then
echo '```' >> $GITHUB_STEP_SUMMARY
cat coverage-report/Summary.txt >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "### Build Log Coverage Summary:"
cat coverage-report/Summary.txt
else
echo "β οΈ Coverage summary file not found"
echo "β οΈ Coverage summary file not found" >> $GITHUB_STEP_SUMMARY
fi
- name: Generate Rich Release Notes
id: release_notes
uses: mikepenz/release-changelog-builder-action@v5.4.1
with:
configuration: |
{
"template": "## π Release ${{ steps.gitversion.outputs.semVer }}\n\n### π
Release Information\n- **Version**: ${{ steps.gitversion.outputs.semVer }}\n- **NuGet Version**: ${{ steps.gitversion.outputs.fullSemVer }}\n- **Build Date**: $(date -u +'%Y-%m-%d %H:%M:%S UTC')\n- **Commit**: ${{ github.sha }}\n\n#{{CHANGELOG}}\n\n### π Statistics\n- **Total Changes**: #{{UNCATEGORIZED_COUNT}} commits\n- **Contributors**: #{{CONTRIBUTORS}}\n\n---\n*Generated automatically by GitHub Actions*",
"categories": [
{
"title": "## π Features",
"labels": ["feature", "enhancement", "feat"]
},
{
"title": "## π Bug Fixes",
"labels": ["bug", "fix", "bugfix"]
},
{
"title": "## π Documentation",
"labels": ["documentation", "docs"]
},
{
"title": "## π§ Maintenance",
"labels": ["maintenance", "chore", "refactor"]
},
{
"title": "## β οΈ Breaking Changes",
"labels": ["breaking", "breaking-change"]
}
],
"pr_template": "- #{{TITLE}} (#{{NUMBER}}) by @#{{AUTHOR}}",
"empty_template": "- #{{TITLE}} (#{{HASH}}) by @#{{AUTHOR}}",
"max_pull_requests": 200,
"max_back_track_time_days": 365
}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Save Release Notes to File
run: echo "${{ steps.release_notes.outputs.changelog }}" > release-notes.md
- name: Upload Release Notes as artifact
uses: actions/upload-artifact@v4
with:
name: release-notes
path: release-notes.md
- name: Check for changes in project paths
id: changes
run: |
latestTag=$(git describe --tags --abbrev=0)
if git diff --quiet "$latestTag" HEAD -- src/Samples/; then
echo "SamplesUpdated=false" >> $GITHUB_OUTPUT
else
echo "SamplesUpdated=true" >> $GITHUB_OUTPUT
fi
if git diff --quiet "$latestTag" HEAD -- src/TestStack.BDDfy/; then
echo "BddfyUpdated=false" >> $GITHUB_OUTPUT
else
echo "BddfyUpdated=true" >> $GITHUB_OUTPUT
fi
- name: Print changed paths
run: |
echo "SamplesUpdated: ${{ steps.changes.outputs.SamplesUpdated }}"
echo "BddfyUpdated: ${{ steps.changes.outputs.BddfyUpdated }}"
- name: Create Samples package
working-directory: src
if: steps.changes.outputs.SamplesUpdated == 'true' || github.event.inputs.publishWhichNuget == 'All'
run: >-
dotnet pack ./Samples/TestStack.BDDfy.Samples/*.csproj
--configuration Release
--no-build
/p:PackageVersion=${{ steps.formatversion.outputs.packageVersion }}
--output ../packages
- name: Create Bddfy package
working-directory: src
if: steps.changes.outputs.BddfyUpdated == 'true' || github.event.inputs.publishWhichNuget == 'All'
run: >-
dotnet pack ./TestStack.BDDfy/*.csproj
--configuration Release
--no-build
/p:PackageVersion=${{ steps.formatversion.outputs.packageVersion }}
--output ../packages
- name: Upload NuGet package as artifact
uses: actions/upload-artifact@v4
with:
name: nuget-package
path: packages/*.nupkg
- name: Publish coverage report as artifact
uses: actions/upload-artifact@v4
with:
name: coverage-report
path: coverage-report/
publish-nuget:
runs-on: ubuntu-latest
needs: build
if: needs.build.outputs.publishNuget == 'true' && (github.event.inputs.runPublish == 'true' || github.ref_name == github.event.repository.default_branch)
environment:
name: Publish
url: https://www.nuget.org/packages/TestStack.BDDfy/
steps:
- name: Download NuGet package
uses: actions/download-artifact@v5
with:
name: nuget-package
path: packages
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: '8.0.x'
- name: Publish to NuGet
run: dotnet nuget push packages/*.nupkg --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
create-release-tag:
runs-on: ubuntu-latest
needs: [build, publish-nuget]
if: github.event.inputs.runPublish == 'true' && github.ref_name == github.event.repository.default_branch
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v5
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }}
- name: Check if tag already exists
id: check_tag
run: |
TAG="v${{ needs.build.outputs.semver }}"
if git rev-parse "$TAG" >/dev/null 2>&1; then
echo "Tag $TAG already exists"
echo "tag_exists=true" >> $GITHUB_OUTPUT
else
echo "Creating new tag: $TAG"
echo "tag_exists=false" >> $GITHUB_OUTPUT
echo "new_tag=$TAG" >> $GITHUB_OUTPUT
fi
- name: Download Release Notes
if: steps.check_tag.outputs.tag_exists == 'false'
uses: actions/download-artifact@v5
with:
name: release-notes
path: .
- name: Create Git Tag and GitHub Release
if: steps.check_tag.outputs.tag_exists == 'false'
run: |
TAG="${{ steps.check_tag.outputs.new_tag }}"
# Configure git
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Create and push tag
git tag -a "$TAG" -m "Release $TAG"
git push origin "$TAG"
# Create GitHub release
gh release create "$TAG" \
--title "Release $TAG" \
--notes-file release-notes.md \
--generate-notes
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}