-
Notifications
You must be signed in to change notification settings - Fork 31
306 lines (268 loc) · 12.6 KB
/
build.yml
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
name: Build
on:
push:
branches:
- master
- prerelease
pull_request:
workflow_dispatch: null
jobs:
setup-matrix:
name: Setup
runs-on: ubuntu-latest
steps:
- name: Create Release
id: create-release
uses: release-drafter/release-drafter@v6
if: github.event_name != 'pull_request'
with:
prerelease: ${{ github.ref != 'refs/heads/master' }}
commitish: ${{ github.ref }}
disable-autolabeler: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Get AL Language versions
id: setup-matrix-combinations
shell: pwsh
env:
GITHUB_EVENT_NAME: ${{ github.event_name }}
run: |
function ConvertTo-Version {
[OutputType([System.Version])]
Param (
[Parameter(Mandatory = $true)]
[string] $version
)
$result = $null
if ([System.Version]::TryParse($version, [ref]$result)) {
return $result
}
else {
Write-Error "The value '$($version)' is not a valid input."
}
}
function Get-FeatureFlags {
[OutputType([System.String])]
Param (
[Parameter(Mandatory = $true)]
[System.Version] $version
)
$featureFlags = ""
$RuntimeVersion = [Ordered]@{
'Spring2018' = '1.0'
'Fall2018' = '2.0'
'Spring2019' = '3.0'
'Fall2019' = '4.0'
'Spring2020' = '5.0'
'Fall2020' = '6.0'
'Spring2021' = '7.0'
'Fall2021' = '8.0'
'Spring2022' = '9.0'
'Spring2022RV1' = '9.1'
'Spring2022RV2' = '9.2'
'Fall2022' = '10.0'
'Spring2023' = '11.0'
'Fall2023' = '12.0'
'Fall2023RV1' = '12.1'
'Fall2023RV2' = '12.2'
'Fall2023RV3' = '12.3'
'Spring2024' = '13.0'
'Fall2024' = '14.0'
'Spring2025' = '15.0'
'Fall2025' = '16.0'
'Spring2024OrGreater' = '13.0.964488'
'ManifestHelper' = '13.0.937154'
'PageSystemAction' = '13.0.878831'
}
$supportedRuntimeVersions = $RuntimeVersion.GetEnumerator() | Where-Object { $(ConvertTo-Version($_.Value)) -le $(ConvertTo-Version($version)) } | Foreach-Object { $_.Key } | ForEach-Object { "#$_" }
if (![string]::IsNullOrEmpty($supportedRuntimeVersions)) {
$featureFlags = [System.String]::Join("", $supportedRuntimeVersions)
}
return $featureFlags
}
$listing = Invoke-WebRequest -Method POST -UseBasicParsing `
-Uri https://marketplace.visualstudio.com/_apis/public/gallery/extensionquery?api-version=3.0-preview.1 `
-Body '{"filters":[{"criteria":[{"filterType":8,"value":"Microsoft.VisualStudio.Code"},{"filterType":12,"value":"4096"},{"filterType":7,"value":"ms-dynamics-smb.al"}],"pageNumber":1,"pageSize":50,"sortBy":0,"sortOrder":0}],"assetTypes":[],"flags":0x192}' `
-ContentType application/json | ConvertFrom-Json
$versionLatest = ConvertTo-Version $($listing.results.extensions.versions `
| Where-Object properties -ne $null `
| Where-Object { $_.properties.key -notcontains 'Microsoft.VisualStudio.Code.PreRelease' } | Select-Object -First 1 -ExpandProperty version)
$versionPreRelease = ConvertTo-Version $($listing.results.extensions.versions `
| Where-Object properties -ne $null `
| Where-Object { $_.properties.key -contains 'Microsoft.VisualStudio.Code.PreRelease' } | Select-Object -First 1 -ExpandProperty version)
$results = $listing.results | Select-Object -First 1 -ExpandProperty extensions `
| Select-Object -ExpandProperty versions `
| Where-Object { $(ConvertTo-Version($_.version)) -gt [System.Version]::Parse("12.0.0") }
$matrix = @()
foreach ($result in $results) {
$version = ConvertTo-Version($result.version)
$assetName = "BusinessCentral.LinterCop.AL-$($result.version).dll"
$assetUri = $result | Select-Object -ExpandProperty files | Where-Object { $_.assetType -eq "Microsoft.VisualStudio.Services.VSIXPackage" } | Select-Object -ExpandProperty source
$featureflags = Get-FeatureFlags($version)
if ( $version.Major -gt $versionLatest.Major) {
$featureflags += "#PreRelease"
}
if ( $version.Major -lt $versionLatest.Major) {
$featureflags += "#Legacy"
}
$matrix += [Ordered]@{
version = $result.version;
assetname = $assetName;
assetUri = $assetUri;
latest = $($result.version -eq $versionLatest);
prerelease = $($result.version -eq $versionPreRelease);
featureflags = Get-FeatureFlags($version)
GH_eventName = $env:GITHUB_EVENT_NAME
}
}
$MATRIX_COMBINATIONS = @{'include' = $matrix } | ConvertTo-Json -Compress
echo "matrix-combinations=$($MATRIX_COMBINATIONS)" >> $env:GITHUB_OUTPUT
outputs:
matrix-combinations: ${{ steps.setup-matrix-combinations.outputs.matrix-combinations }}
release-tag-name: ${{ steps.create-release.outputs.tag_name }}
matrix-job:
name: Build
runs-on: ubuntu-latest
needs: setup-matrix
strategy:
matrix: ${{ fromJson(needs.setup-matrix.outputs.matrix-combinations) }}
fail-fast: false
env:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
steps:
- uses: actions/checkout@v4
# Disable Setup .NET
# dotnet-install: .NET Core Runtime with version '8.0.4' is already installed.
# dotnet-install: .NET Core SDK with version '8.0.204' is already installed.
- name: Setup .NET
uses: actions/setup-dotnet@v4
if: false
with:
dotnet-version: 8.0.*
- name: Restore dependencies
run: dotnet restore
- name: Download platform artifact
shell: pwsh
run: Invoke-WebRequest ${{ matrix.assetUri }} -OutFile ALLanguage.vsix
- name: Unzip vsix
run: 7z x ALLanguage.vsix "-oms-dynamics-smb.al-latest" extension/bin/Analyzers -r
- name: Set AssemblyInfo
shell: pwsh
if: ${{ matrix.GH_eventName != 'pull_request' }}
env:
AL_VERSION: ${{ matrix.version }}
run: (Get-Content AssemblyInfo.cs) -replace 'Version\("([\d\.]+)"\)]',
("Version(""" + ('${{ needs.setup-matrix.outputs.release-tag-name }}'
-replace "v","") + """)]") | Out-File AssemblyInfo.cs
(Get-Content AssemblyInfo.cs) -replace 'AssemblyTitle\("([^"]*)"\)', "AssemblyTitle(`"AL-$env:AL_VERSION`")" | Out-File AssemblyInfo.cs
- name: Build
run: dotnet build /p:FeatureFlags=${{ matrix.featureflags }} --no-restore --configuration Release
- name: Upload build artifact
id: upload-build-asset
uses: actions/upload-artifact@v4
if: ${{ matrix.GH_eventName != 'pull_request' }}
with:
name: ${{ matrix.assetname }}
path: bin/Release/netstandard2.1/BusinessCentral.LinterCop.dll
compression-level: 0 # no compression
### Upload Asset as Latest
- name: Upload build artifact (Latest)
id: upload-build-asset-latest
uses: actions/upload-artifact@v4
if: ${{ matrix.GH_eventName != 'pull_request' && matrix.latest }}
with:
name: BusinessCentral.LinterCop.dll
path: bin/Release/netstandard2.1/BusinessCentral.LinterCop.dll
compression-level: 0 # no compression
### Upload Asset as Pre-Release
- name: Upload build artifact (Pre-Release)
id: upload-build-asset-prerelease
uses: actions/upload-artifact@v4
if: ${{ matrix.GH_eventName != 'pull_request' && matrix.prerelease }}
with:
name: BusinessCentral.LinterCop.AL-PreRelease.dll
path: bin/Release/netstandard2.1/BusinessCentral.LinterCop.dll
compression-level: 0 # no compression
### Compatibility with previous naming of files
### Release Asset as Current
- name: Upload build artifact (Current)
id: upload-build-asset-current
uses: actions/upload-artifact@v4
if: ${{ matrix.GH_eventName != 'pull_request' && matrix.latest }}
with:
name: BusinessCentral.LinterCop.current.dll
path: bin/Release/netstandard2.1/BusinessCentral.LinterCop.dll
compression-level: 0 # no compression
# ### Release Asset as Next
- name: Upload build artifact (Next)
id: upload-build-asset-next
uses: actions/upload-artifact@v4
if: ${{ matrix.GH_eventName != 'pull_request' && matrix.prerelease }}
with:
name: BusinessCentral.LinterCop.next.dll
path: bin/Release/netstandard2.1/BusinessCentral.LinterCop.dll
compression-level: 0 # no compression
sign-job:
name: Sign
runs-on: windows-latest # Code signing must run on a Windows agent for Authenticode signing (dll/exe)
permissions:
id-token: write # Required for requesting the JWT
contents: write # Required for Uploading Release Assets with GitHub CLI (gh release upload)
needs:
- setup-matrix
- matrix-job
if: github.event_name != 'pull_request' # Exclude this job for validation on the pull-request
steps:
# Disable Setup .NET
# dotnet-install: .NET Core Runtime with version '8.0.4' is already installed.
# dotnet-install: .NET Core SDK with version '8.0.204' is already installed.
- name: Setup .NET
uses: actions/setup-dotnet@v4
if: false
with:
dotnet-version: 8.0.*
# Install the code signing tool
- name: Install Sign CLI tool
run: dotnet tool install --tool-path . sign --version 0.9.0-beta.23127.3
# Download artifacts
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: DownloadArtifacts
# Rename artifacts
- name: Rename artifacts
run: |
# Get list of artifacts files
$artifacts = Get-ChildItem -Path DownloadArtifacts -Recurse | ForEach-Object { if (!($_.PSIsContainer)) { $_}} | Where-Object { $_.Name -like 'BusinessCentral.LinterCop*.dll' -and $_.Directory.Name -like 'BusinessCentral.LinterCop*.dll' }
# Create folder if not exits
if (!(Test-Path BuildArtifacts)) {
New-Item -Path BuildArtifacts -ItemType Directory -Force | Out-Null
}
# Move the artifacts (BusinessCentral.LinterCop.dll) in every directory to a combined folder and rename the file to the name of it's parent directory
$artifacts | ForEach-Object { Move-Item -Path $_ -Destination (Join-Path 'BuildArtifacts' $_.Directory.Name) }
- name: "Azure Login"
uses: azure/login@v2
with:
creds: ${{ secrets.AZURE_CREDENTIALS }}
# Run the signing command
- name: Sign artifacts
shell: pwsh
run: >
./sign code azure-key-vault
**/*.dll
--base-directory "${{ github.workspace }}\BuildArtifacts"
--description "BusinessCentral.LinterCop"
--description-url "https://github.com/StefanMaron/BusinessCentral.LinterCop"
--azure-key-vault-managed-identity true
--azure-key-vault-url "${{ secrets.KEY_VAULT_URL }}"
--azure-key-vault-certificate "${{ secrets.KEY_VAULT_CERTIFICATE }}"
# Publish the signed packages
- name: Upload Release Assets
id: upload-release-assets
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_REPO: ${{ github.repository }}
RELEASE_TAG_NAME: ${{ needs.setup-matrix.outputs.release-tag-name }}
run: |
$artifacts = Get-ChildItem -Path BuildArtifacts -Depth 0 -Filter *.dll
$artifacts | ForEach-Object { gh release upload --repo "$env:GITHUB_REPO" "$env:RELEASE_TAG_NAME" "$_" }