-
-
Notifications
You must be signed in to change notification settings - Fork 147
252 lines (214 loc) · 8.2 KB
/
Copy pathtest-and-publish.yml
File metadata and controls
252 lines (214 loc) · 8.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
name: Test and Publish
on:
push:
branches:
- master
- development
- 'cicd/**'
pull_request:
branches:
- master
- development
- 'cicd/**'
concurrency:
group: ${{github.workflow}}-${{github.event.pull_request.number || github.ref}}
cancel-in-progress: true
env:
# Disable the .NET logo in the console output.
DOTNET_NOLOGO: true
# Disable the .NET first time experience to skip caching NuGet packages and speed up the build.
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
# Disable sending .NET CLI telemetry to Microsoft.
DOTNET_CLI_TELEMETRY_OPTOUT: true
jobs:
upload-event-file:
name: Upload Event File
runs-on: ubuntu-22.04
steps:
- name: Upload event file
uses: actions/upload-artifact@v4
with:
name: test-event-file
path: ${{ github.event_path }}
retention-days: 1
# Construct a version suffix including the branch name, build number and commit hash (e.g., "development.58+abcdef12").
get-version:
name: Calculating Version Suffix
runs-on: ubuntu-22.04
outputs:
version_suffix: ${{ steps.set-vars.outputs.version_suffix }}
steps:
- uses: actions/checkout@v4
- id: git-vars
name: Get git branch information
shell: bash
run: |
echo "##[set-output name=git_branch;]$(echo $GITHUB_REF)"
echo "::set-output name=git_hash::$(git rev-parse --short HEAD)"
- id: set-vars
uses: actions/github-script@v7
with:
script: |
let runNumber = "${{ github.run_number }}";
let gitHash = "${{ steps.git-vars.outputs.git_hash }}";
let rawGitRef = "${{ steps.git-vars.outputs.git_branch }}";
console.log("rawGitRef: " + rawGitRef);
let gitRef = rawGitRef.replace(/^refs\/heads\//, "").replace(/^refs\/heads\//, "").replace(/[_//!@#$%&]/g, "-");
if(gitRef.indexOf("refs/pull/") === 0) {
gitRef = "pr-" + gitRef.substring(10, gitRef.lastIndexOf("/"));
}
var versSuffix = `${gitRef}.${runNumber}+${gitHash}`;
console.log(versSuffix);
core.setOutput("version_suffix", versSuffix);
# Main build job for compiling all csprojs.
build:
name: Build
runs-on: windows-2022
needs: [get-version]
timeout-minutes: 10
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
# Master branch is just a normal build.
- name: Build on master branch
if: ${{github.ref == 'refs/heads/master'}}
run: |
dotnet restore AsmResolver.sln
dotnet build AsmResolver.sln `
--configuration Release `
--property:CheckEolTargetFramework=false
# For non-master branches (e.g., development or feature branches) we apply a fixup on the version suffix.
- name: Build on non-master branch
if: ${{github.ref != 'refs/heads/master'}}
run: |
dotnet restore AsmResolver.sln `
--property:VersionSuffix=${{needs.get-version.outputs.version_suffix}} `
--property:CheckEolTargetFramework=false
dotnet build AsmResolver.sln `
--configuration Release `
--property:VersionSuffix=${{needs.get-version.outputs.version_suffix}} `
--property:CheckEolTargetFramework=false
- name: Upload Build Artifacts
uses: actions/upload-artifact@v4
with:
name: build-artifacts
path: artifacts/
retention-days: 7
# Multiplexed test job running all tests on different architectures.
test:
name: Test
needs: [get-version, build]
timeout-minutes: 20
strategy:
fail-fast: false
matrix:
runner: [
{ image: 'windows-2022', arch: 'x64' },
{ image: 'ubuntu-22.04', arch: 'x64' },
# TODO: We disable x86 tests for now due to it being too unstable.
# In particular, x86 tests often fail on spawning the xunit's test host process (cannot load hostpolicy.dll,
# as if dotnet x86 is not installed/loaded properly). This should be addressed in the future, as dynamic
# features that load metadata from live processes (as happens in e.g., AsmResolver.DotNet.Dynamic) should be
# properly covered by CI across architectures as well.
# { image: 'windows-2022', arch: 'x86' },
]
runs-on: ${{ matrix.runner.image }}
steps:
- uses: actions/checkout@v4
- name: Get .NET Installation Path
uses: ./.github/actions/dotnet-path
id: dotnet-path
with:
architecture: ${{ matrix.runner.arch }}
# We need to include many dotnet versions, even including some (specific) EOL versions, as many tests run binaries
# from all kinds of versions.
- name: Setup .NET
uses: dlemstra/setup-dotnet@add-architecture-option
with:
dotnet-architecture: ${{ matrix.runner.arch }}
dotnet-version: |
2.1.202
2.1.818
2.2.402
3.1.426
5.0.x
6.0.x
8.0.x
9.0.x
env:
DOTNET_INSTALL_DIR: ${{steps.dotnet-path.outputs.install-path}}
- name: Get Installed .NET Information
shell: pwsh
run: '& "${{ steps.dotnet-path.outputs.exe-path }}" --info'
# We need wine on linux as many tests build and run (semi-)native PE files.
- name: Setup Wine
if: ${{runner.os == 'Linux'}}
uses: ./.github/actions/setup-wine-ubuntu
- name: Get Installed Wine Information
if: ${{runner.os == 'Linux'}}
run: wine --version
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: artifacts/
# Run all csproj tests, outputting test results as TRX files.
- name: Run Tests (x86)
shell: pwsh
if: "${{ matrix.runner.arch == 'x86' }}"
run: |
& "${{ steps.dotnet-path.outputs.exe-path }}" test AsmResolver.sln `
--arch x86 `
--configuration Release `
--property:VersionSuffix=${{needs.get-version.outputs.version_suffix}} `
--property:CheckEolTargetFramework=false `
--logger "trx" `
--logger "console;verbosity=minimal"
- name: Run Tests (x64)
shell: pwsh
if: "${{ matrix.runner.arch == 'x64' }}"
run: |
& "${{ steps.dotnet-path.outputs.exe-path }}" test AsmResolver.sln `
--configuration Release `
--property:VersionSuffix=${{needs.get-version.outputs.version_suffix}} `
--property:CheckEolTargetFramework=false `
--logger "trx" `
--logger "console;verbosity=minimal"
# Collect all trx files and upload them.
- name: Upload Test Results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results-${{matrix.runner.image}}-${{matrix.runner.arch}}
path: '**/*.trx'
if-no-files-found: 'warn'
retention-days: 1
# Job to publish to nuget feeds.
publish:
name: Publish NuGet Packages
runs-on: ubuntu-22.04
needs: [test]
if: ${{github.ref == 'refs/heads/development' || github.ref == 'refs/heads/master'}}
steps:
- uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
- name: Download Build Artifacts
uses: actions/download-artifact@v4
with:
name: build-artifacts
path: artifacts/
- name: Push to NuGet Nightly`
if: ${{github.ref == 'refs/heads/development'}}
shell: pwsh
env:
NIGHTLY_NUGET_API_KEY: ${{secrets.NIGHTLY_NUGET_API_KEY}}
NIGHTLY_NUGET_SOURCE: ${{secrets.NIGHTLY_NUGET_SOURCE}}
run: dotnet nuget push "./artifacts/**/*.nupkg" -k "$env:NIGHTLY_NUGET_API_KEY" -s "$env:NIGHTLY_NUGET_SOURCE" --skip-duplicate
- name: Push to NuGet
if: ${{github.ref == 'refs/heads/master'}}
shell: pwsh
env:
NUGET_API_KEY: ${{secrets.NUGET_API_KEY}}
run: dotnet nuget push "./artifacts/**/*.nupkg" -k "$env:NUGET_API_KEY" -s https://api.nuget.org/v3/index.json --skip-duplicate