-
Notifications
You must be signed in to change notification settings - Fork 123
305 lines (265 loc) · 12.5 KB
/
main.yaml
File metadata and controls
305 lines (265 loc) · 12.5 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
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
name: "Build Octopus Clients"
# Controls when the action will run.
on:
push:
# Triggers the workflow on pushes to master
branches:
- master
tags-ignore:
- '**'
schedule:
# Daily 5am australian/brisbane time
- cron: '0 19 * * *'
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# Pass branch and patch number to Nuke OctoVersion
env:
OCTOVERSION_CurrentBranch: ${{ github.head_ref || github.ref }}
OCTOVERSION_Patch: ${{ github.run_number }}
AssentNonInteractive: true
jobs:
build:
name: Build Octopus Clients
runs-on: windows-latest
env:
# These codesigning env vars must match the parameter names in Build.cs
AzureKeyVaultUrl: ${{ secrets.AZURE_KEYVAULT_URL }}
AzureKeyVaultAppId: ${{ secrets.AZURE_KEYVAULT_APPID }}
AzureKeyVaultAppSecret: ${{ secrets.AZURE_KEYVAULT_APPSECRET }}
AzureKeyVaultCertificateName: ${{ secrets.AZURE_KEYVAULT_CERTIFICATENAME }}
AzureKeyVaultTenantId: ${{ secrets.AZURE_KEYVAULT_TENANTID }}
outputs:
octoversion_fullsemver: ${{ steps.build.outputs.octoversion_fullsemver }}
skip-release-and-release-note: ${{ steps.github-tag.outputs.skip-release-and-release-note }}
steps:
- uses: actions/checkout@v6
with:
fetch-depth: 0 # all
# At the moment we build using the net10 toolchain but test on net462, net48 and net80.
# We publish packages for net462, net48 and net80
# The Tests run on net10 as part of the Octopus Server build pipeline separately.
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
10.0.x
- name: Append OCTOVERSION_CurrentBranch with -nightly (for scheduled)
if: github.event_name == 'schedule'
run: echo "OCTOVERSION_CurrentBranch=${{ env.OCTOVERSION_CurrentBranch }}-nightly-$(Get-Date -Format 'yyyyMMddHHmmss')" >> $env:GITHUB_ENV
# Note: Because this step runs on Windows, this will also run all of the tests on Windows
- name: Nuke Build 🏗
id: build
shell: bash
run: ./build.cmd
# Unit test reports
- name: Windows .NET 4.6.2 unit test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows .Net 4.6.2 unit test results
path: ./TestResults/Win_net462_*.trx
reporter: dotnet-trx
fail-on-error: true
- name: Windows .NET 4.8 unit test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows.Net 4.8 unit test results
path: ./TestResults/Win_net48_*.trx
reporter: dotnet-trx
fail-on-error: true
- name: Windows .NET 8.0 unit test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows .Net 8.0 unit test results
path: ./TestResults/Win_net8.0_*.trx
reporter: dotnet-trx
fail-on-error: true
# E2E test reports
- name: Windows .NET 4.6.2 E2E test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows .NET 4.6.2 E2E test results
path: ./TestResults/Win-E2E_net462_*.trx
reporter: dotnet-trx
fail-on-error: true
- name: Windows .NET 4.8 E2E test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows .NET 4.8 E2E test results
path: ./TestResults/Win-E2E_net48_*.trx
reporter: dotnet-trx
fail-on-error: true
- name: Windows .NET 8.0 E2E test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Windows .NET 8.0 E2E test results
path: ./TestResults/Win-E2E_net8.0_*.trx
reporter: dotnet-trx
fail-on-error: true
- name: Upload NuGet package artifact
uses: actions/upload-artifact@v6
with:
name: OctoClientsNuget
path: ./artifacts/*.nupkg
- name: Tag release (when not pre-release) 🏷️
id: github-tag
if: ${{ !contains( steps.build.outputs.octoversion_fullsemver, '-' ) }}
uses: actions/github-script@v8
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const commitMessage = context.payload.head_commit?.message?.trim() || '';
const skipReleaseAndReleaseNote = /^skip-release-and-release-note:\s*true\s*$/mi.test(commitMessage);
core.setOutput('skip-release-and-release-note', skipReleaseAndReleaseNote);
if (skipReleaseAndReleaseNote) {
// Abort early: the commit is marked as not significant enough to trigger a release or be included in
// release notes, so we don't need a tag either
return;
}
await github.rest.git.createRef({
owner: context.repo.owner,
repo: context.repo.repo,
ref: "refs/tags/${{ steps.build.outputs.octoversion_fullsemver }}",
sha: context.sha,
});
test-linux:
needs: build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v6
- name: Setup .NET
uses: actions/setup-dotnet@v5
with:
dotnet-version: |
8.0.x
10.0.x
- name: Run unit tests (net8.0) 🏗
shell: bash
run: dotnet test ./source/Octopus.Client.Tests/Octopus.Client.Tests.csproj --framework net8.0 --configuration:Release --logger:"trx;LogFilePrefix=Linux" --results-directory ./TestResults
- name: Linux unit test report
uses: dorny/test-reporter@b082adf0eced0765477756c2a610396589b8c637 # v2.5.0
if: success() || failure() # run this step even if previous step failed
with:
name: Linux unit tests results
path: ./TestResults/*.trx
reporter: dotnet-trx
fail-on-error: true
deploy_nuget:
name: Upload nuget packages to Octopus Deploy and create release if required
runs-on: ubuntu-latest
if: >- # Only run if we want a release or if it's a nightly build (nightly pushes to Octopus to exercise the pipeline, but no actual release gets created)
${{
needs.build.outputs.skip-release-and-release-note == 'false' ||
github.event_name == 'schedule'
}}
permissions:
id-token: write # Required to obtain the ID token from GitHub Actions
actions: read # Required to download artifact
contents: write # Required to create releases
env:
OCTOPUS_SPACE: "Core Platform"
SHOULD_CREATE_RELEASE: ${{ github.ref == 'refs/heads/master' && !contains(needs.build.outputs.octoversion_fullsemver, '-') }}
needs: [ build, test-linux ]
steps:
- if: ${{ env.SHOULD_CREATE_RELEASE == 'true' }}
uses: actions/checkout@v6
with:
fetch-depth: 0 # fetching everything is unfortunately required to get tags
- name: Download nuget package artifact
uses: actions/download-artifact@v8
with:
name: OctoClientsNuget
path: ./artifacts/
- name: Login to Octopus Deploy 🐙
uses: OctopusDeploy/login@e485a40e4b47a154bdf59cc79e57894b0769a760 # v1
with:
server: ${{ secrets.OCTOPUS_URL }}
service_account_id: 8b5a7f0f-c2c9-48de-a0f6-74d83669accf
- name: Push to Octopus 🐙
uses: OctopusDeploy/push-package-action@53ac6adebe7ffe18bf88ed41a80a7af9504273af # v4
with:
packages: |
./artifacts/Octopus.Client.${{ needs.build.outputs.octoversion_fullsemver }}.nupkg
./artifacts/Octopus.Server.Client.${{ needs.build.outputs.octoversion_fullsemver }}.nupkg
- name: Create Release in Octopus 🐙
uses: OctopusDeploy/create-release-action@617cac6e20b9c00741c762637a53bd7b002d4198 # v4
with:
project: "Octopus.Client"
packages: |
Octopus.Client:${{ needs.build.outputs.octoversion_fullsemver }}
# We use jc to convert git log output into something machine readable, as git can't natively do so.
# jq is preinstalled in GitHub actions, but jc (https://github.com/kellyjonbrazil/jc) is not.
- if: ${{ env.SHOULD_CREATE_RELEASE == 'true' }}
name: Set up python
uses: actions/setup-python@v6
with:
python-version: '3.14'
- if: ${{ env.SHOULD_CREATE_RELEASE == 'true' }}
name: Install jc
run: pip3 install jc==1.25.5
- if: ${{ env.SHOULD_CREATE_RELEASE == 'true' }}
name: Create GitHub Release 🚀
uses: actions/github-script@v8
with:
script: |
const { owner, repo } = context.repo;
const tagName = '${{ needs.build.outputs.octoversion_fullsemver }}';
// Look up the tag associated with the last release in order to get commit messages since then, for release notes.
let lastReleaseTag = null;
try {
lastReleaseTag = (await github.rest.repos.getLatestRelease({ owner, repo })).data.tag_name;
} catch (error) {
if (error.status !== 404) throw error;
console.log('No previous release found');
}
console.log('Last release tag:', lastReleaseTag);
// Use jc to convert git log output into JSON we can reliably parse
const gitLogArgs = lastReleaseTag ? [`${lastReleaseTag}..`] : [];
const { stdout: gitCommitsJson } = await exec.getExecOutput('jc', ['--raw', 'git', 'log', '--reverse', ...gitLogArgs]);
const commitsSinceLastRelease = JSON.parse(gitCommitsJson);
// Of the commits since the last release, get the first line of each message that doesn't opt out of release notes
// Also extract GitHub issue URL from the second line if present
const releaseNotes = commitsSinceLastRelease
.map(commit => commit.message)
.filter(message => !/^\s*skip-release-and-release-note:\s*true\s*$/mi.test(message))
.map(message => {
const lines = message.split('\n');
const commitTitle = lines[0];
// Check if the second line (if present and non-empty) contains a GitHub issue URL
const secondLine = lines.length > 1 ? lines[1].trim() : '';
const isGitHubIssueUrl = secondLine && /^https:\/\/github\.com\/octopusdeploy\/issues\/issues\/\d+/i.test(secondLine);
// If second line contains a GitHub issue URL from OctopusDeploy/Issues, format it as a clickable link
// GitHub will automatically convert URLs like "https://github.com/OctopusDeploy/Issues/issues/1" to "OctopusDeploy/Issues#1"
if (isGitHubIssueUrl) {
return `- ${secondLine} - ${commitTitle}`;
}
return `- ${commitTitle}`;
});
// Build release body
const body = `## Release Notes:
${releaseNotes.join('\n')}
## NuGet Packages:
- [Octopus.Server.Client.${tagName}](https://www.nuget.org/packages/Octopus.Server.Client/${tagName})
- [Octopus.Client.${tagName}](https://www.nuget.org/packages/Octopus.Client/${tagName})`;
const release = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: tagName,
name: `Octopus Client Release ${tagName}`,
body: body,
draft: false,
prerelease: false
});
console.log(`Release ${tagName} created successfully`);
- if: ${{ env.SHOULD_CREATE_RELEASE == 'true' }}
name: Attach NuGet packages to release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release upload '${{ needs.build.outputs.octoversion_fullsemver }}' ./artifacts/*.nupkg