11name : Biohazrd
22on :
33 push :
4+ # This prevents tag pushes from triggering this workflow
5+ branches : ['*']
46 pull_request :
7+ release :
8+ types : [published]
59 workflow_dispatch :
10+ inputs :
11+ version :
12+ description : " Version"
13+ default : " "
14+ will_publish_packages :
15+ description : " Publish packages?"
16+ default : " false"
617env :
718 DOTNET_NOLOGO : true
819 DOTNET_CLI_TELEMETRY_OPTOUT : true
@@ -13,37 +24,171 @@ jobs:
1324 strategy :
1425 fail-fast : false
1526 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
1734 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}}
2043 steps :
2144 # ----------------------------------------------------------------------- Checkout
2245 - name : Checkout
2346 uses : actions/checkout@v2
2447 with :
2548 submodules : recursive
2649
50+ # ----------------------------------------------------------------------- Setup Python
51+ - name : Setup Python 3.8
52+ uses : actions/setup-python@v2
53+ with :
54+ python-version : ' 3.8'
55+
2756 # ----------------------------------------------------------------------- Setup .NET
2857 - name : Setup .NET
2958 uses : actions/setup-dotnet@v1
3059 with :
3160 dotnet-version : 5.0.x
3261
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+
3372 # ----------------------------------------------------------------------- Build
3473 - name : Restore
3574 run : dotnet restore
3675
3776 - name : Build
3877 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}}
3983
4084 # ----------------------------------------------------------------------- Test
4185 - name : Test
4286 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
43188
44189 send-ci-failure-notification :
45190 name : Send CI Failure Notification
46- needs : build-and-test
191+ needs : [ build-and-test, publish-packages-github, publish-packages-nuget-org]
47192 if : failure() && github.event_name != 'pull_request'
48193 continue-on-error : true
49194 runs-on : ubuntu-latest
0 commit comments