1
1
name : Biohazrd
2
2
on :
3
3
push :
4
+ # This prevents tag pushes from triggering this workflow
5
+ branches : ['*']
4
6
pull_request :
7
+ release :
8
+ types : [published]
5
9
workflow_dispatch :
10
+ inputs :
11
+ version :
12
+ description : " Version"
13
+ default : " "
14
+ will_publish_packages :
15
+ description : " Publish packages?"
16
+ default : " false"
6
17
env :
7
18
DOTNET_NOLOGO : true
8
19
DOTNET_CLI_TELEMETRY_OPTOUT : true
@@ -13,37 +24,171 @@ jobs:
13
24
strategy :
14
25
fail-fast : false
15
26
matrix :
16
- os : ['windows-latest', 'ubuntu-latest']
27
+ platform :
28
+ - name : Windows
29
+ architecture : x64
30
+ runs-on : windows-latest
31
+ - name : Linux
32
+ architecture : x64
33
+ runs-on : ubuntu-latest
17
34
configuration : ['Debug', 'Release']
18
- name : Build and Test ${{matrix.configuration}} ${{matrix.os}}
19
- runs-on : ${{matrix.os}}
35
+ include :
36
+ # Linux Release x64 builds create packages (if applicable)
37
+ - platform :
38
+ runs-on : ubuntu-latest
39
+ configuration : Release
40
+ create-packages : true
41
+ name : Build and Test ${{matrix.platform.name}} ${{matrix.platform.architecture}} ${{matrix.configuration}}
42
+ runs-on : ${{matrix.platform.runs-on}}
20
43
steps :
21
44
# ----------------------------------------------------------------------- Checkout
22
45
- name : Checkout
23
46
uses : actions/checkout@v2
24
47
with :
25
48
submodules : recursive
26
49
50
+ # ----------------------------------------------------------------------- Setup Python
51
+ - name : Setup Python 3.8
52
+ uses : actions/setup-python@v2
53
+ with :
54
+ python-version : ' 3.8'
55
+
27
56
# ----------------------------------------------------------------------- Setup .NET
28
57
- name : Setup .NET
29
58
uses : actions/setup-dotnet@v1
30
59
with :
31
60
dotnet-version : 5.0.x
32
61
62
+ # ----------------------------------------------------------------------- Configure versioning
63
+ - name : Configure build
64
+ id : configuration
65
+ run : python .github/workflows/configure-build.py
66
+ env :
67
+ github_event_name : ${{github.event_name}}
68
+ github_run_number : ${{github.run_number}}
69
+ release_version : ${{github.event.release.tag_name}}
70
+ workflow_dispatch_version : ${{github.event.inputs.version}}
71
+
33
72
# ----------------------------------------------------------------------- Build
34
73
- name : Restore
35
74
run : dotnet restore
36
75
37
76
- name : Build
38
77
run : dotnet build --no-restore --configuration ${{matrix.configuration}}
78
+
79
+ - name : Pack
80
+ id : pack
81
+ if : matrix.create-packages
82
+ run : dotnet pack --no-build --configuration ${{matrix.configuration}}
39
83
40
84
# ----------------------------------------------------------------------- Test
41
85
- name : Test
42
86
run : dotnet test --no-restore --no-build --configuration ${{matrix.configuration}} --verbosity normal
87
+
88
+ # ----------------------------------------------------------------------- Collect Artifacts
89
+ - name : Collect NuGet Packages
90
+ uses : actions/upload-artifact@v2
91
+ # We always want to collect packages when they were produced
92
+ if : steps.pack.outcome == 'success' && always()
93
+ with :
94
+ name : Packages
95
+ if-no-files-found : error
96
+ path : packages/**
97
+
98
+ publish-packages-github :
99
+ name : Publish to GitHub
100
+ runs-on : ubuntu-latest
101
+ needs : build-and-test
102
+ # Pushes to main always publish CI packages
103
+ # Published releases always publish packages
104
+ # A manual workflow only publishes packages if explicitly enabled
105
+ if : (github.event_name == 'push' && github.ref == 'refs/heads/main') || github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true')
106
+ steps :
107
+ # ----------------------------------------------------------------------- Setup .NET
108
+ - name : Setup .NET
109
+ uses : actions/setup-dotnet@v1
110
+ with :
111
+ dotnet-version : 5.0.x
112
+
113
+ # ----------------------------------------------------------------------- Download built packages
114
+ - name : Download built packages
115
+ uses : actions/download-artifact@v2
116
+ with :
117
+ name : Packages
118
+
119
+ # ----------------------------------------------------------------------- Upload release assets
120
+ - name : Upload release assets
121
+ if : github.event_name == 'release'
122
+ uses : actions/github-script@v4
123
+ with :
124
+ user-agent : actions/github-script for ${{github.repository}}
125
+ script : |
126
+ const fs = require('fs').promises;
127
+ const path = require('path');
128
+ const upload_url = context.payload.release.upload_url;
129
+
130
+ if (!upload_url) {
131
+ throw "Missing release asset upload URL!";
132
+ }
133
+
134
+ for (let filePath of await fs.readdir('.')) {
135
+ const fileExtension = path.extname(filePath);
136
+ if (fileExtension != '.nupkg' && fileExtension != '.snupkg') {
137
+ continue;
138
+ }
139
+
140
+ console.log(`Uploading '${filePath}'`);
141
+ const contentLength = (await fs.stat(filePath)).size;
142
+ const fileContents = await fs.readFile(filePath);
143
+ await github.repos.uploadReleaseAsset({
144
+ url: upload_url,
145
+ headers: {
146
+ 'content-type': 'application/octet-stream',
147
+ 'content-length': contentLength
148
+ },
149
+ name: path.basename(filePath),
150
+ data: fileContents
151
+ });
152
+ }
153
+
154
+ # ----------------------------------------------------------------------- Push to GitHub Packages
155
+ - name : Push to GitHub Packages
156
+ run : dotnet nuget push "*.nupkg" --skip-duplicate --no-symbols true --api-key ${{secrets.GITHUB_TOKEN}} --source https://nuget.pkg.github.com/${{github.repository_owner}}
157
+ env :
158
+ # This is a workaround for https://github.com/NuGet/Home/issues/9775
159
+ DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER : 0
160
+
161
+ publish-packages-nuget-org :
162
+ name : Publish to NuGet.org
163
+ runs-on : ubuntu-latest
164
+ needs : build-and-test
165
+ environment : NuGet.org
166
+ # Release builds always publish packages to NuGet.org
167
+ # Workflow dispatch builds will only publish packages if enabled and an explicit version number is given
168
+ if : github.event_name == 'release' || (github.event_name == 'workflow_dispatch' && github.event.inputs.will_publish_packages == 'true' && github.event.inputs.version != '')
169
+ steps :
170
+ # ----------------------------------------------------------------------- Setup .NET
171
+ - name : Setup .NET
172
+ uses : actions/setup-dotnet@v1
173
+ with :
174
+ dotnet-version : 5.0.x
175
+
176
+ # ----------------------------------------------------------------------- Download built packages
177
+ - name : Download built packages
178
+ uses : actions/download-artifact@v2
179
+ with :
180
+ name : Packages
181
+
182
+ # ----------------------------------------------------------------------- Push to NuGet.org
183
+ - name : Push to NuGet.org
184
+ run : dotnet nuget push "*.nupkg" --api-key ${{secrets.NUGET_API_KEY}} --source ${{secrets.NUGET_API_URL}}
185
+ env :
186
+ # This is a workaround for https://github.com/NuGet/Home/issues/9775
187
+ DOTNET_SYSTEM_NET_HTTP_USESOCKETSHTTPHANDLER : 0
43
188
44
189
send-ci-failure-notification :
45
190
name : Send CI Failure Notification
46
- needs : build-and-test
191
+ needs : [ build-and-test, publish-packages-github, publish-packages-nuget-org]
47
192
if : failure() && github.event_name != 'pull_request'
48
193
continue-on-error : true
49
194
runs-on : ubuntu-latest
0 commit comments