-
Notifications
You must be signed in to change notification settings - Fork 0
210 lines (179 loc) · 6.5 KB
/
build-and-release.yml
File metadata and controls
210 lines (179 loc) · 6.5 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
name: Build and Release NuGet Package
on:
push:
branches: [ "main" ]
paths:
- 'src/**'
pull_request:
branches: [ "main" ]
paths:
- 'src/**'
env:
GLOBAL_JSON_PATH: './src/global.json'
PROJECT_PATH: './src/TurboHttp.sln'
PACKAGE_OUTPUT_DIRECTORY: './packages'
TEST_OUTPUT_DIRECTORY: '${{ github.workspace }}/testresults'
COVERAGE_REPORT_DIRECTORY: './coveragereport'
permissions:
contents: write
deployments: write
checks: write
pull-requests: write
jobs:
build:
permissions:
contents: read
checks: write
pull-requests: write
# For a list of available runner types, refer to
# https://help.github.com/en/actions/reference/workflow-syntax-for-github-actions#jobsjob_idruns-on
runs-on: ubuntu-latest
outputs:
releaseVersion: ${{ steps.gitversion.outputs.majorMinorPatch }}
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 0
# Install the .NET Core workload
- name: Install .NET Core
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.GLOBAL_JSON_PATH }}
cache: true
cache-dependency-path: '**/packages.lock.json'
- name: Install GitVersion
uses: gittools/actions/gitversion/setup@v1.1.1
with:
versionSpec: '5.x'
- name: Determine Version
uses: gittools/actions/gitversion/execute@v1.1.1
id: gitversion
- name: Generate Release Notes for nuget
id: plain-notes
env:
VERSION: ${{ steps.gitversion.outputs.semVer }}
run: |
cat > notes.md << EOF
🎯 TurboHttp v$VERSION
📦 NuGet: https://nuget.org/packages/TurboHttp
🔗 Release: https://github.com/st0o0/TurboHttp/releases/v$VERSION
See release page for full changelog and details!
Built with ❤️
EOF
sed -i "s|v\$VERSION|v$VERSION|g" notes.md
echo "release-notes<<EOF" >> $GITHUB_OUTPUT
cat notes.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Display GitVersion outputs
run: |
echo "Release Version: ${{ steps.gitversion.outputs.majorMinorPatch }}"
echo "Nuget Version: ${{ steps.gitversion.outputs.fullSemVer }}"
- name: Restore dependencies
run: >
dotnet
restore
${{ env.PROJECT_PATH }}
- name: Build
run: >
dotnet build
--configuration Release
--no-restore
${{ env.PROJECT_PATH }}
/p:Version=${{ steps.gitversion.outputs.fullSemVer }}
/p:ContinuousIntegrationBuild=true
- name: Run tests
working-directory: './src'
run: >
dotnet test
--configuration Release
--no-ansi
--no-build
--coverage
--coverage-output-format cobertura
--results-directory ${{ env.TEST_OUTPUT_DIRECTORY }}
--solution *.sln
- name: Create NuGet package
run: >
dotnet pack
--configuration Release
--no-build
--output ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
${{ env.PROJECT_PATH }}
/p:PackageVersion=${{ steps.gitversion.outputs.fullSemVer }}
/p:PackageReleaseNotes="${{ steps.plain-notes.outputs.release-notes }}"
- name: Report Code Coverage
if: always()
uses: danielpalme/ReportGenerator-GitHub-Action@5
with:
reports: '${{ env.TEST_OUTPUT_DIRECTORY }}/*cobertura.xml'
targetdir: '${{ env.COVERAGE_REPORT_DIRECTORY }}'
reporttypes: 'MarkdownSummaryGithub'
tag: '${{ steps.gitversion.outputs.fullSemVer }}'
- name: Add Coverage Summary to Job Summary
if: always()
run: cat ${{ env.COVERAGE_REPORT_DIRECTORY }}/SummaryGithub.md >> $GITHUB_STEP_SUMMARY
- name: Upload package artifacts
uses: actions/upload-artifact@v6
with:
name: nuget-packages
path: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg
publish:
permissions:
contents: write
deployments: write
runs-on: ubuntu-latest
needs: build
environment:
name: nuget
url: https://www.nuget.org/packages/TurboHttp
if: github.ref == 'refs/heads/main' && github.event_name == 'push'
steps:
- name: Checkout
uses: actions/checkout@v6
with:
fetch-depth: 1
- name: Download package artifacts
uses: actions/download-artifact@v7
with:
name: nuget-packages
path: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}
- name: Setup .NET Core
uses: actions/setup-dotnet@v5
with:
global-json-file: ${{ env.GLOBAL_JSON_PATH }}
cache: true
cache-dependency-path: '**/packages.lock.json'
- name: Publish to NuGet
run: |
dotnet nuget push --api-key ${{ secrets.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg
- name: Generate Release Notes
id: notes
env:
GH_TOKEN: ${{ github.token }}
VERSION: ${{ needs.build.outputs.releaseVersion }}
run: |
cat > notes.md << EOF
🎯 TurboHttp v$VERSION
[](https://nuget.org/packages/TurboHttp)
[](https://github.com/st0o0/TurboHttp)
EOF
gh api repos/${{ github.repository }}/releases/generate-notes \
-f tag_name="v\$VERSION" \
--jq .body >> notes.md || echo "## 📋 Changes\nNo changelog available" >> notes.md
sed -i "s|v\$VERSION|v$VERSION|g" notes.md
echo "Built with ❤️" >> notes.md
echo "release-notes<<EOF" >> $GITHUB_OUTPUT
cat notes.md >> $GITHUB_OUTPUT
echo "EOF" >> $GITHUB_OUTPUT
- name: Create & Publish Release
uses: softprops/action-gh-release@v2
with:
tag_name: "v${{ needs.build.outputs.releaseVersion }}"
target_commitish: ${{ github.sha }}
name: "TurboHttp v${{ needs.build.outputs.releaseVersion }}"
body: ${{ steps.notes.outputs.release-notes }}
draft: false
prerelease: false
make_latest: true
files: ${{ env.PACKAGE_OUTPUT_DIRECTORY }}/*.nupkg