-
Notifications
You must be signed in to change notification settings - Fork 0
184 lines (161 loc) · 5.34 KB
/
build.yml
File metadata and controls
184 lines (161 loc) · 5.34 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
name: CI / CD
on:
push:
branches: [main, develop]
pull_request:
branches: [main, develop]
tags:
- 'v*'
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
DOTNET_NOLOGO: true
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages
jobs:
build-and-test:
name: Build & Test (${{ matrix.os }})
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-latest, windows-latest]
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ${{ env.NUGET_PACKAGES }}
key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.csproj') }}
restore-keys: ${{ runner.os }}-nuget-
- name: Restore
run: dotnet restore BeyondNet.Factory.sln
- name: Build
run: dotnet build BeyondNet.Factory.sln --configuration Release --no-restore
- name: Test
run: dotnet test BeyondNet.Factory.sln --configuration Release --no-build --logger "trx;LogFileName=results.trx"
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{ matrix.os }}
path: "**/*.trx"
version:
name: Determine Version
runs-on: ubuntu-latest
needs: build-and-test
if: github.event_name == 'push' || github.event_name == 'tag'
outputs:
version: ${{ steps.version.outputs.version }}
is_release: ${{ steps.version.outputs.is_release }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Get version from tag
id: version
run: |
TAG="${GITHUB_REF#refs/tags/}"
if [[ "$TAG" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$ ]]; then
VERSION="${TAG#v}"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "is_release=true" >> $GITHUB_OUTPUT
else
HASH="${GITHUB_SHA:0:7}"
BRANCH_NAME="${GITHUB_REF#refs/heads/}"
echo "version=0.0.0-$BRANCH_NAME+$HASH" >> $GITHUB_OUTPUT
echo "is_release=false" >> $GITHUB_OUTPUT
fi
pack:
name: Pack NuGet Packages
runs-on: ubuntu-latest
needs: [build-and-test, version]
if: needs.version.outputs.is_release == 'true'
strategy:
matrix:
project:
- src/BeyondNetCode.Shell.Factory/BeyondNetCode.Shell.Factory.csproj
- src/BeyondNetCode.Shell.Factory.Installer/BeyondNetCode.Shell.Factory.Installer.csproj
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Pack
run: |
dotnet pack "${{ matrix.project }}" \
-c Release \
--version:${{ needs.version.outputs.version }} \
--no-build \
-p:PackageOutputPath=${{ github.workspace }}/nupkgs
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: packages-${{ matrix.project }}
path: nupkgs/*.nupkg
publish:
name: Publish to NuGet
runs-on: ubuntu-latest
needs: pack
if: needs.pack.result == 'success' && needs.version.outputs.is_release == 'true'
environment: nuget-release
steps:
- name: Download packages
uses: actions/download-artifact@v4
with:
pattern: packages-*
path: ./nupkgs
merge-multiple: true
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: 10.0.x
- name: Push to NuGet.org
run: |
for nupkg in $(find ./nupkgs -name '*.nupkg'); do
dotnet nuget push "$nupkg" \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json \
--skip-duplicate
done
env:
DOTNET_CLI_TELEMETRY_OPTOUT: '1'
release:
name: Create GitHub Release
runs-on: ubuntu-latest
needs: [version]
if: needs.version.outputs.is_release == 'true'
steps:
- uses: actions/checkout@v4
- name: Generate Release Notes
id: release-notes
uses: actions/github-script@v7
with:
script: |
const { data: commits } = await github.rest.repos.listCommits({
owner: context.repo.owner,
repo: context.repo.repo,
per_page: 100,
since: '2024-01-01'
});
let body = '## What\'s New\n\n';
body += `**Version:** ${context.payload.ref.replace('refs/tags/', '')}\n\n`;
body += '### Commits\n';
commits.slice(0, 20).forEach(c => {
body += `- ${c.commit.message.split('\n')[0]} (${c.sha.slice(0, 7)})\n`;
});
return body;
- name: Create Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
body: ${{ steps.release-notes.outputs.result }}
draft: false
prerelease: ${{ contains(needs.version.outputs.version, 'beta') || contains(needs.version.outputs.version, 'alpha') }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}