Merge pull request #714 from StefanMaron/ExcludeJournalTemplatesOnRul… #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 BusinessCentral.LinterCop | |
- name: Download platform artifact | |
shell: pwsh | |
run: Invoke-WebRequest ${{ matrix.assetUri }} -OutFile ALLanguage.vsix | |
- name: Unzip vsix | |
run: 7z x ALLanguage.vsix "-oALLanguage" "extension/bin/Analyzers" -r | |
- name: Set AssemblyInfo | |
shell: pwsh | |
if: ${{ matrix.GH_eventName != 'pull_request' }} | |
env: | |
AL_VERSION: ${{ matrix.version }} | |
run: | |
(Get-Content BusinessCentral.LinterCop/AssemblyInfo.cs) -replace 'Version\("([\d\.]+)"\)]', | |
("Version(""" + ('${{ needs.setup-matrix.outputs.release-tag-name }}' | |
-replace "v","") + """)]") | Out-File BusinessCentral.LinterCop/AssemblyInfo.cs | |
(Get-Content BusinessCentral.LinterCop/AssemblyInfo.cs) -replace 'AssemblyTitle\("([^"]*)"\)', "AssemblyTitle(`"AL-$env:AL_VERSION`")" | Out-File BusinessCentral.LinterCop/AssemblyInfo.cs | |
- name: Build | |
run: dotnet build BusinessCentral.LinterCop /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: BusinessCentral.LinterCop/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: BusinessCentral.LinterCop/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: BusinessCentral.LinterCop/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: BusinessCentral.LinterCop/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: BusinessCentral.LinterCop/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" "$_" } |