-
Notifications
You must be signed in to change notification settings - Fork 3
364 lines (334 loc) · 14.4 KB
/
CreateRelease.yaml
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
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
name: ' Create release'
on:
workflow_dispatch:
inputs:
appVersion:
description: App version to promote to release (default is latest)
required: false
default: 'latest'
name:
description: Name of this release
required: true
default: ''
tag:
description: Tag of this release (needs to be semantic version string https://semver.org, ex. 1.0.0)
required: true
default: ''
prerelease:
description: Prerelease (Y/N)
required: false
default: 'N'
draft:
description: Draft (Y/N)
required: false
default: 'N'
createReleaseBranch:
description: Create Release Branch (Y/N)
required: false
default: 'N'
updateVersionNumber:
description: New Version Number in main branch. Use Major.Minor for absolute change, use +Major.Minor for incremental change.
required: false
default: ''
directCommit:
description: Direct COMMIT (Y/N)
required: false
default: 'N'
permissions:
contents: write
pull-requests: write
actions: read
concurrency: release
defaults:
run:
shell: powershell
env:
ALGoOrgSettings: ${{ vars.ALGoOrgSettings }}
ALGoRepoSettings: ${{ vars.ALGoRepoSettings }}
jobs:
CreateRelease:
runs-on: [ windows-latest ]
outputs:
telemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
artifacts: ${{ steps.analyzeartifacts.outputs.artifacts }}
releaseId: ${{ steps.createrelease.outputs.releaseId }}
commitish: ${{ steps.analyzeartifacts.outputs.commitish }}
releaseBranch: ${{ steps.createreleasenotes.outputs.releaseBranch }}
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Initialize the workflow
id: init
uses: microsoft/AL-Go-Actions/WorkflowInitialize@PPPreview
with:
shell: powershell
eventId: "DO0094"
- name: Read settings
id: ReadSettings
uses: microsoft/AL-Go-Actions/ReadSettings@PPPreview
with:
shell: powershell
parentTelemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
get: templateUrl,repoName
- name: Determine Projects
id: determineProjects
uses: microsoft/AL-Go-Actions/DetermineProjectsToBuild@PPPreview
with:
shell: powershell
- name: Check for updates to AL-Go system files
uses: microsoft/AL-Go-Actions/CheckForUpdates@PPPreview
with:
shell: powershell
parentTelemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
templateUrl: ${{ env.templateUrl }}
- name: Analyze Artifacts
id: analyzeartifacts
env:
_appVersion: ${{ github.event.inputs.appVersion }}
run: |
$ErrorActionPreference = "STOP"
Set-StrictMode -version 2.0
$projects = '${{ steps.determineProjects.outputs.ProjectsJson }}' | ConvertFrom-Json
Write-Host "projects:"
$projects | ForEach-Object { Write-Host "- $_" }
$include = @()
$sha = ''
$allArtifacts = @()
$page = 1
$headers = @{
"Authorization" = "token ${{ github.token }}"
"Accept" = "application/json"
}
do {
$repoArtifacts = Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri "$($ENV:GITHUB_API_URL)/repos/$($ENV:GITHUB_REPOSITORY)/actions/artifacts?per_page=100&page=$page" | ConvertFrom-Json
$allArtifacts += $repoArtifacts.Artifacts
$page++
}
while ($repoArtifacts.Artifacts.Count -gt 0)
Write-Host "Repo Artifacts count: $($repoArtifacts.total_count)"
Write-Host "Downloaded Artifacts count: $($allArtifacts.Count)"
$projects | ForEach-Object {
$thisProject = $_
if ($thisProject -and ($thisProject -ne '.')) {
$project = $thisProject.Replace('\','_').Replace('/','_')
}
else {
$project = $env:repoName
}
$refname = "$ENV:GITHUB_REF_NAME".Replace('/','_')
Write-Host "Analyzing artifacts for project $project"
$appVersion = "$ENV:_appVersion"
if ($appVersion -eq "latest") {
Write-Host "Grab latest"
$artifact = $allArtifacts | Where-Object { $_.name -like "$project-$refname-Apps-*" -or $_.name -like "$project-$refname-PowerPlatformSolution-*" } | Select-Object -First 1
}
else {
Write-Host "Search for $project-$refname-Apps-$appVersion or $project-$refname-PowerPlatformSolution-$appVersion"
$artifact = $allArtifacts | Where-Object { $_.name -eq "$project-$refname-Apps-$appVersion" -or $_.name -eq "$project-$refname-PowerPlatformSolution-$appVersion" } | Select-Object -First 1
}
if ($artifact) {
$startIndex = $artifact.name.LastIndexOf('-') + 1
$artifactsVersion = $artifact.name.SubString($startIndex)
}
else {
Write-Host "::Error::No artifacts found for this project"
exit 1
}
if ($sha) {
if ($artifact.workflow_run.head_sha -ne $sha) {
Write-Host "::Error::The build selected for release doesn't contain all projects. Please rebuild all projects by manually running the CI/CD workflow and recreate the release."
throw "The build selected for release doesn't contain all projects. Please rebuild all projects by manually running the CI/CD workflow and recreate the release."
}
}
else {
$sha = $artifact.workflow_run.head_sha
}
write-host "looking for $project-$refname-Apps-$artifactsVersion or $project-$refname-TestApps-$artifactsVersion or $project-$refname-Dependencies-$artifactsVersion or $project-$refname-PowerPlatformSolution-$artifactsVersion"
$allArtifacts | Where-Object { ($_.name -like "$project-$refname-Apps-$artifactsVersion" -or $_.name -like "$project-$refname-TestApps-$artifactsVersion" -or $_.name -like "$project-$refname-Dependencies-$artifactsVersion" -or $_.name -like "$project-$refname-PowerPlatformSolution-$artifactsVersion") } | ForEach-Object {
$atype = $_.name.SubString(0,$_.name.Length-$artifactsVersion.Length-1)
$atype = $atype.SubString($atype.LastIndexOf('-')+1)
$include += $( [ordered]@{ "name" = $_.name; "url" = $_.archive_download_url; "atype" = $atype; "project" = $thisproject } )
}
if ($include.Count -eq 0) {
Write-Host "::Error::No artifacts found for version $artifactsVersion"
exit 1
}
}
$artifacts = @{ "include" = $include }
$artifactsJson = $artifacts | ConvertTo-Json -compress
Add-Content -Path $env:GITHUB_OUTPUT -Value "artifacts=$artifactsJson"
Write-Host "artifacts=$artifactsJson"
Add-Content -Path $env:GITHUB_OUTPUT -Value "commitish=$sha"
Write-Host "commitish=$sha"
- name: Prepare release notes
id: createreleasenotes
uses: microsoft/AL-Go-Actions/CreateReleaseNotes@PPPreview
with:
shell: powershell
parentTelemetryScopeJson: ${{ steps.init.outputs.telemetryScopeJson }}
tag_name: ${{ github.event.inputs.tag }}
- name: Create release
uses: actions/github-script@v6
id: createrelease
env:
bodyMD: ${{ steps.createreleasenotes.outputs.releaseNotes }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var bodyMD = process.env.bodyMD
const createReleaseResponse = await github.rest.repos.createRelease({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: '${{ github.event.inputs.tag }}',
name: '${{ github.event.inputs.name }}',
body: bodyMD.replaceAll('\\n','\n').replaceAll('%0A','\n').replaceAll('%0D','\n').replaceAll('%25','%'),
draft: ${{ github.event.inputs.draft=='Y' }},
prerelease: ${{ github.event.inputs.prerelease=='Y' }},
make_latest: 'legacy',
target_commitish: '${{ steps.analyzeartifacts.outputs.commitish }}'
});
const {
data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl }
} = createReleaseResponse;
core.setOutput('releaseId', releaseId);
UploadArtifacts:
runs-on: [ windows-latest ]
needs: [ CreateRelease ]
strategy:
matrix: ${{ fromJson(needs.CreateRelease.outputs.artifacts) }}
fail-fast: true
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Read settings
uses: microsoft/AL-Go-Actions/ReadSettings@PPPreview
with:
shell: powershell
parentTelemetryScopeJson: ${{ needs.CreateRelease.outputs.telemetryScopeJson }}
- name: Read secrets
uses: microsoft/AL-Go-Actions/ReadSecrets@PPPreview
env:
secrets: ${{ toJson(secrets) }}
with:
shell: powershell
parentTelemetryScopeJson: ${{ needs.CreateRelease.outputs.telemetryScopeJson }}
settingsJson: ${{ env.Settings }}
secrets: 'nuGetContext,storageContext'
- name: Download artifact
run: |
$ErrorActionPreference = "STOP"
Set-StrictMode -version 2.0
Write-Host "Downloading artifact ${{ matrix.name}}"
$headers = @{
"Authorization" = "token ${{ github.token }}"
"Accept" = "application/vnd.github.v3+json"
}
Invoke-WebRequest -UseBasicParsing -Headers $headers -Uri '${{ matrix.url }}' -OutFile '${{ matrix.name }}.zip'
- name: Upload release artifacts
uses: actions/github-script@v6
env:
releaseId: ${{ needs.createrelease.outputs.releaseId }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const releaseId = process.env.releaseId
const assetPath = '${{ matrix.name }}.zip'
const assetName = '${{ matrix.name }}.zip'
const fs = require('fs');
const uploadAssetResponse = await github.rest.repos.uploadReleaseAsset({
owner: context.repo.owner,
repo: context.repo.repo,
release_id: releaseId,
name: assetName,
data: fs.readFileSync(assetPath)
});
- name: nuGetContext
id: nuGetContext
if: ${{ env.nuGetContext }}
run: |
$ErrorActionPreference = "STOP"
Set-StrictMode -version 2.0
$nuGetContext = ''
if ('${{ matrix.atype }}' -eq 'Apps') {
$nuGetContext = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String([System.Environment]::GetEnvironmentVariable('nuGetContext')))
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "nuGetContext=$nuGetContext"
- name: Deliver to NuGet
uses: microsoft/AL-Go-Actions/Deliver@PPPreview
if: ${{ steps.nuGetContext.outputs.nuGetContext }}
env:
deliveryContext: ${{ steps.nuGetContext.outputs.nuGetContext }}
with:
shell: powershell
type: 'Release'
projects: ${{ matrix.project }}
deliveryTarget: 'NuGet'
artifacts: ${{ github.event.inputs.appVersion }}
atypes: 'Apps,TestApps'
- name: storageContext
id: storageContext
if: ${{ env.storageContext }}
run: |
$ErrorActionPreference = "STOP"
Set-StrictMode -version 2.0
$storageContext = ''
if ('${{ matrix.atype }}' -eq 'Apps') {
$storageContext = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String([System.Environment]::GetEnvironmentVariable('storageContext')))
}
Add-Content -Path $env:GITHUB_OUTPUT -Value "storageContext=$storageContext"
- name: Deliver to Storage
uses: microsoft/AL-Go-Actions/Deliver@PPPreview
if: ${{ steps.storageContext.outputs.storageContext }}
env:
deliveryContext: ${{ steps.storageContext.outputs.storageContext }}
with:
shell: powershell
type: 'Release'
projects: ${{ matrix.project }}
deliveryTarget: 'Storage'
artifacts: ${{ github.event.inputs.appVersion }}
atypes: 'Apps,TestApps,Dependencies'
CreateReleaseBranch:
if: ${{ github.event.inputs.createReleaseBranch=='Y' }}
runs-on: [ windows-latest ]
needs: [ CreateRelease, UploadArtifacts ]
steps:
- name: Checkout
uses: actions/checkout@v3
with:
ref: '${{ needs.createRelease.outputs.commitish }}'
- name: Create Release Branch
run: |
$ErrorActionPreference = "STOP"
Set-StrictMode -version 2.0
git checkout -b ${{ needs.CreateRelease.outputs.releaseBranch }}
git config user.name ${{ github.actor}}
git config user.email ${{ github.actor}}@users.noreply.github.com
git commit --allow-empty -m "Release branch ${{ needs.CreateRelease.outputs.releaseBranch }}"
git push origin ${{ needs.CreateRelease.outputs.releaseBranch }}
UpdateVersionNumber:
if: ${{ github.event.inputs.updateVersionNumber!='' }}
runs-on: [ windows-latest ]
needs: [ CreateRelease, UploadArtifacts ]
steps:
- name: Update Version Number
uses: microsoft/AL-Go-Actions/IncrementVersionNumber@PPPreview
with:
shell: powershell
parentTelemetryScopeJson: ${{ needs.CreateRelease.outputs.telemetryScopeJson }}
versionNumber: ${{ github.event.inputs.updateVersionNumber }}
directCommit: ${{ github.event.inputs.directCommit }}
PostProcess:
if: always()
runs-on: [ windows-latest ]
needs: [ CreateRelease, UploadArtifacts, CreateReleaseBranch, UpdateVersionNumber ]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Finalize the workflow
id: PostProcess
uses: microsoft/AL-Go-Actions/WorkflowPostProcess@PPPreview
with:
shell: powershell
eventId: "DO0094"
telemetryScopeJson: ${{ needs.CreateRelease.outputs.telemetryScopeJson }}