-
-
Notifications
You must be signed in to change notification settings - Fork 373
218 lines (197 loc) · 8.44 KB
/
main.yml
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
name: MimeKit CI/CD Pipeline
on: [push, pull_request, workflow_dispatch]
jobs:
ci:
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ windows-latest, ubuntu-latest ]
build-configuration: [ Debug, Release ]
outputs:
latest-version: ${{ steps.semantic_version.outputs.version_num }}
environment: ci
env:
SOLUTION_PATH: MimeKit.sln
BUILD_PLATFORM: Any CPU
BUILD_CONFIGURATION: ${{ matrix.build-configuration }}
GITHUB_RUN_NUMBER: ${{ github.run_number }}
steps:
- name: Setup/Install the .NET 8 SDK
id: install-netsdk
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Configure build options
id: configure
shell: pwsh
run: |
$IS_DEBUG = 'false'
$IS_RELEASE = 'false'
$IS_PUSH_TO_MASTER = 'false'
$IS_NOT_PR = 'true'
$IS_GITHUB_RELEASE = 'false'
$IS_WINDOWS = 'false'
$IS_UBUNTU = 'false'
$GENERATE_CODE_COVERAGE = 'no'
if ( $env:BUILD_CONFIGURATION -ceq 'Debug' ) {
$IS_DEBUG = 'true'
}
if ( $env:BUILD_CONFIGURATION -ceq 'Release' ) {
$IS_RELEASE = 'true'
}
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') ) {
$IS_PUSH_TO_MASTER = 'true'
}
if ( $env:GITHUB_EVENT_NAME -ceq 'pull_request' ) {
$IS_NOT_PR = 'false'
}
if ( ($env:GITHUB_EVENT_NAME -ceq 'push') -and ($env:GITHUB_REF -ceq 'refs/heads/master') -and ($env:BUILD_CONFIGURATION -ceq 'Release') -and ($env:OS -ceq 'windows-latest') ) {
$IS_GITHUB_RELEASE = 'true'
}
if ( $env:OS -ceq 'windows-latest' ) {
$IS_WINDOWS = 'true'
}
if ( $env:OS -ceq 'ubuntu-latest' ) {
$IS_UBUNTU = 'true'
}
if ( $IS_WINDOWS -ceq 'true' -and $IS_DEBUG -ceq 'true' ) {
$GENERATE_CODE_COVERAGE = 'yes'
}
echo "is_debug=$IS_DEBUG" >> $GITHUB_OUTPUT
echo "is_release=$IS_RELEASE" >> $GITHUB_OUTPUT
echo "is_push_to_master=$IS_PUSH_TO_MASTER" >> $GITHUB_OUTPUT
echo "is_not_pr=$IS_NOT_PR" >> $GITHUB_OUTPUT
echo "is_github_release=$IS_GITHUB_RELEASE" >> $GITHUB_OUTPUT
echo "is_windows=$IS_WINDOWS" >> $GITHUB_OUTPUT
echo "is_ubuntu=$IS_UBUNTU" >> $GITHUB_OUTPUT
echo "generate_code_coverage=$GENERATE_CODE_COVERAGE" >> $GITHUB_OUTPUT
echo "is_debug=$IS_DEBUG"
echo "is_release=$IS_RELEASE"
echo "is_push_to_master=$IS_PUSH_TO_MASTER"
echo "is_not_pr=$IS_NOT_PR"
echo "is_github_release=$IS_GITHUB_RELEASE"
echo "is_windows=$IS_WINDOWS"
echo "is_ubuntu=$IS_UBUNTU"
echo "generate_code_coverage=$GENERATE_CODE_COVERAGE"
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
GITHUB_REF: ${{ github.ref }}
OS: ${{ matrix.os }}
- if: ${{ steps.configure.outputs.is_windows == 'true' }}
name: Setup MSBuild
id: setup_msbuild
uses: microsoft/setup-msbuild@v1.3.1
- name: Checkout repository
id: checkout_repo
uses: actions/checkout@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
submodules: recursive
fetch-depth: 0
- name: Get semantic version from csproj
id: semantic_version
shell: pwsh
run: |
$xml = [xml](gc MimeKit/MimeKit.csproj)
$SEMANTIC_VERSION_NUMBER = $xml.Project.PropertyGroup.VersionPrefix
$VERSION_NUM = $SEMANTIC_VERSION_NUMBER[0].Trim()
echo "version_num=$VERSION_NUM" >> $GITHUB_OUTPUT
echo "version_tag=v$VERSION_NUM" >> $GITHUB_OUTPUT
- if: ${{ steps.configure.outputs.is_github_release == 'true' }}
name: Get latest tag
id: get_latest_tag
shell: pwsh
run: |
$LATEST_TAG = git -c 'versionsort.suffix=-' ls-remote --exit-code --refs --sort='version:refname' --tags "https://github.com/$env:GIT_URL.git" '*.*.*' | tail --lines=1 | cut --delimiter='/' --fields=3
echo "tag=$LATEST_TAG" >> $GITHUB_OUTPUT
env:
GIT_URL: ${{ github.repository }}
- if: ${{ steps.configure.outputs.is_github_release == 'true' && steps.semantic_version.outputs.version_tag != steps.get_latest_tag.outputs.tag }}
name: Add new tag to repo
id: add_new_tag_to_repo
continue-on-error: true
shell: pwsh
run: |
git config --global user.name $env:GIT_USER_NAME
git config --global user.email $env:GIT_USER_EMAIL
git tag -a -m "Tagged for $env:NEW_VERSION_NUM" $env:NEW_VERSION_NUM
git push --follow-tags
env:
GIT_USER_NAME: ${{ github.event.head_commit.author.username }}
GIT_USER_EMAIL: ${{ github.event.head_commit.author.email }}
NEW_VERSION_NUM: ${{ steps.semantic_version.outputs.version_num }}
- name: Run .NET restore
shell: pwsh
run: |
dotnet restore $env:SOLUTION_PATH
- name: Run .NET tool restore
shell: pwsh
run: |
dotnet tool restore
- name: Build solution
id: build_solution
continue-on-error: true
shell: pwsh
run: |
dotnet msbuild $env:SOLUTION_PATH -property:Platform=$env:BUILD_PLATFORM -property:Configuration=$env:BUILD_CONFIGURATION -property:MonoRuntime=$env:IS_UBUNTU
env:
IS_UBUNTU: ${{ steps.configure.outputs.is_ubuntu }}
- name: Run unit tests
id: run_unit_tests
continue-on-error: true
shell: pwsh
run: |
echo "BUILD_CONFIGURATION=$env:BUILD_CONFIGURATION"
echo "GENERATE_CODE_COVERAGE=$env:GENERATE_CODE_COVERAGE"
& ./scripts/test.ps1 -Configuration:$env:BUILD_CONFIGURATION -GenerateCodeCoverage:$env:GENERATE_CODE_COVERAGE
env:
GENERATE_CODE_COVERAGE: ${{ steps.configure.outputs.generate_code_coverage }}
- name: Upload unit test results
id: upload_test_results
continue-on-error: true
uses: actions/upload-artifact@v4
with:
name: MimeKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}-${{ matrix.os }}-${{ matrix.build-configuration }}-TestResults.xml
path: TestResult.xml
- if: ${{ steps.configure.outputs.generate_code_coverage == 'yes' }}
name: Upload code coverage data to coveralls.io
id: upload_to_coveralls
shell: pwsh
run: |
& ./scripts/coveralls.ps1
env:
COVERALLS_REPO_TOKEN: ${{ secrets.COVERALLS_REPO_TOKEN }}
GIT_COMMIT_SHA: ${{ github.sha }}
GIT_REF: ${{ github.ref }}
GIT_ACTOR: ${{ github.event.head_commit.author.username }}
GIT_ACTOR_EMAIL: ${{ github.event.head_commit.author.email }}
GIT_COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
COVERALLS_JOB_ID: ${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}
- if: ${{ steps.configure.outputs.is_github_release == 'true' }}
name: Create NuGet package
id: create_nuget_package
shell: pwsh
run: |
nuget pack nuget/MimeKit.nuspec `
-Version "$env:LATEST_VERSION.$env:GITHUB_RUN_NUMBER"
env:
LATEST_VERSION: ${{ steps.semantic_version.outputs.version_num }}
- if: ${{ steps.configure.outputs.is_github_release == 'true' }}
name: Push NuGet package to MyGet
id: push_nuget_package
shell: pwsh
run: |
nuget push $env:NUGET_PKG_PATH `
-ApiKey $env:MYGET_API_KEY `
-Source https://www.myget.org/F/mimekit/api/v3/index.json
env:
NUGET_PKG_PATH: MimeKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
MYGET_API_KEY: ${{ secrets.MYGET_API_KEY }}
- if: ${{ steps.configure.outputs.is_github_release == 'true' }}
name: Upload NuGet package as artifact
id: upload_nuget_package
uses: actions/upload-artifact@v4
with:
name: MimeKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
path: MimeKit.${{ steps.semantic_version.outputs.version_num }}.${{ env.GITHUB_RUN_NUMBER }}.nupkg
# Built with ❤ by [Pipeline Foundation](https://pipeline.foundation)